-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bfe515
commit 160b597
Showing
14 changed files
with
293 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/packages/client/src/__tests__/__snapshots__/undefined-vs-null.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`select validation null when undefined is allowed 1`] = ` | ||
"mutation { | ||
updateOnePost( | ||
data: { | ||
id: null | ||
} | ||
where: { | ||
id: \\"abc\\" | ||
} | ||
) { | ||
id | ||
createdAt | ||
updatedAt | ||
published | ||
title | ||
content | ||
authorId | ||
} | ||
}" | ||
`; | ||
|
||
exports[`select validation null when undefined is not allowed 1`] = ` | ||
"mutation { | ||
createOnePost(data: { | ||
published: true | ||
title: null | ||
}) { | ||
id | ||
createdAt | ||
updatedAt | ||
published | ||
title | ||
content | ||
authorId | ||
} | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/packages/client/src/__tests__/undefined-vs-null.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import stripAnsi from 'strip-ansi' | ||
import { blog } from '../fixtures/blog' | ||
import { DMMFClass } from '../runtime/dmmf' | ||
import { makeDocument } from '../runtime/query' | ||
import { getDMMF } from '../generation/getDMMF' | ||
|
||
let dmmf | ||
beforeAll(async () => { | ||
const dmmfDocument = await getDMMF({ datamodel: blog }) | ||
dmmf = new DMMFClass(dmmfDocument) | ||
}) | ||
|
||
describe('select validation', () => { | ||
test('null when undefined is allowed', () => { | ||
const select = { | ||
data: { | ||
id: null, | ||
}, | ||
where: { | ||
id: 'abc', | ||
}, | ||
} | ||
|
||
const document = makeDocument({ | ||
dmmf, | ||
select, | ||
rootTypeName: 'mutation', | ||
rootField: 'updateOnePost', | ||
}) | ||
|
||
expect(String(document)).toMatchSnapshot() | ||
try { | ||
document.validate(select) | ||
} catch (e) { | ||
expect(stripAnsi(e.message)).toMatchInlineSnapshot(` | ||
" | ||
Invalid \`prisma.updateOnePost()\` invocation: | ||
{ | ||
data: { | ||
id: null | ||
~~~~ | ||
}, | ||
where: { | ||
id: 'abc' | ||
} | ||
} | ||
Argument id for data.id must not be null. Please use undefined instead. | ||
" | ||
`) | ||
} | ||
}) | ||
test('null when undefined is not allowed', () => { | ||
const select = { | ||
data: { | ||
published: true, | ||
title: null, | ||
}, | ||
} | ||
|
||
const document = makeDocument({ | ||
dmmf, | ||
select, | ||
rootTypeName: 'mutation', | ||
rootField: 'createOnePost', | ||
}) | ||
|
||
expect(String(document)).toMatchSnapshot() | ||
try { | ||
document.validate(select) | ||
} catch (e) { | ||
expect(stripAnsi(e.message)).toMatchInlineSnapshot(` | ||
" | ||
Invalid \`prisma.createOnePost()\` invocation: | ||
{ | ||
data: { | ||
published: true, | ||
title: null | ||
~~~~ | ||
} | ||
} | ||
Argument title: Got invalid value null on prisma.createOnePost. Provided null, expected String. | ||
" | ||
`) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.