updated behavior journal
This commit is contained in:
1 parent
dc07026a88
commit
7397b85e69
8 files changed
+69
-21
No files matched your search
@@ -15,8 +15,8 @@ export const behaviorRangeSchema = z.object({
|
||||
from: z.string().datetime({ offset: true }),
|
||||
to: z.string().datetime({ offset: true }),
|
||||
behaviorTypeId: z.string().uuid().optional(),
|
||||
}).refine(({ from, to }) => Date.parse(to) > Date.parse(from) && Date.parse(to) - Date.parse(from) <= 32 * 86400000, {
|
||||
message: 'Choose a date range of up to 32 days, with to after from.',
|
||||
}).refine(({ from, to }) => Date.parse(to) > Date.parse(from) && Date.parse(to) - Date.parse(from) <= 366 * 86400000, {
|
||||
message: 'Choose a date range of up to 366 days, with to after from.',
|
||||
});
|
||||
export type BehaviorInput = z.infer<typeof behaviorOccurrenceSchema>;
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ const behaviorResponse = registry.register('BehaviorOccurrence', z.object({
|
||||
}));
|
||||
endpoint({ method: 'get', path: '/birds/{birdId}/behavior-types', summary: 'List available behavior types', tag: 'Behavior Journal', response: many('behaviorTypes', behaviorTypeResponse), errors: [400, 404], description: 'Includes common behaviors, flock custom behaviors, and behaviors in this bird’s transferred history.' });
|
||||
endpoint({ method: 'post', path: '/birds/{birdId}/behavior-types', summary: 'Create a reusable flock behavior type', tag: 'Behavior Journal', body: behaviorTypeSchema, response: one('behaviorType', behaviorTypeResponse), errors: [404, 409], description: 'Names are unique within the flock, ignoring case. An existing type is returned for a duplicate name.' });
|
||||
endpoint({ method: 'get', path: '/birds/{birdId}/behaviors', summary: 'List behavior occurrences in a date range', tag: 'Behavior Journal', response: many('occurrences', behaviorResponse), query: z.object({ from: z.string().datetime({ offset: true }), to: z.string().datetime({ offset: true }), behaviorTypeId: z.string().uuid().optional() }), errors: [404], description: 'From is inclusive; to is exclusive. The range must be positive and at most 32 days. Send local month boundaries with their UTC offsets or converted to UTC. Results are newest first; individual events are never aggregated.' });
|
||||
endpoint({ method: 'get', path: '/birds/{birdId}/behaviors', summary: 'List behavior occurrences in a date range', tag: 'Behavior Journal', response: many('occurrences', behaviorResponse), query: z.object({ from: z.string().datetime({ offset: true }), to: z.string().datetime({ offset: true }), behaviorTypeId: z.string().uuid().optional() }), errors: [404], description: 'From is inclusive; to is exclusive. The range must be positive and at most 366 days. Send local date boundaries with their UTC offsets or converted to UTC. Results are newest first; individual events are never aggregated.' });
|
||||
endpoint({ method: 'post', path: '/birds/{birdId}/behaviors', summary: 'Record a behavior occurrence', tag: 'Behavior Journal', body: behaviorOccurrenceSchema, response: one('occurrence', behaviorResponse), errors: [404, 409], description: 'Duration is optional and measured in seconds. Intensity is optional, from 1 to 5. Occurrence timestamps require a time zone offset.' });
|
||||
endpoint({ method: 'put', path: '/birds/{birdId}/behaviors/{occurrenceId}', summary: 'Edit a behavior occurrence', tag: 'Behavior Journal', body: behaviorOccurrenceSchema, response: one('occurrence', behaviorResponse), errors: [404, 409] });
|
||||
endpoint({ method: 'delete', path: '/birds/{birdId}/behaviors/{occurrenceId}', summary: 'Delete a behavior occurrence', tag: 'Behavior Journal', errors: [400, 404, 409] });
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { behaviorRangeSchema } from '../behaviorSchemas.js';
|
||||
|
||||
test('behavior ranges span months and include a full leap year', () => {
|
||||
for (const range of [
|
||||
{ from: '2026-09-30T00:00:00-04:00', to: '2026-11-02T00:00:00-05:00' },
|
||||
{ from: '2024-01-01T00:00:00Z', to: '2025-01-01T00:00:00Z' },
|
||||
{ from: '2026-11-01T00:00:00-04:00', to: '2026-11-02T00:00:00-05:00' },
|
||||
]) assert.equal(behaviorRangeSchema.safeParse(range).success, true);
|
||||
});
|
||||
|
||||
test('behavior ranges reject invalid, reversed, empty, and oversized intervals', () => {
|
||||
for (const range of [
|
||||
{ from: 'invalid', to: 'invalid' },
|
||||
{ from: '2026-10-02T00:00:00Z', to: '2026-10-01T00:00:00Z' },
|
||||
{ from: '2026-10-01T00:00:00Z', to: '2026-10-01T00:00:00Z' },
|
||||
{ from: '2024-01-01T00:00:00Z', to: '2025-01-01T00:00:01Z' },
|
||||
]) assert.equal(behaviorRangeSchema.safeParse(range).success, false);
|
||||
});
|
||||
Reference in new issue
Block a user