mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +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:
@@ -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