From ab475f1a92ff70f70959476a5af6f18d5b7d285e Mon Sep 17 00:00:00 2001 From: Edward Runkel Date: Tue, 28 Nov 2023 22:46:55 -0500 Subject: [PATCH] LBGG-564: Account confirmation (#580) * Update version requirements in `package` * Update API library * Create `useConfirmAccount` composable * Create `BasicAlert` component, and add it to the default layout * Create `Loader` component * Create `/confirm-account` route * Fix rendering error messages on signup * Actually fix rendering errors on signup failure * Fix confrimation aborting, when no code or from path mismatch * Switch composable definitions to use function declarations over function expressions * Pin the latest `pnpm` version --- assets/sprite/svg/circle-check.svg | 1 + assets/sprite/svg/circle-exclamation.svg | 1 + assets/sprite/svg/circle-info.svg | 1 + assets/sprite/svg/spinner.svg | 1 + assets/sprite/svg/triangle-exclamation.svg | 1 + components.d.ts | 5 + components/blocks/Loader/Loader.vue | 31 ++++++ .../cards/BasicAlert/BasicAlert.test.ts | 60 +++++++++++ .../blocks/cards/BasicAlert/BasicAlert.vue | 99 +++++++++++++++++ .../blocks/cards/SignUpCard/SignUpCard.vue | 11 +- composables/api/index.ts | 1 + composables/api/useConfirmAccount/index.ts | 20 ++++ .../useConfirmAccount.test.ts | 24 +++++ .../api/useGetLeaderboardDetail/index.ts | 4 +- composables/api/useGetUserDetail/index.ts | 4 +- composables/api/useLoginUser/index.ts | 4 +- composables/api/useLogoutUser/index.ts | 2 +- composables/api/useRegisterUser/index.ts | 4 +- composables/useApi/index.ts | 4 +- composables/useCurrentUser.ts | 5 +- composables/useModalAlert.ts | 17 +++ composables/useSessionToken.ts | 4 +- layouts/default.vue | 2 + lib/api/Account.ts | 92 ++++++++++++++++ lib/api/AccountRoute.ts | 102 ++++++++++++++++++ lib/api/data-contracts.ts | 18 ++++ lib/helpers.ts | 18 ++++ middleware/confirm-account.ts | 32 ++++++ package.json | 6 +- pages/confirm-account.test.ts | 23 ++++ pages/confirm-account.vue | 12 +++ pages/index.test.ts | 8 +- testUtils.ts | 7 ++ 33 files changed, 594 insertions(+), 30 deletions(-) create mode 100644 assets/sprite/svg/circle-check.svg create mode 100644 assets/sprite/svg/circle-exclamation.svg create mode 100644 assets/sprite/svg/circle-info.svg create mode 100644 assets/sprite/svg/spinner.svg create mode 100644 assets/sprite/svg/triangle-exclamation.svg create mode 100644 components/blocks/Loader/Loader.vue create mode 100644 components/blocks/cards/BasicAlert/BasicAlert.test.ts create mode 100644 components/blocks/cards/BasicAlert/BasicAlert.vue create mode 100644 composables/api/useConfirmAccount/index.ts create mode 100644 composables/api/useConfirmAccount/useConfirmAccount.test.ts create mode 100644 composables/useModalAlert.ts create mode 100644 middleware/confirm-account.ts create mode 100644 pages/confirm-account.test.ts create mode 100644 pages/confirm-account.vue diff --git a/assets/sprite/svg/circle-check.svg b/assets/sprite/svg/circle-check.svg new file mode 100644 index 00000000..9ba4259b --- /dev/null +++ b/assets/sprite/svg/circle-check.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/sprite/svg/circle-exclamation.svg b/assets/sprite/svg/circle-exclamation.svg new file mode 100644 index 00000000..81b3768a --- /dev/null +++ b/assets/sprite/svg/circle-exclamation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/sprite/svg/circle-info.svg b/assets/sprite/svg/circle-info.svg new file mode 100644 index 00000000..652acbee --- /dev/null +++ b/assets/sprite/svg/circle-info.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/sprite/svg/spinner.svg b/assets/sprite/svg/spinner.svg new file mode 100644 index 00000000..cc611eb4 --- /dev/null +++ b/assets/sprite/svg/spinner.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/sprite/svg/triangle-exclamation.svg b/assets/sprite/svg/triangle-exclamation.svg new file mode 100644 index 00000000..0a695fd2 --- /dev/null +++ b/assets/sprite/svg/triangle-exclamation.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/components.d.ts b/components.d.ts index f4d661fe..0c95ff40 100644 --- a/components.d.ts +++ b/components.d.ts @@ -7,12 +7,17 @@ export {} declare module 'vue' { export interface GlobalComponents { + ISvgCircleCheck: typeof import('~icons/svg/circle-check')['default'] + ISvgCircleExclamation: typeof import('~icons/svg/circle-exclamation')['default'] + ISvgCircleInfo: typeof import('~icons/svg/circle-info')['default'] ISvgClock: typeof import('~icons/svg/clock')['default'] ISvgClose: typeof import('~icons/svg/close')['default'] ISvgEyeHidden: typeof import('~icons/svg/eye-hidden')['default'] ISvgEyeVisible: typeof import('~icons/svg/eye-visible')['default'] ISvgMenu: typeof import('~icons/svg/menu')['default'] ISvgSearch: typeof import('~icons/svg/search')['default'] + ISvgSpinner: typeof import('~icons/svg/spinner')['default'] + ISvgTriangleExclamation: typeof import('~icons/svg/triangle-exclamation')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] } diff --git a/components/blocks/Loader/Loader.vue b/components/blocks/Loader/Loader.vue new file mode 100644 index 00000000..262f7674 --- /dev/null +++ b/components/blocks/Loader/Loader.vue @@ -0,0 +1,31 @@ + + + + + diff --git a/components/blocks/cards/BasicAlert/BasicAlert.test.ts b/components/blocks/cards/BasicAlert/BasicAlert.test.ts new file mode 100644 index 00000000..ad18ac93 --- /dev/null +++ b/components/blocks/cards/BasicAlert/BasicAlert.test.ts @@ -0,0 +1,60 @@ +import { mount, enableAutoUnmount } from '@vue/test-utils' +import { useModalAlert } from 'composables/useModalAlert' +import { getByClass, getByTestId, getHTMLElement } from 'root/testUtils' +import BasicAlert from './BasicAlert.vue' + +function getBasicAlertWrapper() { + return mount(BasicAlert) +} + +beforeEach(() => { + const modalAlertState = useModalAlert() + modalAlertState.value = { + body: 'This is a test', + show: true, + title: 'A test alert?', + type: 'info', + } +}) + +enableAutoUnmount(afterEach) + +afterEach(() => { + fetchMock.resetMocks() + vi.restoreAllMocks() +}) + +describe('', () => { + it('should render without crashing', () => { + const wrapper = getBasicAlertWrapper() + + expect(wrapper.isVisible()).toBe(true) + }) + + it('renders with the correct information', () => { + const wrapper = getBasicAlertWrapper() + + expect( + getHTMLElement(getByClass(wrapper, 'basic-modal-alert__header')) + .childElementCount, + ).toEqual(3) + expect(getByClass(wrapper, 'basic-modal-alert__title').text()).toEqual( + 'A test alert?', + ) + expect(getByClass(wrapper, 'basic-modal-alert__body').text()).toEqual( + 'This is a test', + ) + }) + + describe('when the close button is clicked', () => { + it('should emit the close event', async () => { + const wrapper = getBasicAlertWrapper() + + await getByTestId(wrapper, 'basic-modal-alert-close-button').trigger( + 'click', + ) + + expect(wrapper.isVisible()).toBe(false) + }) + }) +}) diff --git a/components/blocks/cards/BasicAlert/BasicAlert.vue b/components/blocks/cards/BasicAlert/BasicAlert.vue new file mode 100644 index 00000000..73763d23 --- /dev/null +++ b/components/blocks/cards/BasicAlert/BasicAlert.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/components/blocks/cards/SignUpCard/SignUpCard.vue b/components/blocks/cards/SignUpCard/SignUpCard.vue index 508224f2..17de6c8c 100644 --- a/components/blocks/cards/SignUpCard/SignUpCard.vue +++ b/components/blocks/cards/SignUpCard/SignUpCard.vue @@ -1,5 +1,6 @@