From 48c2a50c5def85a08d8169ed51f72ce2a1a3b869 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 22 Jun 2026 12:08:43 +0000 Subject: [PATCH] fix(guest): route homepage CTA to guest checkout when unauthenticated Guest checkout was unreachable: the homepage CTA "Fortsatt till brevet" always linked to /compose (requiresAuth), so anonymous users hit the router guard and got redirected to /logga-in instead of reaching the guest checkout flow. Changes: - HomePage.vue: compute CTA target based on auth state. Authenticated users still go to /compose; unauthenticated users go to /gast-bestallning with the plate as a query param. - GuestCheckoutPage.vue: accept plate from route.query.plate so the user does not have to re-enter it after looking it up on the homepage. - HomePage.spec.ts: add Pinia setup + guest-checkout route; update CTA assertion to expect /gast-bestallning?plate=... when unauthenticated. All 318 frontend tests pass, vue-tsc clean (exit 0). --- frontend/src/__tests__/HomePage.spec.ts | 19 ++++++++++++++++--- frontend/src/pages/GuestCheckoutPage.vue | 5 +++-- frontend/src/pages/HomePage.vue | 17 +++++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/frontend/src/__tests__/HomePage.spec.ts b/frontend/src/__tests__/HomePage.spec.ts index 4ba77df..0664b4d 100644 --- a/frontend/src/__tests__/HomePage.spec.ts +++ b/frontend/src/__tests__/HomePage.spec.ts @@ -1,8 +1,10 @@ -import { describe, it, expect, vi } from 'vitest' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { mount } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' import { createRouter, createMemoryHistory } from 'vue-router' import HomePage from '@/pages/HomePage.vue' import ComposePage from '@/pages/ComposePage.vue' +import GuestCheckoutPage from '@/pages/GuestCheckoutPage.vue' vi.mock('@/api/vehicles', () => ({ lookupVehicle: vi.fn(), @@ -17,6 +19,11 @@ function createTestRouter() { routes: [ { path: '/', name: 'home', component: HomePage }, { path: '/compose', name: 'compose', component: ComposePage }, + { + path: '/gast-bestallning', + name: 'guest-checkout', + component: GuestCheckoutPage, + }, ], }) } @@ -28,6 +35,12 @@ function mountHome(router: ReturnType) { } describe('HomePage', () => { + beforeEach(() => { + setActivePinia(createPinia()) + localStorage.removeItem('auth_token') + vi.clearAllMocks() + }) + it('renders headline', () => { const router = createTestRouter() const wrapper = mountHome(router) @@ -88,7 +101,7 @@ describe('HomePage', () => { expect(cta.text()).toBe('Fortsätt till brevet') }) - it('CTA links to compose page with plate query param', async () => { + it('CTA links to guest checkout with plate query param when unauthenticated', async () => { mockLookupVehicle.mockResolvedValue({ make: 'Volvo', model: 'V70', @@ -107,6 +120,6 @@ describe('HomePage', () => { const cta = wrapper.find('.btn--primary') const href = cta.attributes('href') - expect(href).toBe('/compose?plate=ABC123') + expect(href).toBe('/gast-bestallning?plate=ABC123') }) }) diff --git a/frontend/src/pages/GuestCheckoutPage.vue b/frontend/src/pages/GuestCheckoutPage.vue index 8a625fa..2f98efa 100644 --- a/frontend/src/pages/GuestCheckoutPage.vue +++ b/frontend/src/pages/GuestCheckoutPage.vue @@ -1,11 +1,12 @@