-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pacyL2K19-test/sample-12-graphql-schema-first'
- Loading branch information
Showing
9 changed files
with
353 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Oops, something went wrong.