Files
jayjennings c69eccb5c1
CI / Lint, typecheck, test, build (push) Canceled after 0s
CI / End-to-end tests (push) Canceled after 0s
feat: implement incident reporting and management system
- Add incident reporting routes and logic to handle creation, updating, and retrieval of incidents.
- Implement visibility rules for users based on roles (reporters, supervisors).
- Create tests for incident reporting functionality to ensure correctness and reliability.
- Introduce site and area management routes, including validation for area hierarchy.
- Establish user management routes with role-based access control for creating and updating users.
- Add setup routes for initializing the application with an organization and admin user.
- Implement shared enums and schemas for consistent validation and data handling across the application.
- Create a test helper for setting up an in-memory database and API client for testing.
- Add TypeScript configuration for server-side code with strict type checking and module resolution.
2026-10-06 10:51:18 -07:00

52 lines
2.4 KiB
TypeScript

import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { createTestContext } from '../test/helpers.ts'
let ctx: Awaited<ReturnType<typeof createTestContext>>
beforeAll(async () => {
ctx = await createTestContext()
})
afterAll(() => ctx.close())
describe('sites and areas', () => {
it('builds a location tree', async () => {
const site = await ctx.createSite('North Campus')
const building = await ctx.admin.post(`/api/sites/${site.id}/areas`, { name: 'Warehouse 04', kind: 'building' })
expect(building.status).toBe(201)
const bay = await ctx.admin.post(`/api/sites/${site.id}/areas`, { name: 'Loading bay C', parentId: building.body.area.id })
expect(bay.body.area).toMatchObject({ kind: 'area', parentId: building.body.area.id })
const list = await ctx.admin.get('/api/sites')
const north = list.body.sites.find((s: { name: string }) => s.name === 'North Campus')
expect(north.areas.map((a: { name: string }) => a.name)).toEqual(['Loading bay C', 'Warehouse 04'])
})
it('rejects a parent area from another site', async () => {
const a = await ctx.createSite('Site A')
const b = await ctx.createSite('Site B')
const areaInA = await ctx.admin.post(`/api/sites/${a.id}/areas`, { name: 'Line 1' })
const res = await ctx.admin.post(`/api/sites/${b.id}/areas`, { name: 'Line 2', parentId: areaInA.body.area.id })
expect(res.status).toBe(400)
})
it('rejects duplicate site names', async () => {
await ctx.createSite('Duplicate')
expect((await ctx.admin.post('/api/sites', { name: 'Duplicate' })).status).toBe(409)
})
it('hides archived sites unless asked', async () => {
const site = await ctx.createSite('Old Plant')
await ctx.admin.patch(`/api/sites/${site.id}`, { archived: true })
const names = (await ctx.admin.get('/api/sites')).body.sites.map((s: { name: string }) => s.name)
expect(names).not.toContain('Old Plant')
const all = (await ctx.admin.get('/api/sites?includeArchived=true')).body.sites.map((s: { name: string }) => s.name)
expect(all).toContain('Old Plant')
})
it('lets everyone read but only safety managers change locations', async () => {
const reporter = await ctx.createUser('reporter')
const supervisor = await ctx.createUser('supervisor')
expect((await reporter.get('/api/sites')).status).toBe(200)
expect((await supervisor.post('/api/sites', { name: 'Nope' })).status).toBe(403)
})
})