mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(server): handle graphql bad input error (#10854)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import {
|
||||
applyDecorators,
|
||||
Body,
|
||||
@@ -130,7 +132,12 @@ function gql(app: INestApplication, query: string) {
|
||||
return request(app.getHttpServer())
|
||||
.post('/graphql')
|
||||
.send({ query })
|
||||
.expect(200);
|
||||
.expect(res => {
|
||||
assert(
|
||||
res.status === 200 || res.status === 400,
|
||||
'GraphQL query should return 200 or 400'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test.before(async ({ context }) => {
|
||||
@@ -199,6 +206,15 @@ test('should be able to handle validation error in graphql query', async t => {
|
||||
t.true(t.context.logger.error.notCalled);
|
||||
});
|
||||
|
||||
test('should be able to handle graphql input error', async t => {
|
||||
const res = await gql(t.context.app, `mutation { validate(email: 123) }`);
|
||||
const err = res.body.errors[0];
|
||||
t.is(err.message, 'String cannot represent a non string value: 123');
|
||||
t.is(err.extensions.status, HttpStatus.BAD_REQUEST);
|
||||
t.is(err.extensions.name, 'GRAPHQL_BAD_REQUEST');
|
||||
t.true(t.context.logger.error.notCalled);
|
||||
});
|
||||
|
||||
test('should be able to respond request', async t => {
|
||||
const res = await request(t.context.app.getHttpServer())
|
||||
.get('/ok')
|
||||
|
||||
Reference in New Issue
Block a user