Replace the header "Byt lösenord" link with an Inställningar menu for changing email or password. Email changes are two-step: request with password, confirmation link to the new address, then password again on confirm so a wrong inbox cannot take over the account. - Backend: EmailChangeService, V10 email_change_tokens, confirm API - Frontend: ChangeEmailPage, ConfirmEmailChangePage, header dropdown - E2E: account-settings round-trips, Mailpit verification, wrong-password guard - Flyway: V9 restore for dev DBs, CI migration checks, V10 for email tokens Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { mount, flushPromises } from '@vue/test-utils'
|
|
import { createRouter, createMemoryHistory } from 'vue-router'
|
|
import { setActivePinia, createPinia } from 'pinia'
|
|
import ConfirmEmailChangePage from '@/pages/ConfirmEmailChangePage.vue'
|
|
|
|
function createTestRouter() {
|
|
return createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{
|
|
path: '/bekrafta-epost',
|
|
name: 'confirm-email-change',
|
|
component: ConfirmEmailChangePage,
|
|
},
|
|
],
|
|
})
|
|
}
|
|
|
|
async function mountPage(initialPath: string) {
|
|
const pinia = createPinia()
|
|
setActivePinia(pinia)
|
|
const router = createTestRouter()
|
|
await router.push(initialPath)
|
|
await router.isReady()
|
|
const wrapper = mount(ConfirmEmailChangePage, {
|
|
global: { plugins: [router, pinia] },
|
|
})
|
|
await flushPromises()
|
|
return { wrapper, router }
|
|
}
|
|
|
|
describe('ConfirmEmailChangePage', () => {
|
|
it('shows password form when token is present', async () => {
|
|
const { wrapper } = await mountPage('/bekrafta-epost?token=test-token')
|
|
|
|
expect(wrapper.text()).toContain('Bekräfta e-postadress')
|
|
expect(wrapper.text()).toContain('Ange ditt lösenord')
|
|
expect(wrapper.find('#password').exists()).toBe(true)
|
|
expect(wrapper.find('button[type="submit"]').text()).toBe(
|
|
'Bekräfta ny e-postadress',
|
|
)
|
|
})
|
|
|
|
it('shows error when token is missing', async () => {
|
|
const { wrapper } = await mountPage('/bekrafta-epost')
|
|
|
|
expect(wrapper.text()).toContain('Bekräftelselänken saknar en giltig kod.')
|
|
})
|
|
})
|