21 lines
1.0 KiB
TypeScript
21 lines
1.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createFlockNote, deleteFlockNote } from './auditRepository.js';
|
|
import { mockDb } from '../test/mockDb.js';
|
|
|
|
test('bird notes require a current, non-memorialized bird in the workspace', async () => {
|
|
const { calls } = mockDb({ rows: [] });
|
|
const result = await createFlockNote({ workspaceId: 1, birdId: 'bird-1', body: 'Note', createdByUserId: 'user-1' });
|
|
assert.equal(result, null);
|
|
assert.match(calls[0].text, /birds.workspace_id = \$1\s+AND birds.memorialized_at IS NULL/);
|
|
assert.deepEqual(calls[0].params, [1, 'bird-1', 'Note', 'Note', 'user-1']);
|
|
});
|
|
|
|
test('deleting bird notes preserves memorialized and transferred bird history', async () => {
|
|
const { calls } = mockDb({ rows: [] });
|
|
assert.equal(await deleteFlockNote('note-1', 1), null);
|
|
assert.match(calls[0].text, /bird_id IS NULL OR EXISTS/);
|
|
assert.match(calls[0].text, /birds.id = flock_notes.bird_id/);
|
|
assert.match(calls[0].text, /birds.workspace_id = \$2\s+AND birds.memorialized_at IS NULL/);
|
|
});
|