Skip to content

Commit 1986ece

Browse files
committed
add more tests
1 parent 6219031 commit 1986ece

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import tap from 'tap'
2+
import { NewNamespace, Request, Response } from '../test-utils'
3+
import { ErrorResponse } from '../types'
4+
import { getSchemaValidation } from './get-schema-validation'
5+
6+
tap.test('Schema validation', (t) => {
7+
t.test('Should validate schema as valid', async (t) => {
8+
NewNamespace(
9+
{
10+
name: 'SERVICES',
11+
},
12+
[],
13+
)
14+
15+
let req = Request('POST', '', {
16+
type_defs: 'type Query { hello: String }',
17+
name: 'foo',
18+
})
19+
let res = Response()
20+
await getSchemaValidation(req, res)
21+
22+
t.equal(res.statusCode, 200)
23+
t.same(res.body, {
24+
success: true,
25+
})
26+
t.end()
27+
})
28+
29+
t.test('Should validate schema as invalid', async (t) => {
30+
NewNamespace(
31+
{
32+
name: 'SERVICES',
33+
},
34+
[],
35+
)
36+
37+
let req = Request('POST', '', {
38+
type_defs: 'type Query { hello: String22 }',
39+
name: 'foo',
40+
})
41+
let res = Response()
42+
await getSchemaValidation(req, res)
43+
44+
const body = (res.body as any) as ErrorResponse
45+
46+
t.equal(res.statusCode, 400)
47+
t.equal(body.success, false)
48+
t.ok(body.error)
49+
t.end()
50+
})
51+
t.end()
52+
})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import tap from 'tap'
2+
import { NewNamespace, Request, Response } from '../test-utils'
3+
import { getSchemaDiff } from './get-schema-diff'
4+
import { registerSchema } from './register-schema'
5+
6+
tap.test('Schema diff', (t) => {
7+
t.test('Should calculate schema diff', async (t) => {
8+
NewNamespace(
9+
{
10+
name: 'SERVICES',
11+
},
12+
[],
13+
)
14+
15+
let req = Request('POST', '', {
16+
type_defs: 'type Query { hello: String }',
17+
version: '1',
18+
name: 'foo',
19+
})
20+
let res = Response()
21+
await registerSchema(req, res)
22+
23+
t.equal(res.statusCode, 200)
24+
25+
req = Request('POST', '', {
26+
name: 'foo',
27+
type_defs: 'type Query { hello: String world: String }',
28+
})
29+
res = Response()
30+
await getSchemaDiff(req, res)
31+
t.equal(res.statusCode, 200)
32+
t.same(res.body, {
33+
success: true,
34+
data: [
35+
{
36+
criticality: {
37+
level: 'NON_BREAKING',
38+
},
39+
type: 'FIELD_ADDED',
40+
message: "Field 'world' was added to object type 'Query'",
41+
path: 'Query.world',
42+
},
43+
],
44+
})
45+
t.end()
46+
})
47+
t.end()
48+
})

0 commit comments

Comments
 (0)