diff --git a/middleware/confirm-account.ts b/middleware/confirm-account.ts new file mode 100644 index 00000000..14e5582a --- /dev/null +++ b/middleware/confirm-account.ts @@ -0,0 +1,29 @@ +import { useConfirmAccount } from 'composables/api' +import { useModalAlert } from 'composables/useModalAlert' + +export default defineNuxtRouteMiddleware((_to, from) => { + const route = useRoute() + const confirmationCode = route.query.code as string + const modalAlertState = useModalAlert().value + + if (from !== `/confirm-account?code=${confirmationCode}`) { + navigateTo('/', { replace: true }) + } + + useConfirmAccount(confirmationCode, { + onError: () => { + modalAlertState.show = true + modalAlertState.title = 'Something went wrong...' + modalAlertState.body = 'Unable to confirm account.' + modalAlertState.type = 'error' + navigateTo('/', { replace: true }) + }, + onOkay: () => { + modalAlertState.show = true + modalAlertState.title = 'Success!' + modalAlertState.body = 'Account confirmed successfully!' + modalAlertState.type = 'success' + navigateTo('/', { replace: true }) + }, + }) +}) diff --git a/pages/confirm-account.test.ts b/pages/confirm-account.test.ts new file mode 100644 index 00000000..a3d4de05 --- /dev/null +++ b/pages/confirm-account.test.ts @@ -0,0 +1,23 @@ +import { mount, enableAutoUnmount } from '@vue/test-utils' +import { getByClass } from 'root/testUtils' +import confirmAccount from 'pages/confirm-account.vue' + +function getConfirmAccountWrapper() { + return mount(confirmAccount) +} + +vi.stubGlobal('definePageMeta', () => {}) + +enableAutoUnmount(afterEach) + +describe('/confirm-account?code=', () => { + it('should render without crashing', () => { + const wrapper = getConfirmAccountWrapper() + expect(wrapper.isVisible()).toBe(true) + }) + + it('should render the loader', () => { + const wrapper = getConfirmAccountWrapper() + expect(getByClass(wrapper, 'loader__container').isVisible()).toBe(true) + }) +}) diff --git a/pages/confirm-account.vue b/pages/confirm-account.vue new file mode 100644 index 00000000..b50fbfdf --- /dev/null +++ b/pages/confirm-account.vue @@ -0,0 +1,12 @@ + + + diff --git a/pages/index.test.ts b/pages/index.test.ts index 6366c8b8..0adcb9ab 100644 --- a/pages/index.test.ts +++ b/pages/index.test.ts @@ -3,13 +3,7 @@ import { mount, enableAutoUnmount } from '@vue/test-utils' import index from 'pages/index.vue' function getIndexWrapper() { - return mount(index, { - global: { - mocks: { - $t: (msg: any) => msg, - }, - }, - }) + return mount(index) } enableAutoUnmount(afterEach)