added full api

This commit is contained in:
blaisadmin
2026-04-14 22:41:17 -04:00
parent e0ab66d21a
commit 37c8265320
17 changed files with 3146 additions and 978 deletions
@@ -0,0 +1,69 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createBird, getBirdById, listWeightsForBird } from './birdRepository.js';
import { mockDb } from '../test/mockDb.js';
test('getBirdById returns null when the bird does not exist in the workspace', async () => {
const { calls } = mockDb({ rowCount: 0, rows: [] });
const bird = await getBirdById('bird-1', 10);
assert.equal(bird, null);
assert.equal(calls.length, 1);
assert.deepEqual(calls[0].params, ['bird-1', 10]);
});
test('createBird returns the inserted bird row', async () => {
mockDb({
rowCount: 1,
rows: [
{
id: 'bird-1',
workspace_id: 10,
name: 'Kiwi',
tag_id: 'A-1',
species: 'Cockatiel',
date_of_birth: null,
gotcha_day: null,
chart_color: '#cb3a35',
photo_data_url: null,
notify_on_dob: false,
notify_on_gotcha_day: false,
created_at: '2026-04-14T00:00:00.000Z',
latest_weight_grams: null,
latest_recorded_on: null,
},
],
});
const bird = await createBird({
workspaceId: 10,
name: 'Kiwi',
tagId: 'A-1',
species: 'Cockatiel',
dateOfBirth: null,
gotchaDay: null,
chartColor: '#cb3a35',
photoDataUrl: null,
notifyOnDob: false,
notifyOnGotchaDay: false,
});
assert.equal(bird?.name, 'Kiwi');
assert.equal(bird?.workspace_id, 10);
});
test('listWeightsForBird scopes by bird, workspace, and day window', async () => {
const { calls } = mockDb({
rowCount: 0,
rows: [],
});
const weights = await listWeightsForBird('bird-1', 10, 30);
assert.deepEqual(weights, []);
assert.equal(calls.length, 1);
assert.deepEqual(calls[0].params, ['bird-1', 30, 10]);
assert.match(calls[0].text, /FROM weight_records/);
});