feat(auth): merge reporter, supervisor, capa_owner into ssa role
Add Site Safety Assistant (ssa) role replacing reporter, supervisor and capa_owner. Portals move under /ssa (overview, my-reports, incidents, capas). Update RLS, schema, API role checks, notification recipients, nav and tests. Add db/ops/2026-11-06-merge-roles-into-ssa.sql (not yet applied; needs owner go-ahead and a pg_dump first). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
701fefd286
commit
813395700f
@@ -2,7 +2,7 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
vi.mock('@/lib/auth/get-session', () => ({
|
||||
getSession: async () => ({ sub: 'owner-1', role: 'capa_owner' }),
|
||||
getSession: async () => ({ sub: 'owner-1', role: 'ssa' }),
|
||||
}))
|
||||
vi.mock('@/lib/db/audit', () => ({ writeAuditLog: vi.fn() }))
|
||||
vi.mock('@/lib/db/with-user', () => ({
|
||||
|
||||
@@ -38,7 +38,7 @@ function req(note: string | null, fileCount: number) {
|
||||
const ctx = { params: Promise.resolve({ id: 'capa-1' }) }
|
||||
|
||||
beforeEach(() => {
|
||||
h.session = { sub: 'owner-1', role: 'capa_owner' }
|
||||
h.session = { sub: 'owner-1', role: 'ssa' }
|
||||
h.capa = { incidentId: 'inc-1', ownerUserId: 'owner-1', status: 'in_progress' }
|
||||
h.updates = []
|
||||
h.inserts = []
|
||||
@@ -56,7 +56,7 @@ describe('POST /api/capa/[id]/submit', () => {
|
||||
expect((await POST(req('done', 1) as never, ctx)).status).toBe(404)
|
||||
})
|
||||
it('403 for a user who is neither owner nor hse/admin', async () => {
|
||||
h.session = { sub: 'other', role: 'reporter' }
|
||||
h.session = { sub: 'other', role: 'ssa' }
|
||||
expect((await POST(req('done', 1) as never, ctx)).status).toBe(403)
|
||||
})
|
||||
it('409 when status is not in_progress', async () => {
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('GET /api/incidents/[id]/report-pdf', () => {
|
||||
})
|
||||
|
||||
it('returns 403 for non-hse/admin roles', async () => {
|
||||
vi.mocked(getSession).mockResolvedValue({ ...mockSession, role: 'reporter' as never })
|
||||
vi.mocked(getSession).mockResolvedValue({ ...mockSession, role: 'ssa' as never })
|
||||
const res = await GET(makeRequest('inc-1'), { params: Promise.resolve({ id: 'inc-1' }) })
|
||||
expect(res.status).toBe(403)
|
||||
})
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('AppShell', () => {
|
||||
})
|
||||
|
||||
it('hides the search box for roles without an incident list', () => {
|
||||
const { container } = render(<AppShell role="reporter" userName="Ada"><span /></AppShell>)
|
||||
const { container } = render(<AppShell role="ssa" userName="Ada"><span /></AppShell>)
|
||||
expect(container.querySelector('header form')).toBeNull()
|
||||
})
|
||||
|
||||
|
||||
@@ -2,23 +2,21 @@ import { describe, it, expect } from 'vitest'
|
||||
import { navItemsFor, isActivePath, searchHrefFor } from '@/components/layout/nav-items'
|
||||
|
||||
describe('nav items', () => {
|
||||
it('returns the role menu and falls back to reporter', () => {
|
||||
it('returns the role menu and falls back to ssa', () => {
|
||||
expect(navItemsFor('hse').map(i => i.label)).toEqual(['Dashboard', 'Incidents', 'CAPA', 'Settings'])
|
||||
expect(navItemsFor('admin')[0].label).toBe('Admin')
|
||||
expect(navItemsFor('nobody')).toEqual(navItemsFor('reporter'))
|
||||
expect(navItemsFor('nobody')).toEqual(navItemsFor('ssa'))
|
||||
})
|
||||
|
||||
it('matches root pages exactly and nested pages by prefix', () => {
|
||||
expect(isActivePath('/reporter', '/reporter')).toBe(true)
|
||||
expect(isActivePath('/reporter', '/reporter/incidents/1')).toBe(false)
|
||||
expect(isActivePath('/ssa', '/ssa')).toBe(true)
|
||||
expect(isActivePath('/ssa', '/ssa/incidents/1')).toBe(false)
|
||||
expect(isActivePath('/hse/incidents', '/hse/incidents/abc')).toBe(true)
|
||||
})
|
||||
|
||||
it('offers the search box only to roles that have an incident list', () => {
|
||||
expect(searchHrefFor('hse')).toBe('/hse/incidents')
|
||||
expect(searchHrefFor('admin')).toBe('/hse/incidents')
|
||||
expect(searchHrefFor('supervisor')).toBe('/supervisor/incidents')
|
||||
expect(searchHrefFor('reporter')).toBeNull()
|
||||
expect(searchHrefFor('capa_owner')).toBeNull()
|
||||
expect(searchHrefFor('ssa')).toBe('/ssa/incidents')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ vi.mock('resend', () => {
|
||||
// Mock asAdmin: first call returns recipients, second returns incident+join rows
|
||||
let asAdminCallCount = 0
|
||||
const mockRecipients = [
|
||||
{ email: 'supervisor@setiacorp.com' },
|
||||
{ email: 'ssa@setiacorp.com' },
|
||||
{ email: 'hse@setiacorp.com' },
|
||||
]
|
||||
const mockIncidentRows = [{
|
||||
@@ -44,11 +44,11 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('sendNewIncidentEmail', () => {
|
||||
it('sends email to supervisor and hse users', async () => {
|
||||
it('sends email to ssa and hse users', async () => {
|
||||
await sendNewIncidentEmail('inc-001', 'site-001', 'SCW1-202607-0001', 'near_miss')
|
||||
expect(mockSend).toHaveBeenCalledTimes(1)
|
||||
const call = mockSend.mock.calls[0][0]
|
||||
expect(call.to).toEqual(expect.arrayContaining(['supervisor@setiacorp.com', 'hse@setiacorp.com']))
|
||||
expect(call.to).toEqual(expect.arrayContaining(['ssa@setiacorp.com', 'hse@setiacorp.com']))
|
||||
expect(call.subject).toContain('SCW1-202607-0001')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user