Skip to content

Commit

Permalink
chore: upgrade @nestjs v8 (#293)
Browse files Browse the repository at this point in the history
* chore: upgrade @nestjs v8

* fix: spec

* fix: disconnect socket

* fix: socker usage
  • Loading branch information
9renpoto authored Aug 19, 2021
1 parent 18942cf commit d713d69
Show file tree
Hide file tree
Showing 6 changed files with 3,093 additions and 9,153 deletions.
31 changes: 31 additions & 0 deletions example/__tests__/__snapshots__/app.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AppModule /graphql(POST) forbiddenError 1`] = `
Array [
Object {
"extensions": Object {
"code": "FORBIDDEN",
"response": Object {
"message": "Forbidden",
"statusCode": 403,
},
},
"message": "Forbidden",
},
]
`;

exports[`AppModule /graphql(POST) forbiddenError warning 1`] = `
Array [
Object {
"extensions": Object {
"code": "UNAUTHENTICATED",
"response": Object {
"message": "Unauthorized",
"statusCode": 401,
},
},
"message": "Unauthorized",
},
]
`;
29 changes: 8 additions & 21 deletions example/__tests__/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { createTestClient } from 'apollo-server-testing';
import { getApolloServer } from '@nestjs/graphql';
import type { ApolloServerBase } from 'apollo-server-core';
import gql from 'graphql-tag';
import { AppModule } from './../src/app.module';

describe('AppModule', () => {
let app: INestApplication;
let apolloClient: ReturnType<typeof createTestClient>;
let apolloClient: ApolloServerBase;

beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
Expand All @@ -18,10 +18,7 @@ describe('AppModule', () => {
app = moduleFixture.createNestApplication();
await app.init();

const module: GraphQLModule =
moduleFixture.get<GraphQLModule>(GraphQLModule);
// apolloServer is protected, we need to cast module to any to get it
apolloClient = createTestClient((module as any).apolloServer);
apolloClient = getApolloServer(moduleFixture);
});

afterAll(() => app.close());
Expand All @@ -34,36 +31,26 @@ describe('AppModule', () => {
request(app.getHttpServer()).get('/graphql').expect(400));

it('/graphql(POST) forbiddenError warning', async () => {
const { query } = apolloClient;
const result = await query({
const result = await apolloClient.executeOperation({
query: gql`
query {
unauthorizedException
}
`,
variables: {},
});
expect(result.errors).toMatchInlineSnapshot(`
Array [
[GraphQLError: Unauthorized],
]
`);
expect(result.errors).toMatchSnapshot();
});

it('/graphql(POST) forbiddenError', async () => {
const { query } = apolloClient;
const result = await query({
const result = await apolloClient.executeOperation({
query: gql`
query {
forbiddenException
}
`,
variables: {},
});
expect(result.errors).toMatchInlineSnapshot(`
Array [
[GraphQLError: Forbidden],
]
`);
expect(result.errors).toMatchSnapshot();
});
});
Loading

0 comments on commit d713d69

Please sign in to comment.