forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidatePrismaClientOptions.test.ts
114 lines (110 loc) · 2.77 KB
/
validatePrismaClientOptions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { validatePrismaClientOptions } from '../runtime/utils/validatePrismaClientOptions'
const config = {
datasourceNames: ['db'],
}
describe('valid options', () => {
test('empty', () => {
expect.assertions(0)
validatePrismaClientOptions({}, config)
})
test('full', () => {
expect.assertions(0)
validatePrismaClientOptions(
{
datasources: {
db: {
url: '',
},
},
errorFormat: 'pretty',
log: ['error'],
},
config,
)
validatePrismaClientOptions(
{
datasources: {
db: {
url: '',
},
},
errorFormat: 'pretty',
log: [
{
emit: 'event',
level: 'error',
},
],
},
config,
)
})
})
describe('invalid options', () => {
test('typos', () => {
expect(() =>
validatePrismaClientOptions(
{
errorsFormat: 'minimal',
} as any,
config,
),
).toThrowErrorMatchingInlineSnapshot(`
"Unknown property errorsFormat provided to PrismaClient constructor. Did you mean "errorFormat"?
Read more at https://pris.ly/d/client-constructor"
`)
expect(() =>
validatePrismaClientOptions(
{
errorFormat: 'minimal',
datasources: {
asd: {},
},
},
config,
),
).toThrowErrorMatchingInlineSnapshot(`
"Unknown datasource asd provided to PrismaClient constructor. Available datasources: db
Read more at https://pris.ly/d/client-constructor"
`)
expect(() =>
validatePrismaClientOptions(
{
errorFormat: 'minimal',
datasources: {
db: { murl: '' },
},
} as any,
config,
),
).toThrowErrorMatchingInlineSnapshot(`
"Invalid value {"db":{"murl":""}} for datasource "db" provided to PrismaClient constructor.
It should have this form: { url: "CONNECTION_STRING" }
Read more at https://pris.ly/d/client-constructor"
`)
expect(() =>
validatePrismaClientOptions(
{
errorFormat: 'minimal',
log: [{ helo: 'world' }],
} as any,
config,
),
).toThrowErrorMatchingInlineSnapshot(`
"Invalid property helo for "log" provided to PrismaClient constructor
Read more at https://pris.ly/d/client-constructor"
`)
expect(() =>
validatePrismaClientOptions(
{
errorFormat: 'minimal',
log: ['muery'],
} as any,
config,
),
).toThrowErrorMatchingInlineSnapshot(`
"Invalid log level "muery" provided to PrismaClient constructor. Did you mean "query"?
Read more at https://pris.ly/d/client-constructor"
`)
})
})