-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
267 additions
and
135 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
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 |
---|---|---|
@@ -1,17 +1,6 @@ | ||
module.exports = { | ||
name: 'api-e2e', | ||
testRegex: '.e2e-spec.ts$', | ||
transform: { | ||
'^.+\\.(t|j)s$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['js', 'json', 'ts'], | ||
collectCoverage: true, | ||
coverageReporters: ['html'], | ||
testEnvironment: 'node', | ||
preset: '../../jest.config.js', | ||
testMatch: ['**/+(*.)+(e2e-spec|e2e-test).+(ts|js)?(x)'], | ||
coverageDirectory: '../../coverage/apps/api-e2e', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: 'apps/api-e2e/tsconfig.e2e.json', | ||
}, | ||
}, | ||
}; |
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
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,78 @@ | ||
// import 'jest'; | ||
// import * as supertest from 'supertest'; | ||
// import { Test } from '@nestjs/testing'; | ||
// import { INestApplication } from '@nestjs/common'; | ||
// | ||
// import { AuthModule } from '../../src/auth/auth.module'; | ||
// import { AuthService } from '../../src/auth/auth.service'; | ||
// import { AuthenticateDto } from '../../src/auth/dto/authenticate-dto'; | ||
// import { users } from '../../src/auth/users.const'; | ||
// | ||
// describe('Auth', () => { | ||
// let app: INestApplication; | ||
// | ||
// // | ||
// // Setup mock data & services | ||
// // | ||
// const regularUser = users.find(user => user.username === 'user@mydomain.com'); | ||
// let regularUserJWTToken: any; | ||
// const staffUser = users.find(user => user.username === 'staff@mydomain.com'); | ||
// let staffUserJWTToken: any; | ||
// | ||
// beforeAll(async () => { | ||
// // | ||
// // Instantiate nest application | ||
// // | ||
// const module = await Test.createTestingModule({ | ||
// imports: [AuthModule], | ||
// }).compile(); | ||
// | ||
// app = module.createNestApplication(); | ||
// await app.init(); | ||
// | ||
// supertest(app.getHttpServer()) | ||
// .post('/api/auth/authenticate') | ||
// .send({ authenticateDto: { username: regularUser.username, password: regularUser.password } }) | ||
// .end((err, res) => { | ||
// regularUserJWTToken = JSON.parse(res.text).data; | ||
// }); | ||
// | ||
// supertest(app.getHttpServer()) | ||
// .post('/api/auth/authenticate') | ||
// .send({ authenticateDto: { username: staffUser.username, password: staffUser.password } }) | ||
// .end((err, res) => { | ||
// staffUserJWTToken = JSON.parse(res.text).data; | ||
// }); | ||
// }); | ||
// | ||
// it(`/POST auth`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .post('/api/auth/authenticate') | ||
// .send({ authenticateDto: { username: regularUser.username, password: regularUser.password } }) | ||
// .expect(201); | ||
// }); | ||
// | ||
// it(`/GET protected data without auth token`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/auth/data') | ||
// .expect(401); | ||
// }); | ||
// | ||
// it(`/GET protected data with wrong role`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/auth/data') | ||
// .set('authorization', `Bearer ${regularUserJWTToken.accessToken}`) | ||
// .expect(403); | ||
// }); | ||
// | ||
// it(`/GET protected data with correct role`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/auth/data') | ||
// .set('authorization', `Bearer ${staffUserJWTToken.accessToken}`) | ||
// .expect(200); | ||
// }); | ||
// | ||
// afterAll(async () => { | ||
// await app.close(); | ||
// }); | ||
// }); |
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,99 @@ | ||
// import 'jest'; | ||
// import * as supertest from 'supertest'; | ||
// import { Test } from '@nestjs/testing'; | ||
// import { CatsModule } from '../../src/cats/cats.module'; | ||
// import { INestApplication } from '@nestjs/common'; | ||
// import { AuthService } from '../../src/auth/auth.service'; | ||
// import { AccessTokenWithMetadata } from '../../src/auth/interfaces/jwt-accessTokenData.interface'; | ||
// import { users } from '../../src/auth/users.const'; | ||
// import { ConfigService } from '../../src/common/services/config.service'; | ||
// import { CatsService } from '../../src/cats/cats.service'; | ||
// | ||
// describe('Notifications', () => { | ||
// let app: INestApplication; | ||
// let userAuthToken: AccessTokenWithMetadata; | ||
// let staffAuthToken: AccessTokenWithMetadata; | ||
// const configService = new ConfigService(); | ||
// | ||
// // | ||
// // Set configuration flags | ||
// // | ||
// configService.nodeEnv = 'test'; | ||
// | ||
// // | ||
// // Setup mock data & services | ||
// // | ||
// const userJwtPayload = { | ||
// user: users.find(user => user.username === 'user@mydomain.com'), | ||
// }; | ||
// | ||
// const staffJwtPayload = { | ||
// user: users.find(user => user.username === 'staff@mydomain.com'), | ||
// }; | ||
// | ||
// const catsService = { findAll: () => ['test'] }; | ||
// | ||
// beforeAll(async () => { | ||
// // | ||
// // Instantiate nest application | ||
// // | ||
// const module = await Test.createTestingModule({ | ||
// imports: [CatsModule], | ||
// }) | ||
// .overrideProvider(CatsService) | ||
// .useValue(catsService) | ||
// .compile(); | ||
// | ||
// app = module.createNestApplication(); | ||
// await app.init(); | ||
// | ||
// userAuthToken = await app.get(AuthService).createToken(userJwtPayload); | ||
// staffAuthToken = await app.get(AuthService).createToken(staffJwtPayload); | ||
// }); | ||
// | ||
// it(`/GET cats`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/cats') | ||
// .expect(200) | ||
// .expect({ | ||
// data: catsService.findAll(), | ||
// }); | ||
// }); | ||
// | ||
// it(`/GET cats with auth token`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/cats') | ||
// .set('authorization', `Bearer ${userAuthToken}`) | ||
// .expect(200) | ||
// .expect({ | ||
// data: catsService.findAll(), | ||
// }); | ||
// }); | ||
// | ||
// it(`/GET protected cats without auth token`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/cats/protected') | ||
// .expect(401); | ||
// }); | ||
// | ||
// it(`/GET protected cats with user auth token`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/cats/protected') | ||
// .set('authorization', `Bearer ${userAuthToken.accessToken}`) | ||
// .expect(403); | ||
// }); | ||
// | ||
// it(`/GET protected cats with staff auth token`, () => { | ||
// return supertest(app.getHttpServer()) | ||
// .get('/api/cats/protected') | ||
// .set('authorization', `Bearer ${staffAuthToken.accessToken}`) | ||
// .expect(200) | ||
// .expect({ | ||
// data: catsService.findAll(), | ||
// }); | ||
// }); | ||
// | ||
// afterAll(async () => { | ||
// await app.close(); | ||
// }); | ||
// }); |
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
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 |
---|---|---|
@@ -1,30 +1,7 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": ["tslint:recommended"], | ||
"jsRules": { | ||
"no-unused-expression": true | ||
}, | ||
"rules": { | ||
"eofline": false, | ||
"quotemark": [true, "single"], | ||
"indent": false, | ||
"member-access": [false], | ||
"ordered-imports": [false], | ||
"max-line-length": [true, 150], | ||
"member-ordering": [false], | ||
"curly": false, | ||
"interface-name": [false], | ||
"array-type": [false], | ||
"no-console": false, | ||
"no-empty-interface": false, | ||
"no-empty": false, | ||
"arrow-parens": false, | ||
"object-literal-sort-keys": false, | ||
"no-unused-expression": false, | ||
"max-classes-per-file": [false], | ||
"variable-name": [false], | ||
"one-line": [false], | ||
"one-variable-per-declaration": [false] | ||
}, | ||
"rulesDirectory": [] | ||
"extends": "../../tslint.json", | ||
"rules": {}, | ||
"jsRules":{ | ||
"object-literal-sort-keys": false | ||
} | ||
} |
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
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
Oops, something went wrong.