Files
standardnotes-app-web/packages/snjs/lib/Domain/UseCase/GetRecoveryCodes/GetRecoveryCodes.spec.ts
Karol Sójko 5e6c901c21 feat: recovery codes UI (recovery sign in + get recovery codes) (#2139)
* feat(web): show recovery codes

* feat(web): add recovery sign in

* fix: copy

* fix: styles

* feat: add "copy to clipboard" button

* style: copy

* fix: copy button bg

* style: singularize recovery codes

* style: singularize recovery codes

* feat: password validation

Co-authored-by: Aman Harwara <amanharwara@protonmail.com>
Co-authored-by: Mo <mo@standardnotes.com>
2023-01-10 21:33:44 +01:00

49 lines
1.6 KiB
TypeScript

import { AuthClientInterface } from '@standardnotes/services'
import { SettingsClientInterface } from '@Lib/Services/Settings/SettingsClientInterface'
import { GetRecoveryCodes } from './GetRecoveryCodes'
describe('GetRecoveryCodes', () => {
let authClient: AuthClientInterface
let settingsClient: SettingsClientInterface
const createUseCase = () => new GetRecoveryCodes(authClient, settingsClient)
beforeEach(() => {
authClient = {} as jest.Mocked<AuthClientInterface>
authClient.generateRecoveryCodes = jest.fn().mockResolvedValue('recovery-codes')
settingsClient = {} as jest.Mocked<SettingsClientInterface>
settingsClient.getSetting = jest.fn().mockResolvedValue('existing-recovery-codes')
})
it('should return existing recovery code if they exist', async () => {
const useCase = createUseCase()
const result = await useCase.execute()
expect(result.getValue()).toBe('existing-recovery-codes')
})
it('should generate recovery code if they do not exist', async () => {
settingsClient.getSetting = jest.fn().mockResolvedValue(undefined)
const useCase = createUseCase()
const result = await useCase.execute()
expect(result.getValue()).toBe('recovery-codes')
})
it('should return error if recovery code could not be generated', async () => {
settingsClient.getSetting = jest.fn().mockResolvedValue(undefined)
authClient.generateRecoveryCodes = jest.fn().mockResolvedValue(false)
const useCase = createUseCase()
const result = await useCase.execute()
expect(result.isFailed()).toBe(true)
})
})