Files
ims/tests/middleware-matcher.test.ts
adminandClaude Haiku 4.5 bbe038e3aa fix(middleware): exempt manifest.json and sw.js from the auth matcher
Logged-out requests were redirected to /login, and logged-in non-admin roles
were bounced to their home page, which blocked PWA install and the service
worker.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-01 08:13:59 +08:00

21 lines
600 B
TypeScript

import { describe, it, expect } from 'vitest'
import { config } from '@/middleware'
const re = new RegExp(`^${config.matcher[0]}$`)
describe('middleware matcher', () => {
it.each(['/manifest.json', '/sw.js', '/_next/static/chunks/a.js', '/favicon.ico', '/icons/icon-192.png'])(
'skips public asset %s so PWA files load without a session',
path => {
expect(re.test(path)).toBe(false)
},
)
it.each(['/', '/login', '/hse/incidents', '/api/incidents', '/manifest.jsonx', '/app/sw.js'])(
'still guards %s',
path => {
expect(re.test(path)).toBe(true)
},
)
})