Files
TREK/server/tests/unit/db/journey-social-migration.test.ts
T
Maurice 52552133e3 feat(journey): comment on journal entries and follow a share link by email
The people on a journey can now talk about its entries, and a reader of its
share link can comment there too and follow the journey by email (#1702,

- journey_entry_comments holds a comment under an entry: by an account or
  signed with a name through the link, plain text up to 2000 characters. It
  goes with its entry and journey; a deleted account leaves it as unknown.
  Everyone on the journey reads and writes them, the author or an editor
  deletes one, an editor hides one from everyone but the editors.
- The share link gains allow_comments and allow_subscriptions (default 0,
  kept when a save leaves them out). Readers comment under the entries the
  link shows, behind the link's password gate, with a honeypot field and a
  limit per address and link. The public payload says what a reader may do.
- journey_share_subscribers holds an address following a link, with double
  opt-in: one mail asks to confirm it, nothing else is sent before. The mail
  links open app pages that post the token, so a scanner changes nothing.
  The owner lists and removes the addresses; they go with the link.
- A daily job (journey-digest) tells everyone on a journey about entries
  published since the last run (journey_entry_published, their settings
  apply, not about their own), mails each confirmed follower once a day in
  their language with an unsubscribe link and a List-Unsubscribe header, and
  forgets addresses unconfirmed for a week. journey_entries.announced marks
  what was told; existing published entries start as told.
- The owner hears about a new comment (journey_comment). Both events are
  translated in every locale, as are the follower mails.
- journey:entry:commented pings the journey's people; the journal page
  leaves it to the comments reader instead of reloading.
- MCP: list_journey_comments, set_journey_comment_hidden,
  delete_journey_comment, list_journey_subscribers, remove_journey_subscriber,
  and create_journey_share_link takes both switches like the REST route. The
  assistant is not offered the follower tools.
2026-11-30 16:56:15 +01:00

65 lines
3.0 KiB
TypeScript

/**
* `Migration20200101046630_a_journey_gathers_comments_and_followers`: the two
* switches on `journey_share_tokens`, `journey_entries.announced`, and the
* comment and follower tables (#1702, #1669). Migrate to the step before it
* with a journey and its link already there, apply just this one, and check
* that the link comes through with both switches off and that every entry a
* reader already sees counts as told, so the first digest after an upgrade
* never names a journey's whole past. On Postgres the same step runs in the
* Postgres lane, where PARITY-PG holds the result to the entities.
*/
import { createMigrationOrm, migrateTo, pendingNames, rawExec, rawQuery } from '../../helpers/migration-step';
import { describe, expect, it } from 'vitest';
const TARGET = 'Migration20200101046630_a_journey_gathers_comments_and_followers';
describe('journey comments and followers migration', () => {
it('JSOCIAL-MIG-001: the switches start off, what readers see counts as told, the tables arrive', async () => {
const orm = await createMigrationOrm();
try {
const names = await pendingNames(orm);
const previous = names[names.indexOf(TARGET) - 1];
if (!previous) throw new Error('no step before the target');
await migrateTo(orm, previous);
await rawExec(orm, "INSERT INTO users (id, username, email, password_hash) VALUES (1, 'owner', 'o@test', 'x')");
await rawExec(
orm,
"INSERT INTO journeys (id, user_id, title, created_at, updated_at) VALUES (5, 1, 'Iceland', 0, 0)",
);
await rawExec(
orm,
"INSERT INTO journey_share_tokens (id, journey_id, token, created_by, share_timeline) VALUES (9, 5, 'tok', 1, 1)",
);
const entry = (id: number, type: string, draft: number, dismissed: number) =>
rawExec(
orm,
`INSERT INTO journey_entries (id, journey_id, author_id, type, entry_date, created_at, updated_at, is_draft, dismissed) VALUES (${id}, 5, 1, '${type}', '2026-01-01', 0, 0, ${draft}, ${dismissed})`,
);
await entry(1, 'entry', 0, 0);
await entry(2, 'entry', 1, 0);
await entry(3, 'skeleton', 0, 0);
await entry(4, 'entry', 0, 1);
await migrateTo(orm, TARGET);
expect(
await rawQuery(orm, 'SELECT allow_comments, allow_subscriptions FROM journey_share_tokens WHERE id = 9'),
).toEqual([{ allow_comments: 0, allow_subscriptions: 0 }]);
expect(await rawQuery(orm, 'SELECT id, announced FROM journey_entries ORDER BY id')).toEqual([
{ id: 1, announced: 1 },
{ id: 2, announced: 0 },
{ id: 3, announced: 0 },
{ id: 4, announced: 0 },
]);
const tables = await rawQuery<{ name: string }>(
orm,
"SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('journey_entry_comments', 'journey_share_subscribers') ORDER BY name",
);
expect(tables.map((t) => t.name)).toEqual(['journey_entry_comments', 'journey_share_subscribers']);
} finally {
await orm.close(true);
}
});
});