fix(snjs): simplify authenticator api for generating options (#2147)
This commit is contained in:
@@ -23,7 +23,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: 'invalid',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticatorName',
|
||||
})
|
||||
|
||||
@@ -31,25 +30,11 @@ describe('AddAuthenticator', () => {
|
||||
expect(result.getError()).toBe('Could not generate authenticator registration options: Given value is not a valid uuid: invalid')
|
||||
})
|
||||
|
||||
it('should return error if username is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: '',
|
||||
authenticatorName: 'authenticatorName',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Could not generate authenticator registration options: Username cannot be empty')
|
||||
})
|
||||
|
||||
it('should return error if authenticatorName is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: '',
|
||||
})
|
||||
|
||||
@@ -64,7 +49,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -79,7 +63,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -96,7 +79,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -111,7 +93,7 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -124,7 +106,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -136,7 +117,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AuthenticatorClientInterface } from '@standardnotes/services'
|
||||
import { Result, UseCaseInterface, Username, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
import { Result, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
|
||||
import { AddAuthenticatorDTO } from './AddAuthenticatorDTO'
|
||||
|
||||
@@ -24,12 +24,6 @@ export class AddAuthenticator implements UseCaseInterface<void> {
|
||||
}
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
const usernameOrError = Username.create(dto.username)
|
||||
if (usernameOrError.isFailed()) {
|
||||
return Result.fail(`Could not generate authenticator registration options: ${usernameOrError.getError()}`)
|
||||
}
|
||||
const username = usernameOrError.getValue()
|
||||
|
||||
const authenticatorNameValidatorResult = Validator.isNotEmpty(dto.authenticatorName)
|
||||
if (authenticatorNameValidatorResult.isFailed()) {
|
||||
return Result.fail(
|
||||
@@ -37,7 +31,7 @@ export class AddAuthenticator implements UseCaseInterface<void> {
|
||||
)
|
||||
}
|
||||
|
||||
const registrationOptions = await this.authenticatorClient.generateRegistrationOptions(userUuid, username)
|
||||
const registrationOptions = await this.authenticatorClient.generateRegistrationOptions()
|
||||
if (registrationOptions === null) {
|
||||
return Result.fail('Could not generate authenticator registration options')
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export interface AddAuthenticatorDTO {
|
||||
userUuid: string
|
||||
username: string
|
||||
authenticatorName: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user