-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathapp.e2e-spec.ts
More file actions
53 lines (45 loc) · 1.47 KB
/
Copy pathapp.e2e-spec.ts
File metadata and controls
53 lines (45 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import { GraphQLModule } from "@nestjs/graphql";
import { ApolloServerBase } from 'apollo-server-core';
import gql from "graphql-tag";
import { AppModule } from "./../src/app.module";
import { Factory } from '@linnify/typeorm-factory';
import { Account } from "../src/account/account.entity";
import { ApolloDriver } from "@nestjs/apollo";
class AccountFactory extends Factory<Account> {
entity = Account;
name = 'name'
}
describe("AppModule", () => {
let app: INestApplication;
let apolloClient: ApolloServerBase;
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
const graphqlModule = app.get<GraphQLModule<ApolloDriver>>(GraphQLModule);
apolloClient = graphqlModule.graphQlAdapter?.instance;
});
afterAll(() => app.close());
it("defined", () => expect(app).toBeDefined());
it("/graphql(POST) getAccounts", async () => {
const f = new AccountFactory();
const account = await f.create();
const result = await apolloClient.executeOperation({
query: gql`
query q($ids: [ID!]!) {
getAccounts(ids: $ids) {
id
}
}
`,
variables: {
ids: [account.id],
},
});
expect(result.errors).toBeUndefined();
});
});