You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/string.test.js
+59-15Lines changed: 59 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
52
52
53
53
strictEqual(statusCode,400)
54
54
strictEqual(body.errors[0].message,
55
-
'Variable "$input" got invalid value "a💩" at "input.title"; Expected type "title_String_minLength_3". Must be at least 3 characters in length')
55
+
'Variable "$input" got invalid value "a💩" at "input.title"; Expected type "title_String_NotNull_minLength_3". Must be at least 3 characters in length')
56
56
})
57
57
58
58
it('should throw custom error',asyncfunction(){
@@ -169,7 +169,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
169
169
170
170
strictEqual(statusCode,400)
171
171
strictEqual(body.errors[0].message,
172
-
'Variable "$input" got invalid value "bar💩" at "input.title"; Expected type "title_String_startsWith_". Must start with 💩')
172
+
'Variable "$input" got invalid value "bar💩" at "input.title"; Expected type "title_String_NotNull_startsWith_". Must start with 💩')
173
173
})
174
174
175
175
it('should throw custom error',asyncfunction(){
@@ -228,7 +228,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
228
228
229
229
strictEqual(statusCode,400)
230
230
strictEqual(body.errors[0].message,
231
-
'Variable "$input" got invalid value "💩bar" at "input.title"; Expected type "title_String_endsWith_". Must end with 💩')
231
+
'Variable "$input" got invalid value "💩bar" at "input.title"; Expected type "title_String_NotNull_endsWith_". Must end with 💩')
232
232
})
233
233
234
234
it('should throw custom error',asyncfunction(){
@@ -287,7 +287,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
287
287
288
288
strictEqual(statusCode,400)
289
289
strictEqual(body.errors[0].message,
290
-
'Variable "$input" got invalid value "fobar" at "input.title"; Expected type "title_String_contains_". Must contain 💩')
290
+
'Variable "$input" got invalid value "fobar" at "input.title"; Expected type "title_String_NotNull_contains_". Must contain 💩')
291
291
})
292
292
293
293
it('should throw custom error',asyncfunction(){
@@ -346,7 +346,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
346
346
347
347
strictEqual(statusCode,400)
348
348
strictEqual(body.errors[0].message,
349
-
'Variable "$input" got invalid value "💩foobar" at "input.title"; Expected type "title_String_notContains_foo". Must not contain foo')
349
+
'Variable "$input" got invalid value "💩foobar" at "input.title"; Expected type "title_String_NotNull_notContains_foo". Must not contain foo')
350
350
})
351
351
352
352
it('should throw custom error',asyncfunction(){
@@ -405,7 +405,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
405
405
406
406
strictEqual(statusCode,400)
407
407
strictEqual(body.errors[0].message,
408
-
'Variable "$input" got invalid value "£££" at "input.title"; Expected type "title_String_pattern_09azAZ". Must match ^[0-9a-zA-Z]*$')
408
+
'Variable "$input" got invalid value "£££" at "input.title"; Expected type "title_String_NotNull_pattern_09azAZ". Must match ^[0-9a-zA-Z]*$')
409
409
})
410
410
411
411
it('should throw custom error',asyncfunction(){
@@ -467,7 +467,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
467
467
468
468
strictEqual(statusCode,400)
469
469
strictEqual(body.errors[0].message,
470
-
'Variable "$input" got invalid value "£££" at "input.title"; Expected type "title_String_format_byte". Must be in byte format')
470
+
'Variable "$input" got invalid value "£££" at "input.title"; Expected type "title_String_NotNull_format_byte". Must be in byte format')
471
471
})
472
472
473
473
it('should throw custom error',asyncfunction(){
@@ -528,7 +528,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
528
528
529
529
strictEqual(statusCode,400)
530
530
strictEqual(body.errors[0].message,
531
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_datetime". Must be a date-time in RFC 3339 format')
531
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_datetime". Must be a date-time in RFC 3339 format')
532
532
})
533
533
534
534
it('should throw custom error',asyncfunction(){
@@ -589,7 +589,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
589
589
590
590
strictEqual(statusCode,400)
591
591
strictEqual(body.errors[0].message,
592
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_date". Must be a date in ISO 8601 format')
592
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_date". Must be a date in ISO 8601 format')
593
593
})
594
594
595
595
it('should throw custom error',asyncfunction(){
@@ -650,7 +650,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
650
650
651
651
strictEqual(statusCode,400)
652
652
strictEqual(body.errors[0].message,
653
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_email". Must be in email format')
653
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_email". Must be in email format')
654
654
})
655
655
656
656
it('should throw custom error',asyncfunction(){
@@ -711,7 +711,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
711
711
712
712
strictEqual(statusCode,400)
713
713
strictEqual(body.errors[0].message,
714
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_ipv4". Must be in IP v4 format')
714
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_ipv4". Must be in IP v4 format')
715
715
})
716
716
717
717
it('should throw custom error',asyncfunction(){
@@ -772,7 +772,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
772
772
773
773
strictEqual(statusCode,400)
774
774
strictEqual(body.errors[0].message,
775
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_ipv6". Must be in IP v6 format')
775
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_ipv6". Must be in IP v6 format')
776
776
})
777
777
778
778
it('should throw custom error',asyncfunction(){
@@ -833,7 +833,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
833
833
834
834
strictEqual(statusCode,400)
835
835
strictEqual(body.errors[0].message,
836
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_uri". Must be in URI format')
836
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_uri". Must be in URI format')
837
837
})
838
838
839
839
it('should throw custom error',asyncfunction(){
@@ -894,7 +894,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
894
894
895
895
strictEqual(statusCode,400)
896
896
strictEqual(body.errors[0].message,
897
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_uuid". Must be in UUID format')
897
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_uuid". Must be in UUID format')
898
898
})
899
899
900
900
it('should throw custom error',asyncfunction(){
@@ -943,7 +943,7 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
943
943
944
944
strictEqual(statusCode,400)
945
945
strictEqual(body.errors[0].message,
946
-
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_format_test". Invalid format type test')
946
+
'Variable "$input" got invalid value "a" at "input.title"; Expected type "title_String_NotNull_format_test". Invalid format type test')
947
947
})
948
948
949
949
it('should throw custom error',asyncfunction(){
@@ -963,6 +963,50 @@ describe('@constraint String in INPUT_FIELD_DEFINITION', function () {
963
963
})
964
964
})
965
965
})
966
+
967
+
describe('#notNull',function(){
968
+
before(function(){
969
+
this.typeDefs=`
970
+
type Query {
971
+
books: [Book]
972
+
}
973
+
type Book {
974
+
title: String
975
+
}
976
+
type Mutation {
977
+
createBook(input: BookInput): Book
978
+
}
979
+
input BookInput {
980
+
title: String! @constraint(minLength: 3)
981
+
}`
982
+
983
+
this.request=setup(this.typeDefs)
984
+
})
985
+
986
+
it('should fail with null',asyncfunction(){
987
+
const{ body, statusCode }=awaitthis.request
988
+
.post('/graphql')
989
+
.set('Accept','application/json')
990
+
.send({ query,variables: {input: {title: null}}
991
+
})
992
+
993
+
strictEqual(statusCode,400)
994
+
strictEqual(body.errors[0].message,
995
+
'Variable "$input" got invalid value null at "input.title"; Expected non-nullable type "title_String_NotNull_minLength_3!" not to be null.')
0 commit comments