diff --git a/composables/api/index.ts b/composables/api/index.ts index 93143d36..fff76ec6 100644 --- a/composables/api/index.ts +++ b/composables/api/index.ts @@ -7,3 +7,4 @@ export { default as useLogoutUser } from './useLogoutUser' export { default as useRecoverAccount } from './useRecoverAccount' export { default as useRegisterUser } from './useRegisterUser' export { default as useValidateRecoveryToken } from './useValidateRecoveryToken' +export { default as useResendAccountConfirmation } from './useResendAccountConfirmation' diff --git a/composables/api/useResendAccountConfirmation/index.ts b/composables/api/useResendAccountConfirmation/index.ts new file mode 100644 index 00000000..1971b2a8 --- /dev/null +++ b/composables/api/useResendAccountConfirmation/index.ts @@ -0,0 +1,25 @@ +import { + type ApiResponse, + type optionalParameters, + useApi, +} from 'composables/useApi' +import { Account } from 'lib/api/Account' + +/** + * Resends the account confirmation email for a newly-registered user. + */ +export async function useResendAccountConfirmation( + opts: optionalParameters = {}, +): Promise> { + const { onError, onOkay } = opts + const account = new Account({ + baseUrl: useRuntimeConfig().public.BACKEND_BASE_URL, + }) + + return await useApi(async () => await account.confirmCreate(), { + onError, + onOkay, + }) +} + +export default useResendAccountConfirmation diff --git a/composables/api/useResendAccountConfirmation/useResendAccountConfirmation.test.ts b/composables/api/useResendAccountConfirmation/useResendAccountConfirmation.test.ts new file mode 100644 index 00000000..4dbcccc3 --- /dev/null +++ b/composables/api/useResendAccountConfirmation/useResendAccountConfirmation.test.ts @@ -0,0 +1,20 @@ +import { useResendAccountConfirmation } from '.' + +const mockSuccessResendAccount = vi.fn(() => Promise.resolve({ ok: true })) + +describe('useResendAccountConfirmation', () => { + describe('when everything is successful', () => { + it('changes the password for the user', async () => { + vi.mock('lib/api/Account', () => ({ + Account: function Account() { + this.confirmCreate = mockSuccessResendAccount + }, + })) + + await useResendAccountConfirmation() + + expect(mockSuccessResendAccount).toBeCalledTimes(1) + expect(mockSuccessResendAccount).toBeCalledWith() + }) + }) +})