mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
chore: minor formatting changes
This commit is contained in:
67
sample/12-graphql-schema-first/e2e/cats/cats.e2e-spec.ts
Normal file
67
sample/12-graphql-schema-first/e2e/cats/cats.e2e-spec.ts
Normal file
@@ -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
sample/12-graphql-schema-first/e2e/jest-e2e.json
Normal file
13
sample/12-graphql-schema-first/e2e/jest-e2e.json
Normal file
@@ -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"]
|
||||
}
|
||||
97
sample/12-graphql-schema-first/package-lock.json
generated
97
sample/12-graphql-schema-first/package-lock.json
generated
@@ -29,6 +29,7 @@
|
||||
"@nestjs/schematics": "10.1.1",
|
||||
"@nestjs/testing": "10.3.2",
|
||||
"@types/express": "4.17.21",
|
||||
"@types/jest": "29.5.10",
|
||||
"@types/node": "20.17.6",
|
||||
"@types/supertest": "6.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "5.62.0",
|
||||
@@ -2577,7 +2578,7 @@
|
||||
"version": "0.22.0",
|
||||
"resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.22.0.tgz",
|
||||
"integrity": "sha512-HqNBuV/oIlMKdkLshXd1zKBqNQCsuPEsgQOkfFQ/eUKjRlwndXW1AjN9LVkBEIukm00gGXSRmfkl0Wv5VXLnlw==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"fast-glob": "^3.3.2",
|
||||
"minimatch": "^9.0.3",
|
||||
@@ -2589,7 +2590,7 @@
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
@@ -2598,7 +2599,7 @@
|
||||
"version": "9.0.3",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz",
|
||||
"integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
},
|
||||
@@ -2613,7 +2614,7 @@
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz",
|
||||
"integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"mkdirp": "dist/cjs/src/bin.js"
|
||||
},
|
||||
@@ -2792,6 +2793,16 @@
|
||||
"@types/istanbul-lib-report": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/jest": {
|
||||
"version": "29.5.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.10.tgz",
|
||||
"integrity": "sha512-tE4yxKEphEyxj9s4inideLHktW/x6DwesIwWZ9NN1FKf9zbJYsnhBoA9vrHA/IuIOKwPa5PcFBNV4lpMIOEzyQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"expect": "^29.0.0",
|
||||
"pretty-format": "^29.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz",
|
||||
@@ -4164,7 +4175,7 @@
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz",
|
||||
"integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==",
|
||||
"devOptional": true
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/collect-v8-coverage": {
|
||||
"version": "1.0.2",
|
||||
@@ -7993,7 +8004,7 @@
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz",
|
||||
"integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==",
|
||||
"devOptional": true
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/path-exists": {
|
||||
"version": "4.0.0",
|
||||
@@ -9471,7 +9482,7 @@
|
||||
"version": "21.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-21.0.1.tgz",
|
||||
"integrity": "sha512-dbDtVdEAncKctzrVZ+Nr7kHpHkv+0JDJb2MjjpBaj8bFeCkePU9rHfMklmhuLFnpeq/EJZk2IhStY6NzqgjOkg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@ts-morph/common": "~0.22.0",
|
||||
"code-block-writer": "^12.0.0"
|
||||
@@ -10348,8 +10359,7 @@
|
||||
"@apollo/cache-control-types": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.3.tgz",
|
||||
"integrity": "sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g=="
|
||||
},
|
||||
"@apollo/protobufjs": {
|
||||
"version": "1.2.7",
|
||||
@@ -10449,8 +10459,7 @@
|
||||
"@apollo/utils.dropunuseddefinitions": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/utils.dropunuseddefinitions/-/utils.dropunuseddefinitions-2.0.1.tgz",
|
||||
"integrity": "sha512-EsPIBqsSt2BwDsv8Wu76LK5R1KtsVkNoO4b0M5aK0hx+dGg9xJXuqlr7Fo34Dl+y83jmzn+UvEW+t1/GP2melA==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-EsPIBqsSt2BwDsv8Wu76LK5R1KtsVkNoO4b0M5aK0hx+dGg9xJXuqlr7Fo34Dl+y83jmzn+UvEW+t1/GP2melA=="
|
||||
},
|
||||
"@apollo/utils.fetcher": {
|
||||
"version": "2.0.0",
|
||||
@@ -10486,14 +10495,12 @@
|
||||
"@apollo/utils.printwithreducedwhitespace": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/utils.printwithreducedwhitespace/-/utils.printwithreducedwhitespace-2.0.1.tgz",
|
||||
"integrity": "sha512-9M4LUXV/fQBh8vZWlLvb/HyyhjJ77/I5ZKu+NBWV/BmYGyRmoEP9EVAy7LCVoY3t8BDcyCAGfxJaLFCSuQkPUg==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-9M4LUXV/fQBh8vZWlLvb/HyyhjJ77/I5ZKu+NBWV/BmYGyRmoEP9EVAy7LCVoY3t8BDcyCAGfxJaLFCSuQkPUg=="
|
||||
},
|
||||
"@apollo/utils.removealiases": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/utils.removealiases/-/utils.removealiases-2.0.1.tgz",
|
||||
"integrity": "sha512-0joRc2HBO4u594Op1nev+mUF6yRnxoUH64xw8x3bX7n8QBDYdeYgY4tF0vJReTy+zdn2xv6fMsquATSgC722FA==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-0joRc2HBO4u594Op1nev+mUF6yRnxoUH64xw8x3bX7n8QBDYdeYgY4tF0vJReTy+zdn2xv6fMsquATSgC722FA=="
|
||||
},
|
||||
"@apollo/utils.sortast": {
|
||||
"version": "2.0.1",
|
||||
@@ -10506,8 +10513,7 @@
|
||||
"@apollo/utils.stripsensitiveliterals": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/utils.stripsensitiveliterals/-/utils.stripsensitiveliterals-2.0.1.tgz",
|
||||
"integrity": "sha512-QJs7HtzXS/JIPMKWimFnUMK7VjkGQTzqD9bKD1h3iuPAqLsxd0mUNVbkYOPTsDhUKgcvUOfOqOJWYohAKMvcSA==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-QJs7HtzXS/JIPMKWimFnUMK7VjkGQTzqD9bKD1h3iuPAqLsxd0mUNVbkYOPTsDhUKgcvUOfOqOJWYohAKMvcSA=="
|
||||
},
|
||||
"@apollo/utils.usagereporting": {
|
||||
"version": "2.1.0",
|
||||
@@ -11175,8 +11181,7 @@
|
||||
"@graphql-typed-document-node/core": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.1.2.tgz",
|
||||
"integrity": "sha512-9anpBMM9mEgZN4wr2v8wHJI2/u5TnnggewRN6OlvXTTnuVyoY19X6rOv9XTqKRw6dcGKwZsBi8n0kDE2I5i4VA==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-9anpBMM9mEgZN4wr2v8wHJI2/u5TnnggewRN6OlvXTTnuVyoY19X6rOv9XTqKRw6dcGKwZsBi8n0kDE2I5i4VA=="
|
||||
},
|
||||
"@humanwhocodes/config-array": {
|
||||
"version": "0.11.10",
|
||||
@@ -11854,8 +11859,7 @@
|
||||
"@nestjs/mapped-types": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.0.5.tgz",
|
||||
"integrity": "sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg=="
|
||||
},
|
||||
"@nestjs/platform-express": {
|
||||
"version": "10.3.8",
|
||||
@@ -12020,7 +12024,7 @@
|
||||
"version": "0.22.0",
|
||||
"resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.22.0.tgz",
|
||||
"integrity": "sha512-HqNBuV/oIlMKdkLshXd1zKBqNQCsuPEsgQOkfFQ/eUKjRlwndXW1AjN9LVkBEIukm00gGXSRmfkl0Wv5VXLnlw==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-glob": "^3.3.2",
|
||||
"minimatch": "^9.0.3",
|
||||
@@ -12032,7 +12036,7 @@
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0"
|
||||
}
|
||||
@@ -12041,7 +12045,7 @@
|
||||
"version": "9.0.3",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz",
|
||||
"integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
}
|
||||
@@ -12050,7 +12054,7 @@
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz",
|
||||
"integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==",
|
||||
"devOptional": true
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -12222,6 +12226,16 @@
|
||||
"@types/istanbul-lib-report": "*"
|
||||
}
|
||||
},
|
||||
"@types/jest": {
|
||||
"version": "29.5.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.10.tgz",
|
||||
"integrity": "sha512-tE4yxKEphEyxj9s4inideLHktW/x6DwesIwWZ9NN1FKf9zbJYsnhBoA9vrHA/IuIOKwPa5PcFBNV4lpMIOEzyQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"expect": "^29.0.0",
|
||||
"pretty-format": "^29.0.0"
|
||||
}
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz",
|
||||
@@ -12628,15 +12642,13 @@
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz",
|
||||
"integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"acorn-jsx": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
|
||||
"integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"acorn-walk": {
|
||||
"version": "8.2.0",
|
||||
@@ -12691,8 +12703,7 @@
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz",
|
||||
"integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"ansi-colors": {
|
||||
"version": "4.1.3",
|
||||
@@ -13242,7 +13253,7 @@
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-12.0.0.tgz",
|
||||
"integrity": "sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==",
|
||||
"devOptional": true
|
||||
"dev": true
|
||||
},
|
||||
"collect-v8-coverage": {
|
||||
"version": "1.0.2",
|
||||
@@ -13444,8 +13455,7 @@
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz",
|
||||
"integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"deep-is": {
|
||||
"version": "0.1.3",
|
||||
@@ -13803,8 +13813,7 @@
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz",
|
||||
"integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"eslint-import-resolver-node": {
|
||||
"version": "0.3.9",
|
||||
@@ -14539,8 +14548,7 @@
|
||||
"graphql-ws": {
|
||||
"version": "5.16.0",
|
||||
"resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.16.0.tgz",
|
||||
"integrity": "sha512-Ju2RCU2dQMgSKtArPbEtsK5gNLnsQyTNIo/T7cZNp96niC1x0KdJNZV0TIoilceBPQwfb5itrGl8pkFeOUMl4A==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-Ju2RCU2dQMgSKtArPbEtsK5gNLnsQyTNIo/T7cZNp96niC1x0KdJNZV0TIoilceBPQwfb5itrGl8pkFeOUMl4A=="
|
||||
},
|
||||
"has": {
|
||||
"version": "1.0.3",
|
||||
@@ -15292,8 +15300,7 @@
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz",
|
||||
"integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"jest-regex-util": {
|
||||
"version": "29.6.3",
|
||||
@@ -16113,7 +16120,7 @@
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz",
|
||||
"integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==",
|
||||
"devOptional": true
|
||||
"dev": true
|
||||
},
|
||||
"path-exists": {
|
||||
"version": "4.0.0",
|
||||
@@ -16936,8 +16943,7 @@
|
||||
"ws": {
|
||||
"version": "7.5.7",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.7.tgz",
|
||||
"integrity": "sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -17153,7 +17159,7 @@
|
||||
"version": "21.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-21.0.1.tgz",
|
||||
"integrity": "sha512-dbDtVdEAncKctzrVZ+Nr7kHpHkv+0JDJb2MjjpBaj8bFeCkePU9rHfMklmhuLFnpeq/EJZk2IhStY6NzqgjOkg==",
|
||||
"devOptional": true,
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@ts-morph/common": "~0.22.0",
|
||||
"code-block-writer": "^12.0.0"
|
||||
@@ -17571,8 +17577,7 @@
|
||||
"ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ=="
|
||||
},
|
||||
"xss": {
|
||||
"version": "1.0.14",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "echo 'No e2e tests implemented yet.'"
|
||||
"test:e2e": "jest --config ./e2e/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/server": "4.9.3",
|
||||
@@ -39,6 +39,7 @@
|
||||
"@nestjs/schematics": "10.1.1",
|
||||
"@nestjs/testing": "10.3.2",
|
||||
"@types/express": "4.17.21",
|
||||
"@types/jest": "29.5.10",
|
||||
"@types/node": "20.17.6",
|
||||
"@types/supertest": "6.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "5.62.0",
|
||||
@@ -55,5 +56,36 @@
|
||||
"ts-node": "10.9.2",
|
||||
"tsconfig-paths": "4.2.0",
|
||||
"typescript": "5.3.3"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s",
|
||||
"!main.(t|j)s",
|
||||
"!**/*.module.(t|j)s",
|
||||
"!**/*.dto.(t|j)s",
|
||||
"!**/*.entity.(t|j)s",
|
||||
"!**/*.guard.(t|j)s",
|
||||
"!**/*.response.(t|j)s",
|
||||
"!**/*.strategy.(t|j)s",
|
||||
"!**/*.args.(t|j)s",
|
||||
"!**/*.types.(t|j)s",
|
||||
"!**/*.directive.(t|j)s",
|
||||
"!**/*.plugin.(t|j)s",
|
||||
"!**/*.scalar.(t|j)s",
|
||||
"!**/*.schema.(t|j)s",
|
||||
"!**/node_modules/**"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { Cat, Owner } from '../graphql.schema';
|
||||
import { OwnersService } from '../owners/owners.service';
|
||||
import { CatOwnerResolver } from './cat-owner.resolver';
|
||||
|
||||
describe('CatOwnerResolver', () => {
|
||||
let resolver: CatOwnerResolver;
|
||||
let ownersService: OwnersService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleRef: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CatOwnerResolver,
|
||||
{
|
||||
provide: OwnersService,
|
||||
useValue: {
|
||||
findOneById: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
resolver = moduleRef.get(CatOwnerResolver);
|
||||
ownersService = moduleRef.get(OwnersService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
|
||||
it('should resolve the owner for a cat', async () => {
|
||||
const cat: Cat & { ownerId: number } = { id: 1, ownerId: 101 };
|
||||
const owner: Owner = { id: 101, name: 'Kambale' };
|
||||
|
||||
jest.spyOn(ownersService, 'findOneById').mockImplementation(() => owner);
|
||||
|
||||
const resolvedOwner = await resolver.owner(cat);
|
||||
|
||||
expect(ownersService.findOneById).toHaveBeenCalledWith(cat.ownerId);
|
||||
expect(resolvedOwner).toEqual(owner);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
import { Cat } from '../graphql.schema';
|
||||
import { CatsResolver } from './cats.resolver';
|
||||
import { CatsService } from './cats.service';
|
||||
|
||||
import { MINIMUM_AGE, MINIMUM_AGE_ERROR } from './dto/create-cat.dto';
|
||||
|
||||
describe('CatsResolver', () => {
|
||||
let resolver: CatsResolver;
|
||||
const cat: Cat = { name: 'Cat', age: 5 };
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleRef: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CatsResolver,
|
||||
{
|
||||
provide: CatsService,
|
||||
useValue: {
|
||||
create: jest
|
||||
.fn()
|
||||
.mockImplementation((cat: Cat) => ({ id: 1, ...cat })),
|
||||
findAll: jest.fn().mockReturnValue([cat]),
|
||||
findOneById: jest
|
||||
.fn()
|
||||
.mockImplementation((id: number) => ({ ...cat, id })),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
resolver = moduleRef.get<CatsResolver>(CatsResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create a new cat', async () => {
|
||||
const newCat = await resolver.create({ name: cat.name, age: cat.age });
|
||||
expect(newCat.name).toEqual(cat.name);
|
||||
expect(newCat).toEqual({ id: 1, ...cat });
|
||||
});
|
||||
|
||||
it(`should fail to save if the age is under ${MINIMUM_AGE}`, async () => {
|
||||
try {
|
||||
await resolver.create({ name: cat.name, age: 0 });
|
||||
} catch (error) {
|
||||
expect(error.message).toBe(MINIMUM_AGE_ERROR);
|
||||
}
|
||||
});
|
||||
|
||||
it('should return all cats', async () => {
|
||||
const cats = await resolver.getCats();
|
||||
expect(cats.length).toEqual(1);
|
||||
expect(cats[0].name).toEqual(cat.name);
|
||||
});
|
||||
|
||||
it('should return a cat by id', async () => {
|
||||
const cat = await resolver.findOneById(1);
|
||||
expect(cat).toEqual({ ...cat, id: 1 });
|
||||
});
|
||||
});
|
||||
42
sample/12-graphql-schema-first/src/cats/cats.service.spec.ts
Normal file
42
sample/12-graphql-schema-first/src/cats/cats.service.spec.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CatsService } from './cats.service';
|
||||
import { Cat } from 'src/graphql.schema';
|
||||
|
||||
describe('CatsService', () => {
|
||||
let service: CatsService;
|
||||
const cat: Cat = { name: 'Cat', age: 5 };
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CatsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CatsService>(CatsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create a new cat', () => {
|
||||
const newCat = service.create(cat);
|
||||
expect(newCat.name).toEqual(cat.name);
|
||||
expect(newCat).toEqual({ id: 1, ...cat });
|
||||
});
|
||||
|
||||
it('should return all cats', () => {
|
||||
const cats = service.findAll();
|
||||
expect(cats.length).toEqual(1);
|
||||
expect(cats[0].name).toEqual(cat.name);
|
||||
});
|
||||
|
||||
it('should return a cat by id', () => {
|
||||
const cat = service.findOneById(1);
|
||||
expect(cat).toEqual({ ...cat, id: 1 });
|
||||
});
|
||||
|
||||
it('should return undefined if cat not found', () => {
|
||||
const cat = service.findOneById(2);
|
||||
expect(cat).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Min } from 'class-validator';
|
||||
import { CreateCatInput } from '../../graphql.schema';
|
||||
|
||||
export const MINIMUM_AGE = 1;
|
||||
export const MINIMUM_AGE_ERROR = `Age must be greater than ${MINIMUM_AGE}`;
|
||||
|
||||
export class CreateCatDto extends CreateCatInput {
|
||||
@Min(1)
|
||||
@Min(MINIMUM_AGE, { message: MINIMUM_AGE_ERROR })
|
||||
age: number;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { Owner } from '../graphql.schema';
|
||||
import { OwnersService } from './owners.service';
|
||||
|
||||
describe('OwnersService', () => {
|
||||
let service: OwnersService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [OwnersService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<OwnersService>(OwnersService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe('findOneById', () => {
|
||||
it('should return an owner if exists', () => {
|
||||
const ownerId = 1;
|
||||
const expectedOwner: Owner = { id: 1, name: 'Jon', age: 5 };
|
||||
|
||||
const result = service.findOneById(ownerId);
|
||||
|
||||
expect(result).toEqual(expectedOwner);
|
||||
});
|
||||
|
||||
it('should return undefined if owner does not exist', () => {
|
||||
const ownerId = 9999;
|
||||
|
||||
const result = service.findOneById(ownerId);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user