Skip to content

Commit 0a7a352

Browse files
committed
add more tests, fix schema test
1 parent 440add3 commit 0a7a352

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/routes/get-schema-diff.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'ava'
22
import { NewNamespace, Request, Response } from '../test-utils'
3+
import { ErrorResponse } from '../types'
34
import { getSchemaDiff } from './get-schema-diff'
45
import { registerSchema } from './register-schema'
56

@@ -78,3 +79,20 @@ test.serial('Should detect a breaking change', async (t) => {
7879
],
7980
})
8081
})
82+
83+
test.serial('Should return 400 when type_defs is missing', async (t) => {
84+
NewNamespace({
85+
name: 'SERVICES',
86+
})
87+
88+
let req = Request('POST', '', {
89+
name: 'foo',
90+
})
91+
let res = Response()
92+
await getSchemaDiff(req, res)
93+
94+
const body = (res.body as any) as ErrorResponse
95+
96+
t.is(res.statusCode, 400)
97+
t.is(body.success, false)
98+
})

src/routes/get-schema-validation.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ test.serial('Should validate schema as invalid', async (t) => {
4343
error: 'Error: Unknown type: "String22".',
4444
})
4545
})
46+
47+
test.serial('Should return 400 when type_defs is missing', async (t) => {
48+
NewNamespace({
49+
name: 'SERVICES',
50+
})
51+
52+
let req = Request('POST', '', {
53+
name: 'foo',
54+
})
55+
let res = Response()
56+
await getSchemaValidation(req, res)
57+
58+
const body = (res.body as any) as ErrorResponse
59+
60+
t.is(res.statusCode, 400)
61+
t.is(body.success, false)
62+
})

src/routes/register-schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ test.serial(
112112
t.is(current.data.length, 1)
113113

114114
assert(
115-
first.data[0],
115+
current.data[0],
116116
object({
117117
uid: size(string(), 4, 11),
118118
is_active: literal(true),
119119
service_id: literal('foo'),
120120
type_defs: literal('type Query { hello: String }'),
121121
created_at: number(),
122-
updated_at: literal(null),
122+
updated_at: number(), // updated
123123
version: literal('1'),
124124
}),
125125
)

0 commit comments

Comments
 (0)