This repository has been archived by the owner on Feb 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
402851a
commit eb6f0ca
Showing
70 changed files
with
1,778 additions
and
1,943 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
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
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 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest/utils'); | ||
const { compilerOptions } = require('./tsconfig'); | ||
|
||
module.exports = { | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }), | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,tsx,ts}', '!**/node_modules/**', '!**/vendor/**'], | ||
coverageReporters: ['json', 'lcov'], | ||
testRegex: '/src/.*\\.(test|spec).(ts|tsx|js)$', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
}, | ||
}; |
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
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,29 +1,46 @@ | ||
import { Test } from '@nestjs/testing'; | ||
|
||
import { ConfigModule } from '../../lib/config'; | ||
import { ConfigModule } from '@lib/config'; | ||
import { JwtModule } from '@lib/jwt'; | ||
|
||
import { AuthController } from './auth.controller'; | ||
import { AuthService } from './auth.service'; | ||
|
||
describe('CatsController', () => { | ||
describe('AuthController', () => { | ||
let authController: AuthController; | ||
let authService: AuthService; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [ConfigModule], | ||
imports: [ConfigModule, JwtModule], | ||
controllers: [AuthController], | ||
providers: [AuthService] | ||
providers: [ | ||
{ | ||
provide: AuthService, | ||
useValue: { | ||
login: jest.fn(() => ({ accessToken: 'ACCESS_TOKEN' })), | ||
authorize: jest.fn(() => ({ token: 'TOKEN' })) | ||
} | ||
} | ||
] | ||
}).compile(); | ||
|
||
authService = module.get<AuthService>(AuthService); | ||
authController = module.get<AuthController>(AuthController); | ||
}); | ||
|
||
describe('login', () => { | ||
it('should return true', async () => { | ||
const result = true; | ||
jest.spyOn(authService, 'login').mockImplementation(() => result); | ||
expect(await authController.login({ username: 'A', password: 'A' })).toBe(result); | ||
it('should return access token', async () => { | ||
const body = { username: 'john', password: 'doe' }; | ||
const result = { accessToken: 'ACCESS_TOKEN' }; | ||
expect(await authController.login(body)).toMatchObject(result); | ||
}); | ||
}); | ||
|
||
describe('authorize', () => { | ||
it('should return token', async () => { | ||
const body = { clientId: 'x' }; | ||
const header = { udid: 'x' }; | ||
const result = { token: 'TOKEN' }; | ||
expect(await authController.authorize(body, header as any)).toMatchObject(result); | ||
}); | ||
}); | ||
}); |
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.