-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from olaviolacerda/feature/testing-unit
Feature/testing unit
- Loading branch information
Showing
6 changed files
with
317 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { JwtService } from '@nestjs/jwt'; | ||
|
||
export const mockTokens = { | ||
accessToken: 'fakeJwtToken', | ||
refreshToken: 'fakeJwtToken', | ||
}; | ||
|
||
export const mockJwtService: Partial<JwtService> = { | ||
signAsync: jest.fn().mockResolvedValue('fakeJwtToken'), | ||
}; |
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,20 @@ | ||
import { Role } from '../../../src/common/enums/role.enum'; | ||
import { User } from '../../../src/core/entities/user.entity'; | ||
|
||
export const mockUser: User = { | ||
id: 'id', | ||
username: 'fake', | ||
role: Role.User, | ||
refreshToken: 'refreshToken', | ||
password: 'fakePass', | ||
hashPassword: () => Promise.resolve(), | ||
}; | ||
|
||
export class UsersRepositoryFake { | ||
public async create(): Promise<any> {} | ||
public async save(): Promise<any> {} | ||
public async remove(): Promise<any> {} | ||
public async findOne(): Promise<any> {} | ||
public async find(): Promise<any> {} | ||
public async preload(): Promise<any> {} | ||
} |
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,37 @@ | ||
import { AuthHelper } from '../../../../src/core/providers/helpers/auth.helper'; | ||
|
||
jest.mock('bcrypt', () => ({ | ||
async hashSync(): Promise<string> { | ||
return 'hash'; | ||
}, | ||
})); | ||
|
||
jest.mock('crypto', () => ({ | ||
createHash: jest.fn().mockReturnValue({ | ||
update: jest.fn().mockReturnThis(), | ||
digest: jest.fn(), | ||
}), | ||
})); | ||
|
||
describe('AuthHelper', () => { | ||
let helper: AuthHelper; | ||
|
||
beforeEach(async () => { | ||
helper = new AuthHelper(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(helper).toBeDefined(); | ||
}); | ||
|
||
it('should hash token', async () => { | ||
const refreshToken = 'refreshToken'; | ||
const hashedToken = await helper.hashToken(refreshToken); | ||
|
||
expect(hashedToken).toBe('hash'); | ||
}); | ||
}); |
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.