Ajoute les pages de compte au front et le favicon de la SSMG

- Inscription, suivi de l'inscription (lien de confirmation), seconde
  étape de connexion (code à 6 chiffres ou code de secours), mot de passe
  oublié et réinitialisation, page « Mon compte » (mot de passe, 2FA avec
  QR code et codes de secours), d'après les maquettes Penpot.
- Les jetons reçus par e-mail sont retirés de l'URL dès l'arrivée.
- Favicon de la SSMG (ssmg.be) ; retour en haut de page à chaque
  navigation.
- 93 tests Vitest ; README et CLAUDE.md mis à jour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
boris.waaubandClaude Opus 5.5 committed 2026-11-24 13:27:34 +01:00
1 parent d2da878dbd
commit 0617fa8dc4
29 files changed
+2305 -58

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { defineComponent, ref } from 'vue'
import CodeInput from '@/components/CodeInput.vue'
// Parent avec v-model : reproduit l'usage réel (la valeur ne remonte qu'au rendu du parent).
function mountWithModel() {
const completed: string[] = []
const Parent = defineComponent({
components: { CodeInput },
setup: () => ({ code: ref(''), completed }),
template: '<CodeInput v-model="code" label="Code" @complete="completed.push($event)" />',
})
const wrapper = mount(Parent, { attachTo: document.body })
return { wrapper, completed }
}
function paste(input: Element, text: string) {
const event = new Event('paste', { bubbles: true, cancelable: true }) as ClipboardEvent
Object.defineProperty(event, 'clipboardData', { value: { getData: () => text } })
input.dispatchEvent(event)
}
describe('CodeInput', () => {
it('affiche six cases étiquetées', () => {
const { wrapper } = mountWithModel()
const digits = wrapper.findAll('input')
expect(digits).toHaveLength(6)
expect(digits[0]!.attributes('autocomplete')).toBe('one-time-code')
expect(digits[5]!.attributes('aria-label')).toBe('Code – chiffre 6')
wrapper.unmount()
})
it('répartit un code collé et émet complete', async () => {
const { wrapper, completed } = mountWithModel()
paste(wrapper.find('input').element, '123 456')
await wrapper.vm.$nextTick()
expect(wrapper.findAll('input').map((i) => (i.element as HTMLInputElement).value)).toEqual([
'1',
'2',
'3',
'4',
'5',
'6',
])
expect(completed).toEqual(['123456'])
wrapper.unmount()
})
it('émet complete à la saisie du dernier chiffre', async () => {
const { wrapper, completed } = mountWithModel()
const inputs = wrapper.findAll('input')
for (const [index, digit] of [...'987654'].entries()) {
await inputs[index]!.setValue(digit)
}
expect(completed).toEqual(['987654'])
wrapper.unmount()
})
it('ignore les caractères non numériques', async () => {
const { wrapper, completed } = mountWithModel()
await wrapper.find('input').setValue('a')
expect((wrapper.find('input').element as HTMLInputElement).value).toBe('')
expect(completed).toEqual([])
wrapper.unmount()
})
})
+1
View File
@@ -13,6 +13,7 @@ export const USER: User = {
last_name: 'Dupont',
roles: ['Médecin'],
is_staff: false,
mfa_enabled: false,
}
export function factor(overrides: Partial<FactorResult> = {}): FactorResult {
+245
View File
@@ -0,0 +1,245 @@
import { flushPromises } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { resetAuth, useAuth } from '@/composables/useAuth'
import MfaPanel from '@/components/MfaPanel.vue'
import AccountView from '@/views/AccountView.vue'
import LoginView from '@/views/LoginView.vue'
import { jsonResponse, makeRouter, mockFetch, mountWithPlugins, USER } from './helpers'
beforeEach(resetAuth)
afterEach(() => vi.unstubAllGlobals())
const SETUP = {
secret: 'ABCD EFGH IJKL MNOP',
otpauth_url: 'otpauth://totp/PRISM:x?secret=ABCD',
qr_code: 'data:image/svg+xml;base64,PHN2Zy8+',
}
const CODES = Array.from({ length: 8 }, (_, i) => `AAAA-000${i}`)
async function pasteCode(wrapper: ReturnType<typeof mountWithPlugins>, code: string) {
const event = new Event('paste', { bubbles: true, cancelable: true })
Object.defineProperty(event, 'clipboardData', { value: { getData: () => code } })
wrapper.find('.digit').element.dispatchEvent(event)
await flushPromises()
}
async function signIn(user = USER) {
mockFetch(jsonResponse(200, user))
await useAuth().load()
vi.unstubAllGlobals()
}
describe('LoginView – seconde étape', () => {
async function toSecondStep() {
const router = makeRouter()
const push = vi.spyOn(router, 'push').mockResolvedValue(undefined)
const wrapper = mountWithPlugins(LoginView, { router, attachTo: document.body })
await wrapper.find('#email').setValue('medecin@exemple.be')
await wrapper.find('#password').setValue('secret')
await wrapper.find('form').trigger('submit')
await flushPromises()
return { wrapper, push }
}
it('demande le code quand la 2FA est active, sans ouvrir de session', async () => {
const fetch = mockFetch(jsonResponse(200, { mfa_required: true, user: null }))
const { wrapper, push } = await toSecondStep()
expect(wrapper.find('h1').text()).toBe('Vérification en deux étapes')
expect(wrapper.findAll('.digit')).toHaveLength(6)
expect(fetch).toHaveBeenCalledTimes(1)
expect(push).not.toHaveBeenCalled()
expect(useAuth().user.value).toBeNull()
wrapper.unmount()
})
it('valide automatiquement un code complet puis redirige', async () => {
const fetch = mockFetch(
jsonResponse(200, { mfa_required: true, user: null }),
jsonResponse(200, { mfa_required: false, user: USER }),
jsonResponse(200, USER),
)
const { wrapper, push } = await toSecondStep()
await pasteCode(wrapper, '123456')
expect(fetch.mock.calls[1]![0]).toBe('/api/v1/auth/2fa/verify/')
expect(JSON.parse(fetch.mock.calls[1]![1]!.body as string)).toEqual({ code: '123456' })
expect(useAuth().user.value).toEqual(USER)
expect(push).toHaveBeenCalledWith({ name: 'assessment' })
wrapper.unmount()
})
it('code faux : message et cases vidées', async () => {
mockFetch(
jsonResponse(200, { mfa_required: true, user: null }),
jsonResponse(400, { code: 'invalid_code', detail: 'Code incorrect ou expiré.' }),
)
const { wrapper } = await toSecondStep()
await pasteCode(wrapper, '000000')
expect(wrapper.find('[role="alert"]').text()).toBe('Code incorrect ou expiré.')
expect(wrapper.findAll('.digit').map((d) => (d.element as HTMLInputElement).value)).toEqual(
Array(6).fill(''),
)
wrapper.unmount()
})
it('code de secours', async () => {
const fetch = mockFetch(
jsonResponse(200, { mfa_required: true, user: null }),
jsonResponse(200, { mfa_required: false, user: USER }),
jsonResponse(200, USER),
)
const { wrapper, push } = await toSecondStep()
await wrapper
.findAll('button')
.find((b) => b.text() === 'Utiliser un code de secours')!
.trigger('click')
await wrapper.find('#recovery').setValue('ABCD-EFGH')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[1]![1]!.body as string)).toEqual({ code: 'ABCD-EFGH' })
expect(push).toHaveBeenCalled()
wrapper.unmount()
})
it('étape expirée : retour au mot de passe', async () => {
mockFetch(
jsonResponse(200, { mfa_required: true, user: null }),
jsonResponse(400, { code: 'mfa_expired', detail: 'Recommencez la connexion.' }),
)
const { wrapper } = await toSecondStep()
await pasteCode(wrapper, '123456')
expect(wrapper.find('h1').text()).toBe('Connexion')
expect(wrapper.find('[role="alert"]').text()).toBe('Recommencez la connexion.')
wrapper.unmount()
})
})
describe('MfaPanel', () => {
it('active la 2FA : QR code, code, puis codes de secours', async () => {
await signIn()
const fetch = mockFetch(
jsonResponse(200, SETUP),
jsonResponse(200, { recovery_codes: CODES }),
jsonResponse(200, { ...USER, mfa_enabled: true }),
)
const wrapper = mountWithPlugins(MfaPanel, { attachTo: document.body })
expect(wrapper.find('.status').text()).toBe('Désactivée')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(wrapper.find('img.qr').attributes('src')).toBe(SETUP.qr_code)
expect(wrapper.text()).toContain('ABCD EFGH IJKL MNOP')
await pasteCode(wrapper, '123456')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[1]![1]!.body as string)).toEqual({ code: '123456' })
expect(wrapper.findAll('.codes li').map((li) => li.text())).toEqual(CODES)
const finish = wrapper.findAll('button').find((b) => b.text() === 'Terminer')!
expect(finish.attributes('disabled')).toBeDefined()
await wrapper.find('#codes-saved').setValue(true)
await finish.trigger('click')
await flushPromises()
expect(wrapper.find('.status').text()).toBe('Activée')
expect(wrapper.text()).toContain('La double authentification est activée.')
wrapper.unmount()
})
it('désactive avec mot de passe et code', async () => {
await signIn({ ...USER, mfa_enabled: true })
const fetch = mockFetch(jsonResponse(204), jsonResponse(200, { ...USER, mfa_enabled: false }))
const wrapper = mountWithPlugins(MfaPanel)
await wrapper
.findAll('button')
.find((b) => b.text() === 'Désactiver')!
.trigger('click')
await wrapper.find('#mfa-password').setValue('secret')
await wrapper.find('#mfa-code').setValue('AAAA-0001')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({
password: 'secret',
code: 'AAAA-0001',
})
expect(wrapper.find('.status').text()).toBe('Désactivée')
})
it('compte du personnel : 2FA obligatoire, pas de bouton Désactiver', async () => {
await signIn({ ...USER, is_staff: true, mfa_enabled: true })
const wrapper = mountWithPlugins(MfaPanel)
expect(wrapper.findAll('button').map((b) => b.text())).not.toContain('Désactiver')
})
it('signale la 2FA obligatoire à un compte du personnel qui ne l’a pas', async () => {
await signIn({ ...USER, is_staff: true })
const wrapper = mountWithPlugins(MfaPanel)
expect(wrapper.find('[role="alert"]').text()).toContain('obligatoire')
})
it('régénère les codes de secours', async () => {
await signIn({ ...USER, mfa_enabled: true })
mockFetch(jsonResponse(200, { recovery_codes: CODES }))
const wrapper = mountWithPlugins(MfaPanel)
await wrapper
.findAll('button')
.find((b) => b.text() === 'Régénérer les codes de secours')!
.trigger('click')
await wrapper.find('#mfa-code').setValue('123456')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.findAll('.codes li')).toHaveLength(8)
})
})
describe('AccountView', () => {
it('affiche le profil et change le mot de passe', async () => {
await signIn()
const fetch = mockFetch(jsonResponse(204))
const wrapper = mountWithPlugins(AccountView)
expect(wrapper.find('.avatar').text()).toBe('JD')
expect(wrapper.find('.name').text()).toBe('Dr Jean Dupont')
await wrapper.find('#current').setValue('ancien-mot-de-passe')
await wrapper.find('#next').setValue('un-nouveau-mot-de-passe')
await wrapper.find('#confirm').setValue('un-nouveau-mot-de-passe')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({
current_password: 'ancien-mot-de-passe',
new_password: 'un-nouveau-mot-de-passe',
})
expect(wrapper.text()).toContain('Mot de passe modifié')
expect((wrapper.find('#current').element as HTMLInputElement).value).toBe('')
})
it('affiche l’erreur sur le mot de passe actuel', async () => {
await signIn()
mockFetch(jsonResponse(400, { current_password: ['Mot de passe actuel incorrect.'] }))
const wrapper = mountWithPlugins(AccountView)
await wrapper.find('#current').setValue('faux')
await wrapper.find('#next').setValue('un-nouveau-mot-de-passe')
await wrapper.find('#confirm').setValue('un-nouveau-mot-de-passe')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.find('#current').classes()).toContain('is-invalid')
expect(wrapper.text()).toContain('Mot de passe actuel incorrect.')
})
})
@@ -0,0 +1,156 @@
import { flushPromises } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { resetAuth } from '@/composables/useAuth'
import ForgotPasswordView from '@/views/ForgotPasswordView.vue'
import LoginView from '@/views/LoginView.vue'
import ResetPasswordView from '@/views/ResetPasswordView.vue'
import { jsonResponse, makeRouter, mockFetch, mountWithPlugins } from './helpers'
beforeEach(resetAuth)
afterEach(() => {
vi.unstubAllGlobals()
history.replaceState(null, '')
})
const NEW_PASSWORD = 'un-tout-nouveau-mot-de-passe'
describe('ForgotPasswordView', () => {
it('envoie la demande puis affiche « Vérifiez votre boîte mail »', async () => {
const fetch = mockFetch(jsonResponse(202), jsonResponse(202))
const wrapper = mountWithPlugins(ForgotPasswordView)
await wrapper.find('#email').setValue('medecin@exemple.be')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(fetch.mock.calls[0]![0]).toBe('/api/v1/auth/password-reset/')
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({
email: 'medecin@exemple.be',
})
expect(wrapper.find('h1').text()).toBe('Vérifiez votre boîte mail')
expect(wrapper.text()).toContain('Si un compte existe pour medecin@exemple.be')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(fetch).toHaveBeenCalledTimes(2)
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
})
it('signale la limitation de débit', async () => {
mockFetch(jsonResponse(429, { detail: 'Throttled' }))
const wrapper = mountWithPlugins(ForgotPasswordView)
await wrapper.find('#email').setValue('medecin@exemple.be')
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.find('[role="alert"]').text()).toContain('Trop de demandes')
})
})
describe('ResetPasswordView', () => {
async function mountWithToken(token: string | null, ...responses: Response[]) {
const fetch = mockFetch(...responses)
const router = makeRouter()
await router.push(token ? `/reinitialisation/${token}` : '/reinitialisation')
const push = vi.spyOn(router, 'push')
const wrapper = mountWithPlugins(ResetPasswordView, { router })
await flushPromises()
return { wrapper, router, fetch, push }
}
it('vérifie le lien, retire le jeton de l’URL et affiche le formulaire', async () => {
const { wrapper, router, fetch } = await mountWithToken('Mw.abc-123', jsonResponse(204))
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({ token: 'Mw.abc-123' })
expect(router.currentRoute.value.fullPath).toBe('/reinitialisation')
expect(wrapper.find('h1').text()).toBe('Nouveau mot de passe')
})
it('lien invalide ou expiré : propose un nouveau lien', async () => {
const { wrapper } = await mountWithToken(
'vieux',
jsonResponse(400, { code: 'invalid_token', detail: '' }),
)
expect(wrapper.find('h1').text()).toBe('Lien invalide ou expiré')
expect(wrapper.find('a.btn').attributes('href')).toBe('/mot-de-passe-oublie')
})
it('sans jeton : lien invalide, sans appel à l’API', async () => {
const { wrapper, fetch } = await mountWithToken(null)
expect(wrapper.find('h1').text()).toBe('Lien invalide ou expiré')
expect(fetch).not.toHaveBeenCalled()
})
it('enregistre le mot de passe puis renvoie à la connexion avec un message', async () => {
const { wrapper, fetch, push } = await mountWithToken(
'Mw.abc-123',
jsonResponse(204),
jsonResponse(204),
)
push.mockResolvedValue(undefined)
await wrapper.find('#password').setValue(NEW_PASSWORD)
await wrapper.find('#confirm').setValue(NEW_PASSWORD)
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(fetch.mock.calls[1]![0]).toBe('/api/v1/auth/password-reset/confirm/')
expect(JSON.parse(fetch.mock.calls[1]![1]!.body as string)).toEqual({
token: 'Mw.abc-123',
new_password: NEW_PASSWORD,
})
expect(push).toHaveBeenCalledWith({ name: 'login', state: { notice: 'password-reset' } })
})
it('bloque l’envoi si les mots de passe diffèrent ou sont trop courts', async () => {
const { wrapper } = await mountWithToken('Mw.abc-123', jsonResponse(204))
const button = () => wrapper.find('button[type="submit"]')
await wrapper.find('#password').setValue(NEW_PASSWORD)
await wrapper.find('#confirm').setValue('autre-mot-de-passe-long')
expect(button().attributes('disabled')).toBeDefined()
expect(wrapper.find('#confirm').classes()).toContain('is-invalid')
await wrapper.find('#password').setValue('court')
await wrapper.find('#confirm').setValue('court')
expect(button().attributes('disabled')).toBeDefined()
})
it('affiche le refus du mot de passe par le serveur', async () => {
const { wrapper } = await mountWithToken(
'Mw.abc-123',
jsonResponse(204),
jsonResponse(400, { new_password: ['Ce mot de passe est trop courant.'] }),
)
await wrapper.find('#password').setValue(NEW_PASSWORD)
await wrapper.find('#confirm').setValue(NEW_PASSWORD)
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.find('#password').classes()).toContain('is-invalid')
expect(wrapper.text()).toContain('Ce mot de passe est trop courant.')
})
it('lien devenu invalide entre-temps : écran « Lien invalide »', async () => {
const { wrapper } = await mountWithToken(
'Mw.abc-123',
jsonResponse(204),
jsonResponse(400, { code: 'invalid_token', detail: '' }),
)
await wrapper.find('#password').setValue(NEW_PASSWORD)
await wrapper.find('#confirm').setValue(NEW_PASSWORD)
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.find('h1').text()).toBe('Lien invalide ou expiré')
})
})
describe('LoginView', () => {
it('propose le lien « Mot de passe oublié ? »', () => {
const wrapper = mountWithPlugins(LoginView)
const link = wrapper.findAll('a').find((a) => a.text() === 'Mot de passe oublié ?')
expect(link?.attributes('href')).toBe('/mot-de-passe-oublie')
})
it('affiche la confirmation après réinitialisation', () => {
history.replaceState({ notice: 'password-reset' }, '')
const wrapper = mountWithPlugins(LoginView)
expect(wrapper.find('[role="status"]').text()).toContain('Votre mot de passe a été modifié')
})
})
+151
View File
@@ -0,0 +1,151 @@
import { flushPromises } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { resetAuth } from '@/composables/useAuth'
import RegisterStatusView from '@/views/RegisterStatusView.vue'
import RegisterView from '@/views/RegisterView.vue'
import { jsonResponse, makeRouter, mockFetch, mountWithPlugins } from './helpers'
beforeEach(resetAuth)
afterEach(() => {
vi.unstubAllGlobals()
history.replaceState(null, '')
})
const PASSWORD = 'un-mot-de-passe-solide'
async function fill(wrapper: ReturnType<typeof mountWithPlugins>, overrides = {}) {
const values = {
'#first_name': 'Marie',
'#last_name': 'Curie',
'#email': 'marie@exemple.be',
'#inami': '',
'#password': PASSWORD,
'#confirm': PASSWORD,
...overrides,
}
for (const [selector, value] of Object.entries(values)) {
await wrapper.find(selector).setValue(value)
}
await wrapper.find('#terms').setValue(true)
}
describe('RegisterView', () => {
it('envoie la demande puis affiche « Vérifiez votre boîte mail » sans e-mail dans l’URL', async () => {
const fetch = mockFetch(jsonResponse(201))
const router = makeRouter()
const push = vi.spyOn(router, 'push').mockResolvedValue(undefined)
const wrapper = mountWithPlugins(RegisterView, { router })
await fill(wrapper)
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({
first_name: 'Marie',
last_name: 'Curie',
email: 'marie@exemple.be',
inami_number: '',
password: PASSWORD,
accept_terms: true,
})
expect(push).toHaveBeenCalledWith({
name: 'register-status',
state: { email: 'marie@exemple.be' },
})
})
it('bloque l’envoi si les mots de passe diffèrent, sont trop courts ou sans conditions', async () => {
const wrapper = mountWithPlugins(RegisterView)
const button = () => wrapper.find('button[type="submit"]')
await fill(wrapper, { '#confirm': 'autre-mot-de-passe' })
expect(button().attributes('disabled')).toBeDefined()
expect(wrapper.find('#confirm').classes()).toContain('is-invalid')
await fill(wrapper, { '#password': 'court', '#confirm': 'court' })
expect(button().attributes('disabled')).toBeDefined()
await fill(wrapper)
expect(button().attributes('disabled')).toBeUndefined()
await wrapper.find('#terms').setValue(false)
expect(button().attributes('disabled')).toBeDefined()
})
it('affiche les erreurs de validation du serveur sous chaque champ', async () => {
mockFetch(
jsonResponse(400, {
password: ['Ce mot de passe est trop courant.'],
email: ['Saisissez une adresse e-mail valide.'],
}),
)
const wrapper = mountWithPlugins(RegisterView)
await fill(wrapper)
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(wrapper.find('[role="alert"]').text()).toBe('Corrigez les champs signalés.')
expect(wrapper.find('#password').classes()).toContain('is-invalid')
expect(wrapper.text()).toContain('Ce mot de passe est trop courant.')
expect(wrapper.text()).toContain('Saisissez une adresse e-mail valide.')
})
})
describe('RegisterStatusView', () => {
async function mountAt(path: string, state?: Record<string, unknown>) {
const router = makeRouter()
await router.push(router.resolve(path)).catch(() => {})
if (state) history.replaceState(state, '')
const wrapper = mountWithPlugins(RegisterStatusView, { router })
await flushPromises()
return { wrapper, router }
}
it('après inscription : « Vérifiez votre boîte mail » et renvoi par e-mail', async () => {
const fetch = mockFetch(jsonResponse(202))
const { wrapper } = await mountAt('/inscription/statut', { email: 'marie@exemple.be' })
expect(wrapper.find('h1').text()).toBe('Vérifiez votre boîte mail')
expect(wrapper.text()).toContain('marie@exemple.be')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({
email: 'marie@exemple.be',
})
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
expect(wrapper.text()).toContain('un nouvel e-mail vient d’être envoyé'.replace('’', "'"))
})
it('lien valide : adresse confirmée et jeton retiré de l’URL', async () => {
const fetch = mockFetch(jsonResponse(200, { status: 'approval_pending' }))
const { wrapper, router } = await mountAt('/inscription/statut?jeton=abc')
expect(JSON.parse(fetch.mock.calls[0]![1]!.body as string)).toEqual({ token: 'abc' })
expect(wrapper.find('h1').text()).toBe('Adresse confirmée')
expect(router.currentRoute.value.fullPath).toBe('/inscription/statut')
})
it('lien expiré : renvoi à partir du jeton', async () => {
const fetch = mockFetch(
jsonResponse(400, { code: 'expired_token', detail: 'Ce lien a expiré.' }),
jsonResponse(202),
)
const { wrapper } = await mountAt('/inscription/statut?jeton=vieux')
expect(wrapper.find('h1').text()).toBe('Lien expiré')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(JSON.parse(fetch.mock.calls[1]![1]!.body as string)).toEqual({ token: 'vieux' })
})
it.each([
['invalid_token', 'Lien invalide'],
['used_token', 'Adresse confirmée'],
])('%s → « %s »', async (code, title) => {
mockFetch(jsonResponse(400, { code, detail: '' }))
const { wrapper } = await mountAt('/inscription/statut?jeton=x')
expect(wrapper.find('h1').text()).toBe(title)
})
})
+26
View File
@@ -36,6 +36,32 @@ describe('garde de navigation', () => {
expect(route.name).toBe('not-found')
})
it('protège /compte et laisse /inscription aux visiteurs', async () => {
mockFetch(jsonResponse(403, {}))
expect((await navigate('/compte')).name).toBe('login')
resetAuth()
mockFetch(jsonResponse(403, {}))
expect((await navigate('/inscription')).name).toBe('register')
})
it('renvoie un utilisateur connecté de /inscription vers l’évaluation', async () => {
mockFetch(jsonResponse(200, USER))
expect((await navigate('/inscription')).name).toBe('assessment')
})
it('laisse /inscription/statut ouverte à tous (lien reçu par e-mail)', async () => {
mockFetch(jsonResponse(200, USER))
expect((await navigate('/inscription/statut')).name).toBe('register-status')
})
it('mot de passe oublié réservé aux visiteurs, lien de réinitialisation ouvert à tous', async () => {
mockFetch(jsonResponse(200, USER))
expect((await navigate('/mot-de-passe-oublie')).name).toBe('assessment')
resetAuth()
mockFetch(jsonResponse(200, USER))
expect((await navigate('/reinitialisation/abc')).name).toBe('reset-password')
})
it('laisse la page 403 publique', async () => {
mockFetch(jsonResponse(403, {}))
expect((await navigate('/403')).name).toBe('forbidden')