Skip to content

Commit 190502d

Browse files
committed
fix tests, add more response validations
1 parent 0517b1b commit 190502d

File tree

9 files changed

+68
-56
lines changed

9 files changed

+68
-56
lines changed

package-lock.json

Lines changed: 22 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
"typescript": {
4040
"rewritePaths": {
4141
"./src/": "build/"
42-
}
43-
},
44-
"nodeArguments": []
42+
},
43+
"compile": "tsc"
44+
}
4545
},
4646
"devDependencies": {
47-
"@ava/typescript": "^1.1.1",
47+
"@ava/typescript": "^2.0.0",
4848
"@types/node": "^14.14.41",
4949
"ava": "^3.15.0",
5050
"cross-env": "^7.0.3",

src/registry/federation/deactivate-schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('Should deactivate schema', async (t) => {
2828
const schemaId = res.json().data.schemaId
2929

3030
res = await app.inject({
31-
method: 'POST',
31+
method: 'PUT',
3232
url: '/schema/deactivate',
3333
payload: {
3434
schemaId,
@@ -71,7 +71,7 @@ test('Should return 400 when schema does not exist', async (t) => {
7171
t.teardown(() => app.close())
7272

7373
let res = await app.inject({
74-
method: 'POST',
74+
method: 'PUT',
7575
url: '/schema/deactivate',
7676
payload: {
7777
schemaId: 123,

src/registry/federation/get-composed-schema-versions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ test('Should return 400 when schema in specified version was deactivated', async
220220
const schemaId = res.json().data.schemaId
221221

222222
res = await app.inject({
223-
method: 'POST',
223+
method: 'PUT',
224224
url: '/schema/deactivate',
225225
payload: {
226226
schemaId,

src/registry/federation/register-schema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ test('Should return 400 because an service has no active schema registered', asy
357357
const schemaId = res.json().data.schemaId
358358

359359
res = await app.inject({
360-
method: 'POST',
360+
method: 'PUT',
361361
url: '/schema/deactivate',
362362
payload: {
363363
schemaId,

src/registry/maintanance/garbage-collect.test.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { cleanTest, createTestContext, createTestPrefix, TestContext } from '../
55
const test = anyTest as TestInterface<TestContext>
66
test.before(createTestContext())
77
test.beforeEach(createTestPrefix())
8-
test.after.always('cleanup', cleanTest())
8+
// test.after.always('cleanup', cleanTest())
99

1010
test('Should keep the most recent 10 schemas of every service in the graph', async (t) => {
1111
const app = build({
@@ -43,7 +43,7 @@ test('Should keep the most recent 10 schemas of every service in the graph', asy
4343
method: 'POST',
4444
url: '/schema/garbage_collect',
4545
payload: {
46-
num_schemas_keep: 10,
46+
numSchemasKeep: 10,
4747
},
4848
})
4949

@@ -60,30 +60,4 @@ test('Should keep the most recent 10 schemas of every service in the graph', asy
6060
},
6161
'response payload match',
6262
)
63-
})
64-
65-
test('Should not be possible to delete all schemas', async (t) => {
66-
const app = build({
67-
databaseConnectionUrl: t.context.connectionUrl,
68-
})
69-
t.teardown(() => app.close())
70-
71-
let res = await app.inject({
72-
method: 'POST',
73-
url: '/schema/garbage_collect',
74-
payload: {
75-
num_schemas_keep: 0,
76-
},
77-
})
78-
79-
t.is(res.statusCode, 400)
80-
81-
t.deepEqual(
82-
res.json(),
83-
{
84-
error: 'body.num_schemas_keep should be >= 10',
85-
success: false,
86-
},
87-
'response payload match',
88-
)
89-
})
63+
})

src/registry/maintanance/garbage-collect.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ import { FastifyInstance, FastifySchema } from 'fastify'
33

44
export interface RequestContext {
55
Body: {
6-
num_schemas_keep: number
6+
numSchemasKeep: number
77
}
88
}
99

1010
export const schema: FastifySchema = {
11+
response: {
12+
'2xx': S.object()
13+
.additionalProperties(false)
14+
.required(['success', 'data'])
15+
.prop('success', S.boolean())
16+
.prop(
17+
'data',
18+
S.object()
19+
.required(['deletedSchemas', 'deletedVersions'])
20+
.prop('deletedSchemas', S.number())
21+
.prop('deletedVersions', S.number()),
22+
),
23+
},
1124
body: S.object()
1225
.additionalProperties(false)
1326
.required(['numSchemasKeep'])
@@ -17,7 +30,7 @@ export const schema: FastifySchema = {
1730
export default function garbageCollect(fastify: FastifyInstance) {
1831
fastify.post<RequestContext>('/schema/garbage_collect', { schema }, async (req, res) => {
1932
return fastify.knex.transaction(async function (trx) {
20-
const schemasToKeep = await trx.from('schema').orderBy('updatedAt', 'desc').limit(req.body.num_schemas_keep)
33+
const schemasToKeep = await trx.from('schema').orderBy('updatedAt', 'desc').limit(req.body.numSchemasKeep)
2134

2235
const deletedSchemaTags = await trx
2336
.from('schema_tag')

src/registry/validation/get-schema-diff.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ export interface RequestContext {
1616
}
1717

1818
export const schema: FastifySchema = {
19+
response: {
20+
'2xx': S.object()
21+
.additionalProperties(false)
22+
.required(['success', 'data'])
23+
.prop('success', S.boolean())
24+
.prop(
25+
'data',
26+
S.array().items(
27+
S.object()
28+
.required(['criticality', 'type', 'message', 'path'])
29+
.prop('criticality', S.object().prop('level', S.string()).prop('reason', S.string()))
30+
.prop('type', S.string())
31+
.prop('message', S.string())
32+
.prop('path', S.string()),
33+
),
34+
),
35+
},
1936
body: S.object()
2037
.additionalProperties(false)
2138
.required(['typeDefs', 'serviceName', 'graphName'])

src/registry/validation/get-schema-validation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface RequestContext {
1616
}
1717

1818
export const schema: FastifySchema = {
19+
response: {
20+
'2xx': S.object().additionalProperties(false).required(['success']).prop('success', S.boolean()),
21+
},
1922
body: S.object()
2023
.additionalProperties(false)
2124
.required(['typeDefs', 'serviceName', 'graphName'])

0 commit comments

Comments
 (0)