Merge pull request 'Fix order cancellation by allowing cancelled in the database status constraint.' (#2) from feature/cancel-edit-pending-orders into master
All checks were successful
CI / Lint, type check, unit tests, coverage (push) Successful in 2m13s
CI / E2E browser tests (push) Successful in 53s

Reviewed-on: https://srvr.nu/git/git/jocke/bilhej/pulls/2
This commit is contained in:
jocke 2026-05-22 09:54:07 +00:00
commit aa2b4b4a16
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,14 @@
ALTER TABLE orders DROP CONSTRAINT ck_orders_status;
ALTER TABLE orders
ADD CONSTRAINT ck_orders_status CHECK (
status IN (
'pending_payment',
'paid',
'processing',
'sent',
'delivered',
'failed',
'cancelled'
)
);

View file

@ -91,4 +91,38 @@ test.describe('Order history', () => {
const trackingLink2 = page.getByRole('link', { name: 'PN987654321' }) const trackingLink2 = page.getByRole('link', { name: 'PN987654321' })
await expect(trackingLink2).toBeVisible() await expect(trackingLink2).toBeVisible()
}) })
test('can cancel pending order', async ({ page }) => {
const plate = 'CAN999'
await page.goto('/logga-in')
await page.getByLabel('E-postadress').fill('test@bilhej.se')
await page.getByLabel('Lösenord').fill('test1234')
await page.getByRole('button', { name: 'Logga in' }).click()
await page.waitForURL('/')
await page.goto(`/compose?plate=${plate}`)
await page.getByLabel('Ditt meddelande').fill('E2E-test: ska kunna avbrytas.')
await page.getByRole('button', { name: 'Fortsätt till betalning' }).click()
await expect(page).toHaveURL(/\/betalning\//)
await page.goto('/orders')
const pendingCard = page.locator('.orders__card', { hasText: plate })
await expect(pendingCard.getByText('Väntar på betalning')).toBeVisible()
await expect(
pendingCard.getByRole('link', { name: 'Betala 49 kr' }),
).toBeVisible()
page.once('dialog', (dialog) => dialog.accept())
await pendingCard.getByRole('button', { name: 'Avbryt beställning' }).click()
await expect(pendingCard.getByText('Avbruten')).toBeVisible()
await expect(
pendingCard.getByRole('link', { name: 'Betala 49 kr' }),
).not.toBeVisible()
await expect(
pendingCard.getByRole('button', { name: 'Avbryt beställning' }),
).not.toBeVisible()
})
}) })