-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathrepositories.test.js
More file actions
49 lines (39 loc) · 1.63 KB
/
repositories.test.js
File metadata and controls
49 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* globals describe, it, afterEach */
const { system } = require('gluegun')
const { expect } = require('chai')
const fs = require('fs')
const path = require('path')
const projectName = 'herbs-test-runner'
const generateProject = () => system.run(`herbs new --name ${projectName} --description "testing the herbs CLI" --author herbs --license MIT --graphql --rest no --database postgres --npmInstall yes`)
const callHerbsCli = () => system.run(`herbs`)
const herbsUpdate = () => system.run(`cd ${projectName} && herbs update`)
describe('When I generate a complete project that uses postgres', () => {
afterEach(async () => {
fs.rmSync(path.resolve(process.cwd(), `${projectName}`), { recursive: true })
})
it('Should I create a new repository with foreign key', async () => {
await generateProject()
await callHerbsCli()
const customerEntity =
`
const { entity, id, field } = require('@herbsjs/herbs')
const { herbarium } = require('@herbsjs/herbarium')
const User = require('./user')
const Customer =
entity('Customer', {
id: id(String),
description: field(String),
user: field(User)
})
module.exports =
herbarium.entities
.add(Customer, 'Customer')
.entity
`
const dir = `${path.resolve(process.cwd(), `${projectName}/src/domain/entities/customer.js`)}`
fs.writeFileSync(dir, customerEntity)
expect(fs.existsSync(dir)).to.be.true
await herbsUpdate()
expect(fs.existsSync(path.resolve(process.cwd(), `${projectName}/src/infra/data/repositories/customerRepository.js`))).to.be.true
})
})