mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
feat(notifications): tell a new journey contributor they were added
Adding somebody to a journey was silent (#1669). The new journey_invite event goes to the person added, in-app with a button to the journey and on every channel they use, once: posting the same person again only changes their role. The REST route and the MCP tool both go through JourneyService.addContributor, so both send it; the send is fire and forget like the trip and collection invites. The event is listed while the Journey addon is on, with its label in the notification settings, and its texts are translated in every locale.
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
/**
|
||||
* A protected public journey link, end to end (#2553, #1702, #2959): the
|
||||
* A protected public journey link, end to end (#2553, #1702, #2959, #1669): the
|
||||
* whole app (buildApp, the real guards, share service and rate limit on a
|
||||
* migrated temp SQLite) between the owner who sets a password and an expiry
|
||||
* and the reader who opens the link. Every public route refuses a locked link,
|
||||
* the unlock sets a cookie scoped to the link's own path, a changed password
|
||||
* locks the old cookie out again, an expired link answers 410, saving a switch
|
||||
* keeps the protection, and readers are counted once a day for the owner only.
|
||||
* keeps the protection, readers are counted once a day for the owner only, and
|
||||
* a new contributor hears about the journey.
|
||||
*/
|
||||
import { buildApp } from '../../src/bootstrap';
|
||||
import { JourneyShareTokens } from '../../src/db/entities/JourneyShareTokens.entity';
|
||||
import { Notifications } from '../../src/db/entities/Notifications.entity';
|
||||
import { NotificationsService } from '../../src/nest/notifications/notifications.service';
|
||||
import { makeJourney } from '../helpers/factories/journeys';
|
||||
import { findRow } from '../helpers/factories/rows';
|
||||
import { countRows, findRow } from '../helpers/factories/rows';
|
||||
import { setAddonEnabled } from '../helpers/factories/settings';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { resetRateLimits } from '../helpers/test-db';
|
||||
@@ -213,3 +216,31 @@ describe('the view count of a journey link', () => {
|
||||
expect((await findRow(orm, JourneyShareTokens, { token }))?.view_count).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the journey invite notification', () => {
|
||||
it('JPUBLINK-E2E-030: a new contributor hears about the journey once, a role change says nothing', async () => {
|
||||
const { user: owner } = await makeUser(orm, { username: 'owner_jp' });
|
||||
const { user: friend } = await makeUser(orm);
|
||||
const journey = await makeJourney(orm, owner.id, { title: 'Iceland ring road' });
|
||||
const notifications = app.get(NotificationsService, { strict: false });
|
||||
|
||||
const add = (role: string) =>
|
||||
request(server)
|
||||
.post(`/api/journeys/${journey.id}/contributors`)
|
||||
.set('Cookie', sessionCookie(owner.id))
|
||||
.send({ user_id: friend.id, role });
|
||||
|
||||
const invites = { recipient: friend.id, title_key: 'notif.journey_invite.title' };
|
||||
|
||||
expect((await add('viewer')).status).toBe(201);
|
||||
await notifications.settled();
|
||||
const sent = await findRow(orm, Notifications, invites);
|
||||
expect(sent).toMatchObject({ navigate_target: `/journey/${journey.id}` });
|
||||
expect(JSON.parse(String(sent?.text_params))).toMatchObject({ actor: 'owner_jp', journey: 'Iceland ring road' });
|
||||
|
||||
// Posting the same person again only changes the role.
|
||||
expect((await add('editor')).status).toBe(201);
|
||||
await notifications.settled();
|
||||
expect(await countRows(orm, Notifications, invites)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -466,6 +466,8 @@ const journeyCases: ParityCase[] = [
|
||||
{
|
||||
tool: 'add_journey_contributor',
|
||||
needs: ['journey', 'member'],
|
||||
// The journey_invite notification (#1669) is held back, like the other invites.
|
||||
stub: quietNotifications,
|
||||
args: (s) => ({ journeyId: s.journey.id, targetUserId: s.member.id, role: 'viewer' }),
|
||||
rest: {
|
||||
method: 'post',
|
||||
|
||||
Reference in New Issue
Block a user