Skip to content

Commit

Permalink
Merge branch 'pacyL2K19-test/sample-12-graphql-schema-first'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 20, 2024
2 parents ddf99c3 + d98524a commit 5064d9b
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 48 deletions.
67 changes: 67 additions & 0 deletions sample/12-graphql-schema-first/e2e/cats/cats.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';

import { Cat } from '../../src/graphql.schema';
import { AppModule } from '../../src/app.module';

describe('Cats Resolver (e2e)', () => {
let app: INestApplication;
let cat: Cat;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

afterEach(async () => {
await app.close();
});

it('should create a new cat', async () => {
const query = `
mutation {
createCat(createCatInput: { name: "Cat", age: 5 }) {
id
name
age
}
}
`;

return request(app.getHttpServer())
.post('/graphql')
.send({ query })
.expect(200)
.expect(response => {
cat = response.body.data.createCat;
expect(cat.name).toEqual('Cat');
expect(cat.age).toEqual(5);
});
});

it('should get all cats', async () => {
const query = `
query {
cats {
id
name
age
}
}
`;

return request(app.getHttpServer())
.post('/graphql')
.send({ query })
.expect(200)
.expect(response => {
const cats = response.body.data.cats;
expect(cats[0].name).toEqual('Cat');
});
});
});
13 changes: 13 additions & 0 deletions sample/12-graphql-schema-first/e2e/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"moduleFileExtensions": ["ts", "tsx", "js", "json"],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "/e2e/.*\\.(e2e-test|e2e-spec).(ts|tsx|js)$",
"collectCoverageFrom": [
"src/**/*.{js,jsx,tsx,ts}",
"!**/node_modules/**",
"!**/vendor/**"
],
"coverageReporters": ["json", "lcov"]
}
Loading

0 comments on commit 5064d9b

Please sign in to comment.