Skip to content

Commit daed9a0

Browse files
committed
chore: add null tests
1 parent c94ad5c commit daed9a0

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

test/float.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,46 @@ describe('@constraint Float in INPUT_FIELD_DEFINITION', function () {
348348
})
349349
})
350350

351+
describe('#null', function () {
352+
before(async function () {
353+
this.typeDefs = `
354+
type Query {
355+
books: [Book]
356+
}
357+
type Book {
358+
title: String
359+
}
360+
type Mutation {
361+
createBook(input: BookInput): Book
362+
}
363+
input BookInput {
364+
title: Float @constraint(multipleOf: 2)
365+
}`
366+
367+
this.request = await setup(this.typeDefs)
368+
})
369+
370+
it('should pass with null', async function () {
371+
const { body, statusCode } = await this.request
372+
.post('/graphql')
373+
.set('Accept', 'application/json')
374+
.send({ query, variables: { input: { title: null } } })
375+
376+
strictEqual(statusCode, 200)
377+
deepStrictEqual(body, { data: { createBook: null } })
378+
})
379+
380+
it('should pass with undefined', async function () {
381+
const { body, statusCode } = await this.request
382+
.post('/graphql')
383+
.set('Accept', 'application/json')
384+
.send({ query, variables: { input: { title: undefined } } })
385+
386+
strictEqual(statusCode, 200)
387+
deepStrictEqual(body, { data: { createBook: null } })
388+
})
389+
})
390+
351391
describe('#uniqueTypeName', function () {
352392
before(async function () {
353393
this.typeDefs = `

test/int.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,46 @@ describe('@constraint Int in INPUT_FIELD_DEFINITION', function () {
348348
})
349349
})
350350

351+
describe('#null', function () {
352+
before(async function () {
353+
this.typeDefs = `
354+
type Query {
355+
books: [Book]
356+
}
357+
type Book {
358+
title: String
359+
}
360+
type Mutation {
361+
createBook(input: BookInput): Book
362+
}
363+
input BookInput {
364+
title: Int @constraint(multipleOf: 2)
365+
}`
366+
367+
this.request = await setup(this.typeDefs)
368+
})
369+
370+
it('should pass with null', async function () {
371+
const { body, statusCode } = await this.request
372+
.post('/graphql')
373+
.set('Accept', 'application/json')
374+
.send({ query, variables: { input: { title: null } } })
375+
376+
strictEqual(statusCode, 200)
377+
deepStrictEqual(body, { data: { createBook: null } })
378+
})
379+
380+
it('should pass with undefined', async function () {
381+
const { body, statusCode } = await this.request
382+
.post('/graphql')
383+
.set('Accept', 'application/json')
384+
.send({ query, variables: { input: { title: undefined } } })
385+
386+
strictEqual(statusCode, 200)
387+
deepStrictEqual(body, { data: { createBook: null } })
388+
})
389+
})
390+
351391
describe('#uniqueTypeName', function () {
352392
before(async function () {
353393
this.typeDefs = `

test/string.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,46 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
993993
})
994994
})
995995

996+
describe('#null', function () {
997+
before(async function () {
998+
this.typeDefs = `
999+
type Query {
1000+
books: [Book]
1001+
}
1002+
type Book {
1003+
title: String
1004+
}
1005+
type Mutation {
1006+
createBook(input: BookInput): Book
1007+
}
1008+
input BookInput {
1009+
title: String @constraint(minLength: 3)
1010+
}`
1011+
1012+
this.request = await setup(this.typeDefs)
1013+
})
1014+
1015+
it('should pass with null', async function () {
1016+
const { body, statusCode } = await this.request
1017+
.post('/graphql')
1018+
.set('Accept', 'application/json')
1019+
.send({ query, variables: { input: { title: null } } })
1020+
1021+
strictEqual(statusCode, 200)
1022+
deepStrictEqual(body, { data: { createBook: null } })
1023+
})
1024+
1025+
it('should pass with undefined', async function () {
1026+
const { body, statusCode } = await this.request
1027+
.post('/graphql')
1028+
.set('Accept', 'application/json')
1029+
.send({ query, variables: { input: { title: undefined } } })
1030+
1031+
strictEqual(statusCode, 200)
1032+
deepStrictEqual(body, { data: { createBook: null } })
1033+
})
1034+
})
1035+
9961036
describe('#uniqueTypeName', function () {
9971037
before(async function () {
9981038
this.typeDefs = `

0 commit comments

Comments
 (0)