mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
fix(ci): repair Journey route registration and shared client behavior
Register the public view route, align generated entities and test fixtures, and share the scoped reads and access switches. Keep gallery and notification writes in order, and submit the email subscription from the dialog footer.
This commit is contained in:
@@ -20,6 +20,7 @@ import { TrekPhotos } from '../../src/db/entities/TrekPhotos.entity';
|
||||
import { createLocalMcpServer, McpRegistryService } from '../../src/nest-mcp';
|
||||
import { withRequestContext } from '../../src/nest/database/request-context';
|
||||
import { MapsService } from '../../src/nest/maps/maps.service';
|
||||
import { forEachInOrder } from '../../src/utils/for-each-in-order';
|
||||
import { addJourneyContributor, makeJourney } from '../helpers/factories/journeys';
|
||||
import { countRows, findRows, insertRow } from '../helpers/factories/rows';
|
||||
import { setAddonEnabled } from '../helpers/factories/settings';
|
||||
@@ -221,10 +222,11 @@ describe('journey entries from photos e2e', () => {
|
||||
expect(strangerRes.status).toBe(404);
|
||||
expect(strangerRes.body).toMatchObject({ error: 'Journey not found' });
|
||||
|
||||
for (const bad of [{}, { groups: [] }, { groups: [{ photoIds: ['1'] }] }, { groups: [{ photoIds: [1] }], x: 1 }]) {
|
||||
const invalid = [{}, { groups: [] }, { groups: [{ photoIds: ['1'] }] }, { groups: [{ photoIds: [1] }], x: 1 }];
|
||||
await forEachInOrder(invalid, async (bad) => {
|
||||
const res = await request(app.getHttpServer()).post(base(s.journey.id)).set(as(s.owner.id)).send(bad);
|
||||
expect(res.status, JSON.stringify(bad)).toBe(400);
|
||||
}
|
||||
});
|
||||
const badZone = await request(app.getHttpServer())
|
||||
.post(`${base(s.journey.id)}/preview`)
|
||||
.set(as(s.owner.id))
|
||||
|
||||
@@ -12,6 +12,7 @@ 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 { forEachInOrder } from '../../src/utils/for-each-in-order';
|
||||
import { makeJourney } from '../helpers/factories/journeys';
|
||||
import { countRows, findRow } from '../helpers/factories/rows';
|
||||
import { setAddonEnabled } from '../helpers/factories/settings';
|
||||
@@ -77,11 +78,11 @@ describe('a journey link with a password', () => {
|
||||
expect(JSON.stringify(read.body)).not.toContain('$2');
|
||||
|
||||
const locked = { error: 'Password required', code: 'JOURNEY_PASSWORD_REQUIRED' };
|
||||
for (const path of ['', '/map-layers', '/photos/1/thumbnail', '/photo/local/a.jpg/1/original']) {
|
||||
await forEachInOrder(['', '/map-layers', '/photos/1/thumbnail', '/photo/local/a.jpg/1/original'], async (path) => {
|
||||
const res = await request(server).get(`/api/public/journey/${token}${path}`);
|
||||
expect(res.status, path).toBe(401);
|
||||
expect(res.body, path).toEqual(locked);
|
||||
}
|
||||
});
|
||||
|
||||
const wrong = await request(server).post(`/api/public/journey/${token}/unlock`).send({ password: 'nope' });
|
||||
expect(wrong.status).toBe(401);
|
||||
@@ -122,12 +123,15 @@ describe('a journey link with a password', () => {
|
||||
|
||||
it('JPUBLINK-E2E-003: wrong passwords count per address and link, a right one does not', async () => {
|
||||
const { token } = await sharedJourney({ password: 'secret1' });
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const res = await request(server)
|
||||
.post(`/api/public/journey/${token}/unlock`)
|
||||
.send({ password: `nope${i}` });
|
||||
expect(res.status).toBe(401);
|
||||
}
|
||||
await forEachInOrder(
|
||||
Array.from({ length: 10 }, (_, i) => i),
|
||||
async (i) => {
|
||||
const res = await request(server)
|
||||
.post(`/api/public/journey/${token}/unlock`)
|
||||
.send({ password: `nope${i}` });
|
||||
expect(res.status).toBe(401);
|
||||
},
|
||||
);
|
||||
const limited = await request(server).post(`/api/public/journey/${token}/unlock`).send({ password: 'secret1' });
|
||||
expect(limited.status).toBe(429);
|
||||
|
||||
@@ -164,11 +168,11 @@ describe('a journey link with an expiry', () => {
|
||||
.send({ expires_at: '2020-01-01T00:00:00Z' });
|
||||
|
||||
const gone = { error: 'This link has expired', code: 'JOURNEY_LINK_EXPIRED' };
|
||||
for (const path of ['', '/map-layers', '/photos/1/thumbnail']) {
|
||||
await forEachInOrder(['', '/map-layers', '/photos/1/thumbnail'], async (path) => {
|
||||
const res = await request(server).get(`/api/public/journey/${token}${path}`);
|
||||
expect(res.status, path).toBe(410);
|
||||
expect(res.body, path).toEqual(gone);
|
||||
}
|
||||
});
|
||||
const unlock = await request(server).post(`/api/public/journey/${token}/unlock`).send({ password: 'x' });
|
||||
expect(unlock.status).toBe(410);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Notifications } from '../../src/db/entities/Notifications.entity';
|
||||
import { JourneyDigestService } from '../../src/nest/journey/journey-digest.service';
|
||||
import { MailerService } from '../../src/nest/notifications/mailer/mailer.service';
|
||||
import { NotificationsService } from '../../src/nest/notifications/notifications.service';
|
||||
import { forEachInOrder } from '../../src/utils/for-each-in-order';
|
||||
import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../helpers/factories/journeys';
|
||||
import { countRows, deleteRows, findRow, findRows } from '../helpers/factories/rows';
|
||||
import { setAddonEnabled } from '../helpers/factories/settings';
|
||||
@@ -270,7 +271,12 @@ describe('comments through the share link', () => {
|
||||
expect((await post(entry.id, { name: 'Bot', body: 'Hi', website: 'http://spam.example' })).status).toBe(200);
|
||||
expect(await countRows(orm, JourneyEntryComments, { journey: journey.id })).toBe(0);
|
||||
|
||||
for (let i = 0; i < 8; i++) expect((await post(entry.id, { name: 'Ana', body: `Hi ${i}` })).status).toBe(200);
|
||||
await forEachInOrder(
|
||||
Array.from({ length: 8 }, (_, i) => i),
|
||||
async (i) => {
|
||||
expect((await post(entry.id, { name: 'Ana', body: `Hi ${i}` })).status).toBe(200);
|
||||
},
|
||||
);
|
||||
expect((await post(entry.id, { name: 'Ana', body: 'One more' })).status).toBe(429);
|
||||
});
|
||||
|
||||
@@ -385,12 +391,15 @@ describe('following a link by email', () => {
|
||||
mailWorks();
|
||||
const { owner, journey } = await journeyWithPeople();
|
||||
const token = await share(journey.id, owner.id, { allow_subscriptions: true });
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const res = await request(server)
|
||||
.post(`/api/public/journey/${token}/subscribe`)
|
||||
.send({ email: `r${i}@example.com` });
|
||||
expect(res.status).toBe(200);
|
||||
}
|
||||
await forEachInOrder(
|
||||
Array.from({ length: 5 }, (_, i) => i),
|
||||
async (i) => {
|
||||
const res = await request(server)
|
||||
.post(`/api/public/journey/${token}/subscribe`)
|
||||
.send({ email: `r${i}@example.com` });
|
||||
expect(res.status).toBe(200);
|
||||
},
|
||||
);
|
||||
const sixth = await request(server)
|
||||
.post(`/api/public/journey/${token}/subscribe`)
|
||||
.send({ email: 'r6@example.com' });
|
||||
|
||||
@@ -20,6 +20,7 @@ import { JourneyModule } from '../../src/nest/journey/journey.module';
|
||||
import { ImmichService } from '../../src/nest/memories/immich.service';
|
||||
import { PhotoCaptureBackfillService } from '../../src/nest/memories/photo-capture-backfill.service';
|
||||
import { StorageService } from '../../src/nest/storage/storage.service';
|
||||
import { forEachInOrder } from '../../src/utils/for-each-in-order';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { seedUser, sessionCookie } from './harness';
|
||||
@@ -111,6 +112,7 @@ const { jsvc } = vi.hoisted(() => ({
|
||||
listEntries: vi.fn(),
|
||||
linkPhotoToEntry: vi.fn(),
|
||||
unlinkPhotoFromEntry: vi.fn(),
|
||||
canAccessJourney: vi.fn().mockResolvedValue(journeyRow(9)),
|
||||
addContributor: vi.fn(),
|
||||
updateContributorRole: vi.fn(),
|
||||
},
|
||||
@@ -902,7 +904,7 @@ describe('Journey e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('JOURNEY-E2E-040: 400 for the owner role or an unknown one on add and on update; the service is never asked', async () => {
|
||||
for (const role of ['owner', 'admin']) {
|
||||
await forEachInOrder(['owner', 'admin'], async (role) => {
|
||||
const add = await request(server)
|
||||
.post('/api/journeys/9/contributors')
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -913,7 +915,7 @@ describe('Journey e2e (real auth guard + temp SQLite)', () => {
|
||||
.set('Cookie', sessionCookie(1))
|
||||
.send({ role });
|
||||
expect(update.status, role).toBe(400);
|
||||
}
|
||||
});
|
||||
const none = await request(server)
|
||||
.patch('/api/journeys/9/contributors/2')
|
||||
.set('Cookie', sessionCookie(1))
|
||||
|
||||
@@ -8,6 +8,7 @@ import { JourneyEntries } from '../../../../src/db/entities/JourneyEntries.entit
|
||||
import { JourneyEntryComments } from '../../../../src/db/entities/JourneyEntryComments.entity';
|
||||
import { Users } from '../../../../src/db/entities/Users.entity';
|
||||
import type { JourneyEntryCommentsRepository } from '../../../../src/db/repositories/JourneyEntryComments.repository';
|
||||
import { forEachInOrder } from '../../../../src/utils/for-each-in-order';
|
||||
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
||||
import { makeJourneyComment } from '../../../helpers/factories/journey-social';
|
||||
import { makeJourney, makeJourneyEntry } from '../../../helpers/factories/journeys';
|
||||
@@ -89,9 +90,9 @@ describe('JourneyEntryCommentsRepository', () => {
|
||||
const dismissed = await makeJourneyEntry(t, journey.id, user.id, { dismissed: 1 });
|
||||
const shown = await makeJourneyComment(t, { id: entry.id, journey_id: journey.id }, null);
|
||||
await makeJourneyComment(t, { id: entry.id, journey_id: journey.id }, user.id, { hidden: 1 });
|
||||
for (const e of [draft, skeleton, dismissed]) {
|
||||
await forEachInOrder([draft, skeleton, dismissed], async (e) => {
|
||||
await makeJourneyComment(t, { id: e.id, journey_id: journey.id }, user.id);
|
||||
}
|
||||
});
|
||||
|
||||
expect((await comments.listPublicForJourney(journey.id)).map((r) => r.id)).toEqual([shown.id]);
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ import { JourneyEntryPhotos } from '../../../src/db/entities/JourneyEntryPhotos.
|
||||
import { JourneyPhotos } from '../../../src/db/entities/JourneyPhotos.entity';
|
||||
import { Journeys } from '../../../src/db/entities/Journeys.entity';
|
||||
import { TrekPhotos } from '../../../src/db/entities/TrekPhotos.entity';
|
||||
import { forEachInOrder } from '../../../src/utils/for-each-in-order';
|
||||
import { addJourneyContributor } from '../../helpers/factories/journeys';
|
||||
import { countRows, createRow, findRow, insertRow } from '../../helpers/factories/rows';
|
||||
import { setAddonEnabled } from '../../helpers/factories/settings';
|
||||
@@ -1257,7 +1258,8 @@ describe('journey entry fields', () => {
|
||||
await withHarness(user.id, async (h) => {
|
||||
const journey = await seedJourney(h);
|
||||
const entry = await seedEntry(h, journey.id);
|
||||
for (const bad of [{ visibility: 'friends' }, { location_lng: 181 }, { type: 'note' }]) {
|
||||
const invalid = [{ visibility: 'friends' }, { location_lng: 181 }, { type: 'note' }];
|
||||
await forEachInOrder(invalid, async (bad) => {
|
||||
expect(
|
||||
(
|
||||
await h.client.callTool({
|
||||
@@ -1266,7 +1268,7 @@ describe('journey entry fields', () => {
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
// And none of the refusals touched the row.
|
||||
const row = await entryRow(entry.id);
|
||||
expect(row.visibility).toBe('private');
|
||||
@@ -1612,7 +1614,7 @@ describe('Resource: trek://journeys/{journeyId}/entries', () => {
|
||||
});
|
||||
const data = parseResourceResult(
|
||||
await h.client.readResource({ uri: `trek://journeys/${journey.id}/entries` }),
|
||||
) as any[];
|
||||
) as { title: string; tags: string[] }[];
|
||||
expect(data).toHaveLength(1);
|
||||
expect(data[0].title).toBe('Day 1');
|
||||
expect(Array.isArray(data[0].tags)).toBe(true);
|
||||
@@ -1627,7 +1629,7 @@ describe('Resource: trek://journeys/{journeyId}/contributors', () => {
|
||||
const journey = await createJourney(h);
|
||||
const data = parseResourceResult(
|
||||
await h.client.readResource({ uri: `trek://journeys/${journey.id}/contributors` }),
|
||||
) as any[];
|
||||
) as { user_id?: number; id: number }[];
|
||||
expect(Array.isArray(data)).toBe(true);
|
||||
expect(data.map((c) => c.user_id ?? c.id)).toContain(user.id);
|
||||
});
|
||||
|
||||
@@ -1220,6 +1220,12 @@ describe('parity — JourneyShareTokensRepository reads match the legacy stateme
|
||||
newest_first,
|
||||
share_plan: false,
|
||||
share_recordings: false,
|
||||
has_password: false,
|
||||
expires_at: null,
|
||||
view_count: 0,
|
||||
last_viewed_at: null,
|
||||
allow_comments: false,
|
||||
allow_subscriptions: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1403,13 +1409,14 @@ describe('a protected share link', () => {
|
||||
body: { error: 'Wrong password', code: 'JOURNEY_PASSWORD_INVALID' },
|
||||
});
|
||||
const unlocked = await svc.unlockPublicLink(token, 'open sesame');
|
||||
if (!unlocked) throw new Error('Expected a proof for the protected link');
|
||||
expect(unlocked).toEqual({ proof: unlockProof(token, 1), expiresAt: null });
|
||||
expect((await svc.assertPublicAccess(token, unlocked!.proof)).journey_id).toBe(journey.id);
|
||||
expect((await svc.assertPublicAccess(token, unlocked.proof)).journey_id).toBe(journey.id);
|
||||
// A proof is only good for its own link.
|
||||
const other = await svc.createOrUpdateJourneyShareLink(createJourney(testDb, user.id).id, user.id, {
|
||||
password: 'open sesame',
|
||||
});
|
||||
expect(await refusal(() => svc.assertPublicAccess(other.token, unlocked!.proof))).toMatchObject({ status: 401 });
|
||||
expect(await refusal(() => svc.assertPublicAccess(other.token, unlocked.proof))).toMatchObject({ status: 401 });
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-PW-004: changing or removing the password signs every unlocked reader out again', async () => {
|
||||
|
||||
@@ -14,6 +14,7 @@ import type { JourneyService } from '../../../src/nest/journey/journey.service';
|
||||
import { RenditionPendingError, type PublicMediaService } from '../../../src/nest/memories/public-media.service';
|
||||
import type { StorageService } from '../../../src/nest/storage/storage.service';
|
||||
import type { User } from '../../../src/types';
|
||||
import { forEachInOrder } from '../../../src/utils/for-each-in-order';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
@@ -759,11 +760,11 @@ describe('JourneyController', () => {
|
||||
});
|
||||
|
||||
it('DELETE gallery photo: the journey of the path goes along, a refusal or nothing deleted is a 404', async () => {
|
||||
for (const answer of [null, []]) {
|
||||
await forEachInOrder([null, []], async (answer) => {
|
||||
const refusing = ctl(svc(), {}, {}, { deleteFromGallery: vi.fn().mockResolvedValue(answer) });
|
||||
const refusal = await thrownAsync(() => refusing.deleteGalleryPhoto(user, 3, 7));
|
||||
expect(refusal).toEqual({ status: 404, body: { error: 'Photo not found or not allowed' } });
|
||||
}
|
||||
});
|
||||
(storageStub.delete as ReturnType<typeof vi.fn>).mockClear();
|
||||
const deleteFromGallery = vi.fn().mockResolvedValue([10]);
|
||||
expect(await ctl(svc(), {}, {}, { deleteFromGallery }).deleteGalleryPhoto(user, 3, 10, 'sock-1')).toBeUndefined();
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
JourneyEntriesFromPhotosService,
|
||||
} from '../../../../src/nest/journey/journey-entries-from-photos.service';
|
||||
import { MapsService } from '../../../../src/nest/maps/maps.service';
|
||||
import { forEachInOrder } from '../../../../src/utils/for-each-in-order';
|
||||
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
||||
import { addJourneyContributor, makeJourney, makeJourneyEntry } from '../../../helpers/factories/journeys';
|
||||
import { countRows, findRow, findRows, insertRow } from '../../../helpers/factories/rows';
|
||||
@@ -212,10 +213,11 @@ describe('JourneyEntriesFromPhotosService.preview', () => {
|
||||
it('JRNPHOTOS-SVC-003: asks the geocoder about a bounded number of points and names the rest by country', async () => {
|
||||
const { owner, journey } = await fixture();
|
||||
// One group per day, each a few kilometres further east.
|
||||
for (let day = 0; day < FROM_PHOTOS_MAX_GEOCODED + 2; day++) {
|
||||
const offsets = Array.from({ length: FROM_PHOTOS_MAX_GEOCODED + 2 }, (_, offset) => offset);
|
||||
await forEachInOrder(offsets, async (day) => {
|
||||
const date = new Date(Date.UTC(2026, 4, 1 + day, 7)).toISOString();
|
||||
await galleryPhoto(journey.id, owner.id, date, { lat: 45.0, lng: 9 + day * 0.05 });
|
||||
}
|
||||
});
|
||||
const preview = await svc.preview(owner.id, journey.id, {});
|
||||
expect(reverseGeocode).toHaveBeenCalledTimes(FROM_PHOTOS_MAX_GEOCODED);
|
||||
expect(preview.clusters.filter((c) => c.titleSource === 'place')).toHaveLength(FROM_PHOTOS_MAX_GEOCODED);
|
||||
|
||||
@@ -157,14 +157,20 @@ describe('getPreferencesMatrix', () => {
|
||||
// +1 for plugin_notification: users can mute host-mediated plugin notifications.
|
||||
// +1 for wanderer_source_hint: the hints of the user's own wanderer watch (WAN-02).
|
||||
// +3 for flight_departed, flight_delayed and flight_landed (live flight status, on by default).
|
||||
expect(event_types.length).toBe(16);
|
||||
expect(event_types).toEqual(
|
||||
expect.arrayContaining(['journey_invite', 'journey_comment', 'journey_entry_published']),
|
||||
);
|
||||
expect(event_types).toHaveLength(19);
|
||||
});
|
||||
|
||||
it('NPREF-005 — user scope excludes version_available for everyone including admins', async () => {
|
||||
const { user } = createAdmin(testDb);
|
||||
const { event_types } = await getPreferencesMatrix(user.id, 'admin', 'user');
|
||||
expect(event_types).not.toContain('version_available');
|
||||
expect(event_types.length).toBe(16);
|
||||
expect(event_types).toEqual(
|
||||
expect.arrayContaining(['journey_invite', 'journey_comment', 'journey_entry_published']),
|
||||
);
|
||||
expect(event_types).toHaveLength(19);
|
||||
});
|
||||
|
||||
it('NPREF-005b — admin scope returns the admin-scoped events', async () => {
|
||||
|
||||
Reference in New Issue
Block a user