[schema] DaySentence: The sentence-opened event, an id and never text
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { validateCareEvent, validateHopeSentence, validateTrace } from '../src/validate.js';
|
||||
import { validateCareEvent, validateHopeSentence, validateSentenceOpened, validateTrace } from '../src/validate.js';
|
||||
|
||||
const KEY_A = 'A'.repeat(43);
|
||||
const KEY_B = 'b_-'.repeat(15);
|
||||
@@ -103,6 +103,26 @@ describe('care event', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('sentence opened (day-sentence.md P6)', () => {
|
||||
const opened = { kind: 'sentence-opened', ts: 1761500000000, localDay: '2026-10-24', from: KEY_A, messageId: 'ps-23-4', clientVersion: '0.1.0' };
|
||||
|
||||
it('accepts an opened petal', () => {
|
||||
expect(validateSentenceOpened(opened)).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
it('rejects text in place of an id, so no words can ride in the log', () => {
|
||||
expect(validateSentenceOpened({ ...opened, messageId: 'The LORD is my shepherd' }).ok).toBe(false);
|
||||
expect(validateSentenceOpened({ ...opened, messageId: null }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a missing day, an extra field, or another kind', () => {
|
||||
const { localDay: _, ...noDay } = opened;
|
||||
expect(validateSentenceOpened(noDay).ok).toBe(false);
|
||||
expect(validateSentenceOpened({ ...opened, atSunset: true }).ok).toBe(false);
|
||||
expect(validateSentenceOpened({ ...opened, kind: 'care' }).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('trace', () => {
|
||||
it('accepts a day-bucketed trace', () => {
|
||||
expect(validateTrace(trace)).toMatchObject({ ok: true });
|
||||
|
||||
Reference in New Issue
Block a user