This commit is contained in:
parent
0f3615ee65
commit
f939caf2d9
2 changed files with 38 additions and 1 deletions
|
@ -127,6 +127,43 @@ describe('Register', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('should register a new user with default set of roles on new api version', async () => {
|
||||
const role = new Role()
|
||||
role.name = RoleName.NAMES.CoreUser
|
||||
|
||||
roleRepository.findOneByName = jest.fn().mockReturnValueOnce(role)
|
||||
|
||||
expect(
|
||||
await createUseCase().execute({
|
||||
email: 'test@test.te',
|
||||
password: 'asdzxc',
|
||||
updatedWithUserAgent: 'Mozilla',
|
||||
apiVersion: '20240226',
|
||||
ephemeralSession: false,
|
||||
version: '004',
|
||||
pwCost: 11,
|
||||
pwSalt: 'qweqwe',
|
||||
pwNonce: undefined,
|
||||
}),
|
||||
).toEqual({ success: true, authResponse: { foo: 'bar' } })
|
||||
|
||||
expect(userRepository.save).toHaveBeenCalledWith({
|
||||
email: 'test@test.te',
|
||||
encryptedPassword: expect.any(String),
|
||||
encryptedServerKey: 'test',
|
||||
serverEncryptionVersion: 1,
|
||||
pwCost: 11,
|
||||
pwNonce: undefined,
|
||||
pwSalt: 'qweqwe',
|
||||
updatedWithUserAgent: 'Mozilla',
|
||||
uuid: expect.any(String),
|
||||
version: '004',
|
||||
createdAt: new Date(1),
|
||||
updatedAt: new Date(1),
|
||||
roles: Promise.resolve([role]),
|
||||
})
|
||||
})
|
||||
|
||||
it('should fail to register if applying default settings fails', async () => {
|
||||
applyDefaultSettings.execute = jest.fn().mockReturnValue(Result.fail('error'))
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ export class Register implements UseCaseInterface {
|
|||
|
||||
const { email, password, apiVersion, ephemeralSession, ...registrationFields } = dto
|
||||
|
||||
if (apiVersion !== ApiVersion.v20200115) {
|
||||
if (![ApiVersion.v20200115, ApiVersion.v20240226].includes(apiVersion as ApiVersion)) {
|
||||
return {
|
||||
success: false,
|
||||
errorMessage: `Unsupported api version: ${apiVersion}`,
|
||||
|
|
Loading…
Reference in a new issue