Files
chore/frontend/src/common/__tests__/api.routine.spec.ts
Ryan Kegel eb775ba7d8
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m0s
feat: Implement routines feature with CRUD operations and child assignment
- Add backend routines management with add, get, update, delete, and list functionalities.
- Create models for Routine, RoutineItem, RoutineSchedule, and RoutineExtension.
- Develop event types for routine confirmation and modification.
- Implement frontend components for routine assignment, confirmation dialog, and routine management views.
- Add unit tests for routine API and integration tests for routine CRUD flow.
- Create end-to-end test plan for routines feature covering parent and child interactions.
2026-05-05 09:08:19 -04:00

61 lines
2.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import {
confirmRoutine,
cancelRoutineConfirmation,
setChildRoutineOverride,
setChildOverride,
} from '../api'
describe('routine api helpers', () => {
const originalFetch = globalThis.fetch
beforeEach(() => {
globalThis.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 } as Response)
})
afterEach(() => {
globalThis.fetch = originalFetch
})
it('confirmRoutine posts to confirm endpoint', async () => {
await confirmRoutine('child-1', 'routine-1')
expect(globalThis.fetch).toHaveBeenCalledWith('/api/child/child-1/confirm-routine', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ routine_id: 'routine-1' }),
})
})
it('cancelRoutineConfirmation posts to cancel endpoint', async () => {
await cancelRoutineConfirmation('child-2', 'routine-2')
expect(globalThis.fetch).toHaveBeenCalledWith('/api/child/child-2/cancel-routine-confirmation', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ routine_id: 'routine-2' }),
})
})
it('setChildRoutineOverride delegates to override endpoint with routine entity type', async () => {
await setChildRoutineOverride('child-3', 'routine-3', 11)
expect(globalThis.fetch).toHaveBeenCalledWith('/api/child/child-3/override', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ entity_id: 'routine-3', entity_type: 'routine', custom_value: 11 }),
})
})
it('setChildOverride supports routine entity type directly', async () => {
await setChildOverride('child-4', 'routine-4', 'routine', 12)
expect(globalThis.fetch).toHaveBeenCalledWith('/api/child/child-4/override', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ entity_id: 'routine-4', entity_type: 'routine', custom_value: 12 }),
})
})
})