mirror of
https://github.com/nestjs/nest.git
synced 2026-10-28 09:45:43 +08:00
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
import { Test } from '@nestjs/testing';
|
|
import request from 'supertest';
|
|
import { AppModule } from '../src/app.module.js';
|
|
|
|
describe('GraphQL Pipes', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
const module = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
}).compile();
|
|
|
|
app = module.createNestApplication();
|
|
app.useGlobalPipes(new ValidationPipe());
|
|
await app.init();
|
|
});
|
|
|
|
it(`should throw an error`, () => {
|
|
return request(app.getHttpServer())
|
|
.post('/graphql')
|
|
.send({
|
|
operationName: null,
|
|
variables: {},
|
|
query:
|
|
'mutation {\n addRecipe(newRecipeData: {title: "test", ingredients: []}) {\n id\n }\n}\n',
|
|
})
|
|
.expect(200, {
|
|
data: null,
|
|
errors: [
|
|
{
|
|
extensions: {
|
|
code: 'BAD_REQUEST',
|
|
originalError: {
|
|
error: 'Bad Request',
|
|
message: [
|
|
'description must be longer than or equal to 30 characters',
|
|
],
|
|
statusCode: 400,
|
|
},
|
|
},
|
|
locations: [
|
|
{
|
|
column: 3,
|
|
line: 2,
|
|
},
|
|
],
|
|
message: 'Bad Request Exception',
|
|
path: ['addRecipe'],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await app.close();
|
|
});
|
|
});
|