Hub 2.26.1: devotionals two years ahead; Apps fetch 2 weeks

Devotionals can be written, edited and imported up to two years ahead
(was 3 months), and a CSV holds two years in one file (800 rows, 8 MB).
GET /api/v2/devotionals answers 2 weeks (from and the 13 days after it)
instead of 3 months. Contracts 1.24.0 vendored. No migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 23:23:37 +02:00
co-authored by Claude Opus 5.5
parent 28b108a577
commit 20ea32d533
14 changed files with 73 additions and 52 deletions
+16 -13
View File
@@ -1,5 +1,5 @@
// Hub 2.26.0 (crosscode-platform docs/APP-1.0-PLAN.md §6): Cross Code's devotionals. Written up to 3
// months ahead in the free translations only, imported from CSV with a preview, and fetched by App
// Hub 2.26.0 (crosscode-platform docs/APP-1.0-PLAN.md §6): Cross Code's devotionals. Written up to two
// years ahead (2.26.1) in the free translations only, imported from CSV with a preview, and fetched by App
// installs (GET /api/v2/devotionals with the licence token; App licences only). Also the App's
// tier alert (its active-member band above its tier).
const crypto = require('crypto');
@@ -29,20 +29,21 @@ const form = (over = {}) => ({
beforeEach(() => { for (const k of Object.keys(db.tables)) db.tables[k].length = 0; });
describe('writing devotionals', () => {
test('a devotional: the passage written out, in a free translation, within 3 months', async () => {
test('a devotional: the passage written out, in a free translation, within two years', async () => {
const { devotional, warnings } = await devotionals.create(form(), admin, NOW);
expect(devotional).toMatchObject({ date: '2026-12-05', passage: { reference: '1 Corinthians 13:4–7', translation: 'BSB', text: 'Love is patient, love is kind.' }, prayer: 'Lord, teach me to love.' });
expect(warnings).toEqual([]);
await expect(devotionals.create(form({ title: 'Another' }), admin, NOW)).rejects.toMatchObject({ code: 'DATE_TAKEN' });
});
test('refused: a translation that needs permission, more than 3 months ahead, a reference that can\'t be read, an empty field', async () => {
expect(devotionals.latestDate(NOW)).toBe('2027-02-28');
test('refused: a translation that needs permission, more than two years ahead, a reference that can\'t be read, an empty field', async () => {
expect(devotionals.latestDate(NOW)).toBe('2028-11-30');
await expect(devotionals.create(form({ translation: 'NIV' }), admin, NOW)).rejects.toMatchObject({ code: 'TRANSLATION_NOT_FREE', message: expect.stringContaining('KJV or BSB') });
await expect(devotionals.create(form({ date: '2027-03-01' }), admin, NOW)).rejects.toMatchObject({ code: 'TOO_FAR_AHEAD', message: expect.stringContaining('2027-02-28') });
expect((await devotionals.create(form({ date: '2028-11-30', title: 'Two years on' }), admin, NOW)).devotional.date).toBe('2028-11-30');
await expect(devotionals.create(form({ date: '2028-12-01' }), admin, NOW)).rejects.toMatchObject({ code: 'TOO_FAR_AHEAD', message: expect.stringContaining('up to two years ahead (the last day is 2028-11-30)') });
await expect(devotionals.create(form({ reference: 'Hezekiah 1:1' }), admin, NOW)).rejects.toMatchObject({ code: 'BAD_REFERENCE' });
await expect(devotionals.create(form({ body: ' ' }), admin, NOW)).rejects.toMatchObject({ status: 400, message: expect.stringContaining('The devotional') });
expect(await db.devotional.findMany({})).toEqual([]);
expect((await db.devotional.findMany({})).map(d => d.date)).toEqual(['2028-11-30']);
});
test('a long passage is saved, with a warning', async () => {
@@ -56,7 +57,7 @@ describe('writing devotionals', () => {
await expect(devotionals.update(devotional.id, form({ date: '2026-12-06' }), NOW)).rejects.toMatchObject({ code: 'DATE_TAKEN' });
expect((await devotionals.update(devotional.id, form({ date: '2026-12-07', title: 'Moved' }), NOW)).devotional).toMatchObject({ date: '2026-12-07', title: 'Moved' });
const o = await devotionals.overview(NOW);
expect(o).toMatchObject({ today: '2026-11-30', latest: '2027-02-28', aheadMonths: 3 });
expect(o).toMatchObject({ today: '2026-11-30', latest: '2028-11-30', aheadMonths: 24, ahead: 'two years', appFetchDays: 14 });
expect(o.devotionals.map(d => d.date)).toEqual(['2026-12-06', '2026-12-07']);
expect(o.empty).toContain('2026-12-05');
expect(o.empty).not.toContain('2026-12-06');
@@ -72,12 +73,12 @@ describe('Import CSV', () => {
test('the preview checks every row: a translation needing permission, too far ahead, a day taken', async () => {
await devotionals.create(form({ date: '2026-12-11' }), admin, NOW);
const csv = devotionalCsv([row(), row({ date: '2026-12-11' }), row({ date: '2026-12-12', translation: 'ESV' }), row({ date: '2027-06-01' })]);
const csv = devotionalCsv([row(), row({ date: '2026-12-11' }), row({ date: '2026-12-12', translation: 'ESV' }), row({ date: '2028-12-01' })]);
const preview = await devotionals.previewCsv(csv, NOW);
expect(preview.fileError).toBeNull();
expect(preview.rows.map(r => [!!r.devotional, r.taken])).toEqual([[true, false], [true, true], [false, false], [false, false]]);
expect(preview.rows[2].errors[0].message).toContain('Crossway');
expect(preview.rows[3].errors[0].message).toContain('3 months');
expect(preview.rows[3].errors[0].message).toContain('too far ahead (the last day is 2028-11-30)');
});
test('importing saves the valid rows; days already filled are skipped or replaced', async () => {
@@ -109,16 +110,18 @@ describe('GET /api/v2/devotionals', () => {
}
const get = (token, query = '') => fetch(`${base}/v2/devotionals${query}`, { headers: token ? { Authorization: `Bearer ${token}` } : {} });
test("an App's licence token gets the next 3 months from `from`, as crosscode.devotional/1", async () => {
test("an App's licence token gets the next 2 weeks from `from`, as crosscode.devotional/1", async () => {
const today = devotionals.today();
const later = devotionals.addMonths(today, 1);
const later = devotionals.addDays(today, 13);
const tooLate = devotionals.addDays(today, 14);
await db.devotional.create({ data: { id: crypto.randomUUID(), date: tooLate, title: 'Too late', passage: { reference: 'John 3:16', location: { book: 'JHN', chapter: 3, verse: 16, endChapter: 3, endVerse: 16 }, translation: 'KJV', text: 'x' }, body: 'Body', prayer: null, author: null, updatedAt: new Date() } });
await db.devotional.create({ data: { id: crypto.randomUUID(), date: later, title: 'Later', passage: { reference: 'John 3:16', location: { book: 'JHN', chapter: 3, verse: 16, endChapter: 3, endVerse: 16 }, translation: 'KJV', text: 'For God so loved the world' }, body: 'Body', prayer: null, author: null, updatedAt: new Date() } });
await db.devotional.create({ data: { id: crypto.randomUUID(), date: '2020-01-01', title: 'Old', passage: { reference: 'John 3:16', location: { book: 'JHN', chapter: 3, verse: 16, endChapter: 3, endVerse: 16 }, translation: 'KJV', text: 'x' }, body: 'Body', prayer: null, author: null, updatedAt: new Date() } });
const res = await get(await licence());
expect(res.status).toBe(200);
const body = await res.json();
expect(devotionalsReplySchema.safeParse(body).success).toBe(true);
expect(body).toMatchObject({ from: today, to: devotionals.addMonths(today, 3) });
expect(body).toMatchObject({ from: today, to: later });
expect(body.devotionals.map(d => [d.date, d.source])).toEqual([[later, 'crosscode']]);
});