Skip to content

Commit

Permalink
Create /confirm-account route
Browse files Browse the repository at this point in the history
  • Loading branch information
erunks committed Nov 23, 2023
1 parent e4ae475 commit 62a88b7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
29 changes: 29 additions & 0 deletions middleware/confirm-account.ts
Original file line number Diff line number Diff line change
@@ -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 })
},
})
})
23 changes: 23 additions & 0 deletions pages/confirm-account.test.ts
Original file line number Diff line number Diff line change
@@ -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=<CONFIRMATION_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)
})
})
12 changes: 12 additions & 0 deletions pages/confirm-account.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script setup lang="ts">
import Loader from 'blocks/Loader/Loader.vue'
definePageMeta({
layout: false,
middleware: 'confirm-account',
})
</script>

<template>
<Loader />
</template>
8 changes: 1 addition & 7 deletions pages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 62a88b7

Please sign in to comment.