-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Doctor.test.ts
59 lines (46 loc) · 2.01 KB
/
Doctor.test.ts
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
49
50
51
52
53
54
55
56
57
58
59
import { Doctor } from '../../Doctor'
import { consoleContext, Context } from '../__helpers__/context'
const ctx = Context.new().add(consoleContext()).assemble()
it.skip('doctor should succeed when schema and db do match', async () => {
ctx.fixture('example-project')
const result = Doctor.new().parse([])
await expect(result).resolves.toEqual('Everything in sync 🔄')
expect(
ctx.mocked['console.error'].mock.calls.join('\n'),
).toMatchInlineSnapshot(`👩⚕️🏥 Prisma Doctor checking the database...`)
})
it('should fail when db is missing', async () => {
ctx.fixture('schema-db-out-of-sync')
ctx.fs.remove('dev.db')
const result = Doctor.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(
`P1003: SQLite database file doesn't exist`,
)
})
it('should fail when Prisma schema is missing', async () => {
const result = Doctor.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
Could not find a schema.prisma file that is required for this command.
You can either provide it with --schema, set it as \`prisma.schema\` in your package.json or put it into the default location ./prisma/schema.prisma https://pris.ly/d/prisma-schema-location
`)
})
it('should fail when db is empty', async () => {
ctx.fixture('schema-db-out-of-sync')
ctx.fs.write('dev.db', '')
const result = Doctor.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
P4001
The introspected database was empty: file:dev.db
`)
})
it('should fail when schema and db do not match', async () => {
ctx.fixture('schema-db-out-of-sync')
const result = Doctor.new().parse([])
await expect(result).rejects.toThrowErrorMatchingSnapshot(`
NewPost
↪ Model is missing in database
User
↪ Field newName is missing in database
↪ Field newPosts is missing in database
`)
})