-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix login/register testcases for
auth.controller.ts
- Loading branch information
1 parent
7f3bc91
commit 719ccb4
Showing
1 changed file
with
14 additions
and
25 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 |
---|---|---|
|
@@ -11,9 +11,10 @@ import { Pure } from '@isomera/interfaces' | |
describe('Auth Controller', () => { | ||
let controller: AuthController | ||
let mockedAuthService: jest.Mocked<AuthService> | ||
const user = createMock({ | ||
const testUser = createMock({ | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
password: '$pa55w00rd', | ||
email: '[email protected]' | ||
}) as UserEntity | ||
|
||
|
@@ -42,28 +43,20 @@ describe('Auth Controller', () => { | |
}) | ||
|
||
it('should register a new user', async () => { | ||
const register = { | ||
const register: Pure<SignUpWithEmailCredentialsDto> = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
password: 'Pa$$w0rd', | ||
policy: true, | ||
isPrivacyPolicyAccepted: true | ||
} | ||
|
||
mockedAuthService.register.mockResolvedValue( | ||
createMock<UserEntity>({ | ||
email: register.email, | ||
firstName: 'John', | ||
lastName: 'Doe' | ||
}) as UserEntity | ||
) | ||
const result = await controller.register(register) | ||
const userEntityObjectKeys = Object.getOwnPropertyNames((result)) | ||
|
||
expect(userEntityObjectKeys).not.toEqual( | ||
expect.arrayContaining(['password']) | ||
) | ||
jest.spyOn(mockedAuthService, 'register').mockImplementationOnce(() => { | ||
return Promise.resolve(register) as Promise<UserEntity> | ||
}) | ||
|
||
const user = await controller.register(register) | ||
expect(user).toHaveProperty('email', register.email) | ||
expect(user).not.toHaveProperty('password', undefined) | ||
}) | ||
|
||
it('should log in an user', async () => { | ||
|
@@ -74,16 +67,12 @@ describe('Auth Controller', () => { | |
lastName: 'Doe', | ||
}) as UserEntity | ||
) | ||
const result: UserEntity = await controller.login(user) | ||
const userEntityObjectKeys = Object.getOwnPropertyNames((result)) | ||
|
||
expect(userEntityObjectKeys).not.toEqual( | ||
expect.arrayContaining(['password']) | ||
) | ||
expect(result).toHaveProperty('email') | ||
const user: UserEntity = await controller.login(testUser) | ||
expect(user).not.toHaveProperty('password', undefined) | ||
expect(user).toHaveProperty('email') | ||
}) | ||
|
||
it('should got me logged', () => { | ||
expect(controller.me(user)).toEqual(user) | ||
expect(controller.me(testUser)).toEqual(testUser) | ||
}) | ||
}) |