mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
refactor(server): places, unsplash, vacay, collections and file downloads raise DomainError, so REST and MCP stop translating results
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* registry in tests/helpers/mcp-test-controllers.ts, so the assertions below
|
||||
* exercise the @Tool/@ResourceTemplate path instead of the deleted registrar.
|
||||
*/
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
import { db as testDb } from '../../../src/db/database';
|
||||
|
||||
@@ -1012,10 +1013,10 @@ describe('Tool: import_places_from_url', () => {
|
||||
list.mockRestore();
|
||||
});
|
||||
|
||||
it('surfaces the naver importer\'s { error, status } as a tool error', async () => {
|
||||
it('surfaces the naver importer\'s refusal as a tool error', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const spy = vi.spyOn(PlacesService.prototype, 'importNaverList').mockResolvedValue({ error: 'List is empty or could not be read', status: 400 });
|
||||
const spy = vi.spyOn(PlacesService.prototype, 'importNaverList').mockRejectedValue(new DomainError(400, 'List is empty or could not be read'));
|
||||
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* trek://vacay/holidays/{year} — these ride the registry too (attached inside
|
||||
* registerTools), so `withTools` must stay on even for resource reads.
|
||||
*/
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterEach, afterAll } from 'vitest';
|
||||
import { db as testDb } from '../../../src/db/database';
|
||||
|
||||
@@ -720,7 +721,7 @@ describe('Tool: list_school_holiday_regions', () => {
|
||||
|
||||
it('surfaces the upstream failure', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
schoolRegionsSpy.mockResolvedValueOnce({ error: 'Failed to fetch school holiday regions' });
|
||||
schoolRegionsSpy.mockRejectedValueOnce(new DomainError(502, 'Failed to fetch school holiday regions'));
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name: 'list_school_holiday_regions', arguments: { country: 'DE' } });
|
||||
expect(result.isError).toBe(true);
|
||||
@@ -757,7 +758,7 @@ describe('Tool: list_school_holidays', () => {
|
||||
|
||||
it('surfaces the upstream failure', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
schoolHolidaysSpy.mockResolvedValueOnce({ error: 'Failed to fetch school holidays' });
|
||||
schoolHolidaysSpy.mockRejectedValueOnce(new DomainError(502, 'Failed to fetch school holidays'));
|
||||
await withHarness(user.id, async (h) => {
|
||||
const result = await h.client.callTool({ name: 'list_school_holidays', arguments: { country: 'DE', year: 2025 } });
|
||||
expect(result.isError).toBe(true);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { RuntimeEnvService } from '../../../src/nest/app-config/runtime-env.service';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
@@ -140,7 +141,7 @@ describe('CollectionsController', () => {
|
||||
.toEqual({ status: 403, body: { error: 'Only the owner can invite' } });
|
||||
});
|
||||
it('surfaces a sendInvite error with its status', async () => {
|
||||
const svc = makeService({ sendInvite: vi.fn().mockResolvedValue({ error: 'Already a member', status: 409 }) });
|
||||
const svc = makeService({ sendInvite: vi.fn().mockRejectedValue(new DomainError(409, 'Already a member')) });
|
||||
expect(await thrownAsync(() => new CollectionsController(svc, new RuntimeEnvService(), storageStub).invite(user, { collection_id: 3, user_id: 2 } as never)))
|
||||
.toEqual({ status: 409, body: { error: 'Already a member' } });
|
||||
});
|
||||
@@ -149,7 +150,7 @@ describe('CollectionsController', () => {
|
||||
expect(await new CollectionsController(svc, new RuntimeEnvService(), storageStub).invite(user, { collection_id: 3, user_id: 2 } as never)).toEqual({ success: true });
|
||||
});
|
||||
it('accept surfaces an error, else succeeds', async () => {
|
||||
const bad = makeService({ acceptInvite: vi.fn().mockResolvedValue({ error: 'Gone', status: 404 }) });
|
||||
const bad = makeService({ acceptInvite: vi.fn().mockRejectedValue(new DomainError(404, 'Gone')) });
|
||||
expect(await thrownAsync(() => new CollectionsController(bad, new RuntimeEnvService(), storageStub).acceptInvite(user, { collection_id: 3 } as never, 'sid')))
|
||||
.toEqual({ status: 404, body: { error: 'Gone' } });
|
||||
const svc = makeService();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* faithfully. Keeps its own clearCollections() reset (the shared
|
||||
* resetTestDb RESET_TABLES list has no collection tables).
|
||||
*/
|
||||
import { asLegacyResult } from '../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
|
||||
vi.mock('../../../src/db/database', async () => {
|
||||
@@ -572,11 +573,11 @@ describe('fusion invitations', () => {
|
||||
|
||||
it('COLLECTIONS-SVC-030: sendInvite — self 400, unknown 404, non-owner 403, happy path', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
expect((await svc.sendInvite(col.id, owner.id, owner.username, owner.email, owner.id)).status).toBe(400);
|
||||
expect((await svc.sendInvite(col.id, owner.id, owner.username, owner.email, 99999)).status).toBe(404);
|
||||
expect((await svc.sendInvite(col.id, target.id, target.username, target.email, owner.id)).status).toBe(403); // non-owner inviter
|
||||
expect((await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, owner.id))).status).toBe(400);
|
||||
expect((await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, 99999))).status).toBe(404);
|
||||
expect((await asLegacyResult(svc.sendInvite(col.id, target.id, target.username, target.email, owner.id))).status).toBe(403); // non-owner inviter
|
||||
|
||||
const ok = await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
const ok = await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
expect(ok.error).toBeUndefined();
|
||||
expect(broadcastToUser).toHaveBeenCalledWith(target.id, expect.objectContaining({ type: 'collections:invite' }));
|
||||
// the notification send is fire-and-forget via a dynamic import — flush microtasks.
|
||||
@@ -585,37 +586,37 @@ describe('fusion invitations', () => {
|
||||
|
||||
it('COLLECTIONS-SVC-031: double-invite while pending → 400; existing member → 400', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
expect((await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id)).status).toBe(400);
|
||||
await svc.acceptInvite(target.id, col.id, undefined);
|
||||
expect((await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id)).error).toBe('Already a member');
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
expect((await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id))).status).toBe(400);
|
||||
await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined));
|
||||
expect((await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id))).error).toBe('Already a member');
|
||||
});
|
||||
|
||||
it('COLLECTIONS-SVC-032: acceptInvite — 404 with no pending; flips to accepted → member now sees list', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
expect((await svc.acceptInvite(target.id, col.id, undefined)).status).toBe(404);
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
expect((await svc.acceptInvite(target.id, col.id, undefined)).error).toBeUndefined();
|
||||
expect((await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined))).status).toBe(404);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
expect((await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined))).error).toBeUndefined();
|
||||
expect((await svc.listCollections(target.id)).collections.map((c) => c.id)).toContain(col.id);
|
||||
});
|
||||
|
||||
it('COLLECTIONS-SVC-033: accept-after-cancel → 404 (no orphan accept)', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
await svc.cancelInvite(col.id, owner.id, target.id);
|
||||
expect((await svc.acceptInvite(target.id, col.id, undefined)).status).toBe(404);
|
||||
expect((await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined))).status).toBe(404);
|
||||
});
|
||||
|
||||
it('COLLECTIONS-SVC-034: declineInvite removes the pending row', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
await svc.declineInvite(target.id, col.id, undefined);
|
||||
expect(await membersOf(col.id)).toEqual({ n: 0 });
|
||||
});
|
||||
|
||||
it('COLLECTIONS-SVC-035: cancelInvite is owner-only', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
await expect(svc.cancelInvite(col.id, target.id, target.id)).rejects.toThrow(); // non-owner
|
||||
await svc.cancelInvite(col.id, owner.id, target.id); // owner ok
|
||||
expect(await membersOf(col.id)).toEqual({ n: 0 });
|
||||
@@ -623,8 +624,8 @@ describe('fusion invitations', () => {
|
||||
|
||||
it('COLLECTIONS-SVC-036: leaveCollection — member ok, owner blocked (400)', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
await svc.acceptInvite(target.id, col.id, undefined);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined));
|
||||
await svc.leaveCollection(target.id, col.id, undefined);
|
||||
expect((await svc.listCollections(target.id)).collections.map((c) => c.id)).not.toContain(col.id);
|
||||
|
||||
@@ -638,8 +639,8 @@ describe('fusion invitations', () => {
|
||||
const colA = await svc.createCollection(owner.id, { name: 'A' });
|
||||
const colB = await svc.createCollection(owner.id, { name: 'B' });
|
||||
// target is accepted in A; must still be invitable to B
|
||||
await svc.sendInvite(colA.id, owner.id, owner.username, owner.email, target.id);
|
||||
await svc.acceptInvite(target.id, colA.id, undefined);
|
||||
await asLegacyResult(svc.sendInvite(colA.id, owner.id, owner.username, owner.email, target.id));
|
||||
await asLegacyResult(svc.acceptInvite(target.id, colA.id, undefined));
|
||||
|
||||
const forB = (await svc.availableUsers(owner.id, colB.id)).map((u) => u.id);
|
||||
expect(forB).toContain(target.id);
|
||||
@@ -661,9 +662,9 @@ describe('fusion invitations', () => {
|
||||
|
||||
it('COLLECTIONS-SVC-039: visibility = owner OR accepted member (pending does NOT grant access)', async () => {
|
||||
const { owner, target, col } = await setup();
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, target.id));
|
||||
await expect(svc.getCollection(target.id, col.id)).rejects.toThrow(); // pending, no access yet
|
||||
await svc.acceptInvite(target.id, col.id, undefined);
|
||||
await asLegacyResult(svc.acceptInvite(target.id, col.id, undefined));
|
||||
expect((await svc.getCollection(target.id, col.id)).collection.id).toBe(col.id);
|
||||
});
|
||||
});
|
||||
@@ -677,9 +678,9 @@ describe('deleteCollection', () => {
|
||||
const pending = createUser(testDb).user;
|
||||
const col = await svc.createCollection(owner.id, { name: 'Doomed' });
|
||||
await svc.savePlace(owner.id, { collection_id: col.id, name: 'P' });
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, accepted.id);
|
||||
await svc.acceptInvite(accepted.id, col.id, undefined);
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, accepted.id));
|
||||
await asLegacyResult(svc.acceptInvite(accepted.id, col.id, undefined));
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id));
|
||||
|
||||
// a non-owner member cannot delete
|
||||
await expect(svc.deleteCollection(accepted.id, col.id)).rejects.toThrow();
|
||||
@@ -1028,9 +1029,9 @@ describe('membership lookups', () => {
|
||||
expect(await svc.findMembershipForUser(owner.id, col.id)).toEqual({ is_member: true, is_owner: true, status: 'accepted' });
|
||||
expect(await svc.findMembershipForUser(outsider.id, col.id)).toEqual({ is_member: false, is_owner: false, status: null });
|
||||
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, member.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, member.id));
|
||||
expect(await svc.findMembershipForUser(member.id, col.id)).toEqual({ is_member: false, is_owner: false, status: 'pending' });
|
||||
await svc.acceptInvite(member.id, col.id, undefined);
|
||||
await asLegacyResult(svc.acceptInvite(member.id, col.id, undefined));
|
||||
expect(await svc.findMembershipForUser(member.id, col.id)).toEqual({ is_member: true, is_owner: false, status: 'accepted' });
|
||||
});
|
||||
});
|
||||
@@ -1688,7 +1689,7 @@ describe('Plan 3h Task 1 — repository conversion parity', () => {
|
||||
await addMember(col.id, admin.id, 'admin');
|
||||
await addMember(col.id, editor.id, 'editor');
|
||||
await addMember(col.id, viewer.id, 'viewer');
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id));
|
||||
|
||||
const tag = createTag(testDb, owner.id, { name: 'Foodie' });
|
||||
const place = (await svc.savePlace(owner.id, {
|
||||
@@ -1748,9 +1749,9 @@ describe('Plan 3h Task 1 — repository conversion parity', () => {
|
||||
const accepted = createUser(testDb).user;
|
||||
const pending = createUser(testDb).user;
|
||||
const col = await svc.createCollection(owner.id, { name: 'Ordering proof' });
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, accepted.id);
|
||||
await svc.acceptInvite(accepted.id, col.id, undefined);
|
||||
await svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id);
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, accepted.id));
|
||||
await asLegacyResult(svc.acceptInvite(accepted.id, col.id, undefined));
|
||||
await asLegacyResult(svc.sendInvite(col.id, owner.id, owner.username, owner.email, pending.id));
|
||||
|
||||
broadcastToUser.mockClear();
|
||||
// Captured at CALL time, not after `deleteCollection` returns — if the
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { RuntimeEnvService } from '../../../src/nest/app-config/runtime-env.service';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
@@ -261,7 +262,7 @@ describe('FilesDownloadController', () => {
|
||||
const res = {} as Response;
|
||||
|
||||
it('maps the auth error from authenticateDownload', async () => {
|
||||
const s = dsvc({ authenticateDownload: vi.fn().mockReturnValue({ error: 'Authentication required', status: 401 }) });
|
||||
const s = dsvc({ authenticateDownload: vi.fn().mockRejectedValue(new DomainError(401, 'Authentication required')) });
|
||||
expect(await rejected(new FilesDownloadController(s, dstor()).download(req, res, '5', '9'))).toEqual({ status: 401, body: { error: 'Authentication required' } });
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* and the download-token auth over a real in-memory SQLite DB, plus the
|
||||
* files.bridge delegation (inside the src/nest coverage gate).
|
||||
*/
|
||||
import { asLegacyResult } from '../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll, afterEach } from 'vitest';
|
||||
import path from 'path';
|
||||
|
||||
@@ -808,7 +809,7 @@ describe('read-model parity: raw SQL vs. the repository-backed reads', () => {
|
||||
describe('authenticateDownload', () => {
|
||||
it('FILE-SVC-032: a valid session cookie wins over a bearer token', async () => {
|
||||
verifyJwtAndLoadUser.mockReturnValue({ id: 42 });
|
||||
const result = await svc.authenticateDownload(req({ cookie: 'cookie-jwt', bearer: 'bearer-jwt' }));
|
||||
const result = await asLegacyResult(svc.authenticateDownload(req({ cookie: 'cookie-jwt', bearer: 'bearer-jwt' })));
|
||||
expect(result).toEqual({ userId: 42 });
|
||||
// The concrete expected argument, not expect.anything(): emStub.getRepository
|
||||
// always returns a fresh `{}` (task-1-review.md F6) — deep-equal, not a
|
||||
@@ -825,26 +826,26 @@ describe('authenticateDownload', () => {
|
||||
|
||||
it('FILE-SVC-033: a bearer token is used when no cookie is present; invalid JWTs 401', async () => {
|
||||
verifyJwtAndLoadUser.mockReturnValue({ id: 7 });
|
||||
expect(await svc.authenticateDownload(req({ bearer: 'bearer-jwt' }))).toEqual({ userId: 7 });
|
||||
expect(await asLegacyResult(svc.authenticateDownload(req({ bearer: 'bearer-jwt' })))).toEqual({ userId: 7 });
|
||||
expect(verifyJwtAndLoadUser).toHaveBeenCalledWith('bearer-jwt', {}, {}); // see FILE-SVC-032's comment
|
||||
expect(getRepository).toHaveBeenCalledWith(Users);
|
||||
expect(getRepository).toHaveBeenCalledWith(UserSessions);
|
||||
|
||||
verifyJwtAndLoadUser.mockReturnValue(null);
|
||||
expect(await svc.authenticateDownload(req({ bearer: 'stale' }))).toEqual({ error: 'Invalid or expired token', status: 401 });
|
||||
expect(await asLegacyResult(svc.authenticateDownload(req({ bearer: 'stale' })))).toEqual({ error: 'Invalid or expired token', status: 401 });
|
||||
});
|
||||
|
||||
it('FILE-SVC-034: a ?token= ephemeral token is consumed with the download purpose', async () => {
|
||||
consumeEphemeralToken.mockReturnValue(9);
|
||||
expect(await svc.authenticateDownload(req({ token: 'eph' }))).toEqual({ userId: 9 });
|
||||
expect(await asLegacyResult(svc.authenticateDownload(req({ token: 'eph' })))).toEqual({ userId: 9 });
|
||||
expect(consumeEphemeralToken).toHaveBeenCalledWith('eph', 'download');
|
||||
|
||||
consumeEphemeralToken.mockReturnValue(null);
|
||||
expect(await svc.authenticateDownload(req({ token: 'spent' }))).toEqual({ error: 'Invalid or expired token', status: 401 });
|
||||
expect(await asLegacyResult(svc.authenticateDownload(req({ token: 'spent' })))).toEqual({ error: 'Invalid or expired token', status: 401 });
|
||||
});
|
||||
|
||||
it('FILE-SVC-035: no credentials at all is a 401 Authentication required', async () => {
|
||||
expect(await svc.authenticateDownload(req({}))).toEqual({ error: 'Authentication required', status: 401 });
|
||||
expect(await asLegacyResult(svc.authenticateDownload(req({})))).toEqual({ error: 'Authentication required', status: 401 });
|
||||
expect(verifyJwtAndLoadUser).not.toHaveBeenCalled();
|
||||
expect(consumeEphemeralToken).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
const { legacyDatabaseAccess } = vi.hoisted(() => ({
|
||||
@@ -208,7 +209,7 @@ describe('PlacesController (parity with the legacy /api/trips/:tripId/places rou
|
||||
// pins `url`, so the ZodValidationPipe rejects a urlless body before the
|
||||
// handler runs.
|
||||
it('maps a service { error, status } to the same response', async () => {
|
||||
const s = svc({ importGoogleList: vi.fn().mockResolvedValue({ error: 'List is empty', status: 400 }) } as Partial<PlacesService>);
|
||||
const s = svc({ importGoogleList: vi.fn().mockRejectedValue(new DomainError(400, 'List is empty')) } as Partial<PlacesService>);
|
||||
expect(await thrownAsync(() => new PlacesController(s, new RuntimeEnvService(), storageStub).importGoogle(user, '5', { url: 'http://x' }))).toEqual({ status: 400, body: { error: 'List is empty' } });
|
||||
});
|
||||
it('imports a naver list and returns the count + listName', async () => {
|
||||
@@ -579,7 +580,7 @@ describe('PlacesController (parity with the legacy /api/trips/:tripId/places rou
|
||||
it('GET /:id/image maps service error + returns photos', async () => {
|
||||
const s = svc({ searchImage: vi.fn().mockResolvedValue({ photos: [{ url: 'x' }] }) } as Partial<PlacesService>);
|
||||
expect(await new PlacesController(s, new RuntimeEnvService(), storageStub).image(user, '5', '9')).toEqual({ photos: [{ url: 'x' }] });
|
||||
const e = svc({ searchImage: vi.fn().mockResolvedValue({ error: 'No key', status: 400 }) } as Partial<PlacesService>);
|
||||
const e = svc({ searchImage: vi.fn().mockRejectedValue(new DomainError(400, 'No key')) } as Partial<PlacesService>);
|
||||
expect(await thrownAsync(() => new PlacesController(e, new RuntimeEnvService(), storageStub).image(user, '5', '9'))).toEqual({ status: 400, body: { error: 'No key' } });
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* in a unit test. What is under test is the step between the two: which stops the link
|
||||
* yields, which of them get geocoded, and what a partly readable link leaves behind.
|
||||
*/
|
||||
import { asLegacyResult } from '../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../../src/db/database', async () => {
|
||||
@@ -138,7 +139,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
const search = geocoder();
|
||||
const url = 'https://www.google.com/maps/dir/Berlin/Dresden/@51.5,13.5,8z/'
|
||||
+ 'data=!4m14!1m5!1m1!1s0x0:0x0!2m2!1d13.404954!2d52.520008!1m5!1m1!1s0x0:0x0!2m2!1d13.737262!2d51.050409';
|
||||
const result = await (await svc(search)).importGoogleDirections(tripId, url);
|
||||
const result = await asLegacyResult((await svc(search)).importGoogleDirections(tripId, url));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -150,10 +151,10 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
|
||||
it('PLACES-DIR-002: a stop that is only a name is geocoded, and keeps the name from the link', async () => {
|
||||
const search = geocoder();
|
||||
const result = await (await svc(search)).importGoogleDirections(
|
||||
const result = await asLegacyResult((await svc(search)).importGoogleDirections(
|
||||
tripId,
|
||||
'https://www.google.com/maps/dir/Berlin/Dresden/Prague',
|
||||
);
|
||||
));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -163,10 +164,10 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
|
||||
it('PLACES-DIR-003: a stop nobody can place is left out, not made up, and is counted', async () => {
|
||||
const search = geocoder();
|
||||
const result = await (await svc(search)).importGoogleDirections(
|
||||
const result = await asLegacyResult((await svc(search)).importGoogleDirections(
|
||||
tripId,
|
||||
'https://www.google.com/maps/dir/Berlin/Somewhere+Nobody+Knows/Prague',
|
||||
);
|
||||
));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -181,7 +182,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
if (query === 'Dresden') throw new Error('Nominatim 429');
|
||||
return [hit(query, 52.52, 13.405)];
|
||||
}) as unknown as OsmClient['searchNominatim'];
|
||||
const result = await (await svc(search)).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden/Prague');
|
||||
const result = await asLegacyResult((await svc(search)).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden/Prague'));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -193,7 +194,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
createPlace(testDb, Number(tripId), { name: 'Berlin', lat: 52.520008, lng: 13.404954 });
|
||||
const url = 'https://www.google.com/maps/dir/Berlin/Dresden/@51.5,13.5,8z/'
|
||||
+ 'data=!4m14!1m5!1m1!1s0x0:0x0!2m2!1d13.404954!2d52.520008!1m5!1m1!1s0x0:0x0!2m2!1d13.737262!2d51.050409';
|
||||
const result = await (await svc(geocoder())).importGoogleDirections(tripId, url);
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleDirections(tripId, url));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -202,7 +203,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
});
|
||||
|
||||
it('PLACES-DIR-006: a link that is not Google\'s is refused after it is resolved', async () => {
|
||||
const result = await (await svc(geocoder())).importGoogleDirections(tripId, 'https://evil.example.com/maps/dir/Berlin/Dresden');
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleDirections(tripId, 'https://evil.example.com/maps/dir/Berlin/Dresden'));
|
||||
expect(result).toEqual({ error: 'That link is not a Google Maps link.', status: 400 });
|
||||
});
|
||||
|
||||
@@ -210,7 +211,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
safeFetchFollow.mockResolvedValue({
|
||||
url: 'https://www.google.com/maps/dir/Berlin/Dresden',
|
||||
} as unknown as Response);
|
||||
const result = await (await svc(geocoder())).importGoogleDirections(tripId, 'https://maps.app.goo.gl/abc123');
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleDirections(tripId, 'https://maps.app.goo.gl/abc123'));
|
||||
|
||||
expect(safeFetchFollow).toHaveBeenCalledTimes(1);
|
||||
expect('error' in result).toBe(false);
|
||||
@@ -220,12 +221,12 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
|
||||
it('PLACES-DIR-008: a blocked URL never reaches the parser', async () => {
|
||||
checkSsrf.mockResolvedValue({ allowed: false } as never);
|
||||
const result = await (await svc(geocoder())).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden');
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden'));
|
||||
expect(result).toEqual({ error: 'URL is not allowed', status: 400 });
|
||||
});
|
||||
|
||||
it('PLACES-DIR-009: a link with nothing to read says what to do instead', async () => {
|
||||
const result = await (await svc(geocoder())).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin');
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin'));
|
||||
expect(result).toMatchObject({ status: 400 });
|
||||
expect((result as { error: string }).error).toMatch(/Share button/);
|
||||
});
|
||||
@@ -243,7 +244,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
(service as unknown as { maps: Partial<MapsService> }).maps.geocodeQuery =
|
||||
geocode as unknown as MapsService['geocodeQuery'];
|
||||
|
||||
await service.importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden');
|
||||
await asLegacyResult(service.importGoogleDirections(tripId, 'https://www.google.com/maps/dir/Berlin/Dresden'));
|
||||
|
||||
expect(geocode).toHaveBeenCalledWith('Berlin');
|
||||
expect(geocode).toHaveBeenCalledWith('Dresden');
|
||||
@@ -263,7 +264,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
url: 'https://www.google.com/maps/dir/52.52,13.405/51.05,13.74',
|
||||
} as never);
|
||||
|
||||
const result = await (await svc(geocoder())).importGoogleList(tripId, 'https://maps.app.goo.gl/aBcDeF12345');
|
||||
const result = await asLegacyResult((await svc(geocoder())).importGoogleList(tripId, 'https://maps.app.goo.gl/aBcDeF12345'));
|
||||
|
||||
expect('error' in result).toBe(false);
|
||||
if ('error' in result) return;
|
||||
@@ -276,7 +277,7 @@ describe('PlacesService.importGoogleDirections', () => {
|
||||
it('PLACES-DIR-010: a route where only one stop can be placed is not half an import', async () => {
|
||||
const search = vi.fn(async () => []) as unknown as OsmClient['searchNominatim'];
|
||||
const url = 'https://www.google.com/maps/dir/52.52,13.405/Nowhere/Nowhere+Else';
|
||||
const result = await (await svc(search)).importGoogleDirections(tripId, url);
|
||||
const result = await asLegacyResult((await svc(search)).importGoogleDirections(tripId, url));
|
||||
expect(result).toEqual({ error: 'None of the stops in that link could be placed on the map.', status: 400 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* service is constructed directly, no Nest container needed. External fetches
|
||||
* are mocked where needed.
|
||||
*/
|
||||
import { asLegacyResult } from '../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterEach, afterAll } from 'vitest';
|
||||
import type { PlacePhotoCacheService } from '../../../src/nest/place-photos/place-photo-cache.service';
|
||||
import { UnsplashService } from '../../../src/nest/unsplash/unsplash.service';
|
||||
@@ -1073,7 +1074,7 @@ describe('importGoogleList', () => {
|
||||
it('PLACE-SVC-026 — returns error when list ID cannot be extracted from URL', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://example.com/no-id-here') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://example.com/no-id-here')) as any;
|
||||
expect(result.error).toMatch(/Could not extract list ID/);
|
||||
expect(result.status).toBe(400);
|
||||
});
|
||||
@@ -1082,7 +1083,7 @@ describe('importGoogleList', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const url = 'https://www.google.com/maps/place/Eiffel+Tower/@48.8584,2.2945,17z/data=!3m1';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(result.status).toBe(400);
|
||||
expect(result.error).toMatch(/single place/i);
|
||||
});
|
||||
@@ -1092,7 +1093,7 @@ describe('importGoogleList', () => {
|
||||
const trip = createTrip(testDb, user.id);
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: false, text: async () => '', status: 502 }));
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(result.error).toMatch(/Failed to fetch list/);
|
||||
expect(result.status).toBe(502);
|
||||
});
|
||||
@@ -1113,7 +1114,7 @@ describe('importGoogleList', () => {
|
||||
}));
|
||||
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(result.listName).toBe('My Test List');
|
||||
expect(result.places).toHaveLength(2);
|
||||
expect(result.places[0].name).toBe('Paris');
|
||||
@@ -1132,7 +1133,7 @@ describe('importGoogleList', () => {
|
||||
]],
|
||||
];
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, text: async () => 'prefix\n' + JSON.stringify(listPayload) }));
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as { places: { id: number }[] };
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as { places: { id: number }[] };
|
||||
const row = await findRow(orm, Places, { id: result.places[0].id }) as Record<string, unknown>;
|
||||
expect(row).toMatchObject({
|
||||
trip_id: trip.id, name: 'London', description: null, lat: 51.5074, lng: -0.1278,
|
||||
@@ -1182,7 +1183,7 @@ describe('importGoogleList', () => {
|
||||
}));
|
||||
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
|
||||
expect(result.places).toHaveLength(1);
|
||||
expect(result.places[0].google_place_id).toBeNull();
|
||||
@@ -1209,7 +1210,7 @@ describe('importGoogleList', () => {
|
||||
}));
|
||||
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
const row = await findRow(orm, Places, { id: existing.id }) as any;
|
||||
|
||||
expect(result.places).toHaveLength(0);
|
||||
@@ -1247,7 +1248,7 @@ describe('importGoogleList', () => {
|
||||
text: async () => 'prefix\n' + JSON.stringify(listPayload),
|
||||
}));
|
||||
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
const other = await findRow(orm, Places, { id: namesake.id }) as any;
|
||||
|
||||
expect(result.skipped).toBe(1);
|
||||
@@ -1270,7 +1271,7 @@ describe('importGoogleList', () => {
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
|
||||
respond();
|
||||
const first = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const first = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(first.places).toHaveLength(1);
|
||||
|
||||
// What the reporter does: rename it to something they can actually read, and
|
||||
@@ -1278,7 +1279,7 @@ describe('importGoogleList', () => {
|
||||
await updateRows(orm, Places, { id: first.places[0].id }, { name: 'Saturday market', lat: 43.6, lng: -80.6 });
|
||||
|
||||
respond();
|
||||
const second = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const second = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(second.places).toHaveLength(0);
|
||||
expect(second.skipped).toBe(1);
|
||||
expect(({ c: await countRows(orm, Places, { trip: trip.id }) })).toEqual({ c: 1 });
|
||||
@@ -1300,7 +1301,7 @@ describe('importGoogleList', () => {
|
||||
text: async () => 'prefix\n' + JSON.stringify(listPayload),
|
||||
}));
|
||||
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
expect(result.places).toHaveLength(2);
|
||||
expect(result.skipped).toBe(0);
|
||||
});
|
||||
@@ -1316,7 +1317,7 @@ describe('importGoogleList', () => {
|
||||
}));
|
||||
|
||||
const url = 'https://www.google.com/maps/placelists/list/ABC123DEF456';
|
||||
const result = await svc.importGoogleList(String(trip.id), url) as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), url)) as any;
|
||||
expect(result.error).toBeDefined();
|
||||
expect(result.status).toBe(400);
|
||||
});
|
||||
@@ -1332,7 +1333,7 @@ describe('searchImage', () => {
|
||||
it('PLACE-SVC-030 — returns 404 when place does not exist', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const result = await svc.searchImage(String(trip.id), '99999', user.id) as any;
|
||||
const result = await asLegacyResult(svc.searchImage(String(trip.id), '99999', user.id)) as any;
|
||||
expect(result.error).toBeDefined();
|
||||
expect(result.status).toBe(404);
|
||||
});
|
||||
@@ -1341,12 +1342,8 @@ describe('searchImage', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const place = createPlace(testDb, trip.id);
|
||||
const result: Awaited<ReturnType<PlacesService['searchImage']>> = await svc.searchImage(String(trip.id), `${place.id} `, user.id);
|
||||
expect('error' in result).toBe(true);
|
||||
if ('error' in result) {
|
||||
expect(result.error).toBeDefined();
|
||||
expect(result.status).toBe(404);
|
||||
}
|
||||
const result = await asLegacyResult(svc.searchImage(String(trip.id), `${place.id} `, user.id));
|
||||
expect(result).toEqual({ error: 'Place not found', status: 404 });
|
||||
});
|
||||
|
||||
it('PLACE-SVC-031 — searches Unsplash without a stored API key', async () => {
|
||||
@@ -1363,7 +1360,7 @@ describe('searchImage', () => {
|
||||
status: 200,
|
||||
}));
|
||||
|
||||
const result = await svc.searchImage(String(trip.id), String(place.id), user.id) as any;
|
||||
const result = await asLegacyResult(svc.searchImage(String(trip.id), String(place.id), user.id)) as any;
|
||||
expect(result.photos).toHaveLength(1);
|
||||
const [url] = (fetch as any).mock.calls[0];
|
||||
expect(url).toContain('https://unsplash.com/napi/search/photos?');
|
||||
@@ -1384,7 +1381,7 @@ describe('searchImage', () => {
|
||||
status: 200,
|
||||
}));
|
||||
|
||||
const result = await svc.searchImage(String(trip.id), String(place.id), user.id) as any;
|
||||
const result = await asLegacyResult(svc.searchImage(String(trip.id), String(place.id), user.id)) as any;
|
||||
expect(result.photos).toHaveLength(1);
|
||||
expect(result.photos[0].id).toBe('photo1');
|
||||
expect(result.photos[0].url).toBe('https://img.example.com/1');
|
||||
@@ -2083,7 +2080,7 @@ describe('importGoogleList provider payload', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, text: async () => 'prefix\nnot-json-at-all' }));
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
expect(result).toEqual({ error: 'Invalid list data received from Google Maps', status: 400 });
|
||||
});
|
||||
|
||||
@@ -2091,7 +2088,7 @@ describe('importGoogleList provider payload', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, text: async () => 'prefix\n{"unexpected":true}' }));
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
expect(result).toEqual({ error: 'Invalid list data received from Google Maps', status: 400 });
|
||||
});
|
||||
|
||||
@@ -2103,7 +2100,7 @@ describe('importGoogleList provider payload', () => {
|
||||
headers: { get: () => null }, // chunked: the declared check cannot help
|
||||
text: async () => 'x'.repeat(9 * 1024 * 1024),
|
||||
}));
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
expect(result).toEqual({ error: 'Failed to fetch list from Google Maps', status: 502 });
|
||||
});
|
||||
|
||||
@@ -2116,7 +2113,7 @@ describe('importGoogleList provider payload', () => {
|
||||
headers: { get: (h: string) => (h.toLowerCase() === 'content-length' ? String(20 * 1024 * 1024) : null) },
|
||||
text,
|
||||
}));
|
||||
const result = await svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456') as any;
|
||||
const result = await asLegacyResult(svc.importGoogleList(String(trip.id), 'https://www.google.com/maps/placelists/list/ABC123DEF456')) as any;
|
||||
expect(result).toEqual({ error: 'Failed to fetch list from Google Maps', status: 502 });
|
||||
expect(text).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -2140,7 +2137,7 @@ describe('importNaverList provider payload', () => {
|
||||
headers: { get: (h: string) => (h.toLowerCase() === 'content-length' ? String(20 * 1024 * 1024) : null) },
|
||||
text,
|
||||
}));
|
||||
const result = await svc.importNaverList(String(trip.id), FOLDER_URL) as any;
|
||||
const result = await asLegacyResult(svc.importNaverList(String(trip.id), FOLDER_URL)) as any;
|
||||
expect(result).toEqual({ error: 'Failed to fetch list from Naver Maps', status: 502 });
|
||||
expect(text).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -2153,7 +2150,7 @@ describe('importNaverList provider payload', () => {
|
||||
headers: { get: () => null }, // chunked: the declared check cannot help
|
||||
text: async () => 'x'.repeat(9 * 1024 * 1024),
|
||||
}));
|
||||
const result = await svc.importNaverList(String(trip.id), FOLDER_URL) as any;
|
||||
const result = await asLegacyResult(svc.importNaverList(String(trip.id), FOLDER_URL)) as any;
|
||||
expect(result).toEqual({ error: 'Failed to fetch list from Naver Maps', status: 502 });
|
||||
});
|
||||
|
||||
@@ -2161,7 +2158,7 @@ describe('importNaverList provider payload', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, text: async () => 'not-json-at-all' }));
|
||||
const result = await svc.importNaverList(String(trip.id), FOLDER_URL) as any;
|
||||
const result = await asLegacyResult(svc.importNaverList(String(trip.id), FOLDER_URL)) as any;
|
||||
expect(result).toEqual({ error: 'Invalid list data received from Naver Maps', status: 400 });
|
||||
});
|
||||
|
||||
@@ -2175,7 +2172,7 @@ describe('importNaverList provider payload', () => {
|
||||
bookmarkList: [{ name: 'Gyeongbokgung', px: 126.977, py: 37.5796, memo: null, address: 'Sejongno' }],
|
||||
}),
|
||||
}));
|
||||
const result = await svc.importNaverList(String(trip.id), FOLDER_URL) as any;
|
||||
const result = await asLegacyResult(svc.importNaverList(String(trip.id), FOLDER_URL)) as any;
|
||||
expect(result.listName).toBe('Seoul');
|
||||
expect(result.places).toHaveLength(1);
|
||||
expect(result.places[0].name).toBe('Gyeongbokgung');
|
||||
@@ -2194,7 +2191,7 @@ describe('importNaverList provider payload', () => {
|
||||
bookmarkList: [{ name: 'Gyeongbokgung', px: 126.977, py: 37.5796, memo: 'A palace', address: 'Sejongno' }],
|
||||
}),
|
||||
}));
|
||||
const result = await svc.importNaverList(String(trip.id), FOLDER_URL) as { places: { id: number }[] };
|
||||
const result = await asLegacyResult(svc.importNaverList(String(trip.id), FOLDER_URL)) as { places: { id: number }[] };
|
||||
const row = await findRow(orm, Places, { id: result.places[0].id }) as Record<string, unknown>;
|
||||
expect(row).toMatchObject({
|
||||
trip_id: trip.id, name: 'Gyeongbokgung', description: null, lat: 37.5796, lng: 126.977,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import type { UnsplashService } from '../../../src/nest/unsplash/unsplash.service';
|
||||
import { RuntimeEnvService } from '../../../src/nest/app-config/runtime-env.service';
|
||||
@@ -128,14 +129,14 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
|
||||
});
|
||||
|
||||
it('sends an absent query as "" so the service keeps owning the empty-query 400', async () => {
|
||||
const searchCoverImages = vi.fn().mockResolvedValue({ error: 'Search query is required', status: 400 });
|
||||
const searchCoverImages = vi.fn().mockRejectedValue(new DomainError(400, 'Search query is required'));
|
||||
const s = svc({ searchCoverImages } as Partial<TripsService>);
|
||||
expect(await thrownAsync(() => tc(s).coverImages(user, undefined))).toEqual({ status: 400, body: { error: 'Search query is required' } });
|
||||
expect(searchCoverImages).toHaveBeenCalledWith('', 1);
|
||||
});
|
||||
|
||||
it('keeps the upstream status instead of flattening it into the catch-all 500', async () => {
|
||||
const s = svc({ searchCoverImages: vi.fn().mockResolvedValue({ error: 'Rate limit reached', status: 429 }) } as Partial<TripsService>);
|
||||
const s = svc({ searchCoverImages: vi.fn().mockRejectedValue(new DomainError(429, 'Rate limit reached')) } as Partial<TripsService>);
|
||||
// A 429 that arrives as a 500 makes the client retry immediately and burn
|
||||
// the rest of the hourly Unsplash quota.
|
||||
expect(await thrownAsync(() => tc(s).coverImages(user, 'kyoto'))).toEqual({ status: 429, body: { error: 'Rate limit reached' } });
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { asLegacyResult } from '../../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -33,7 +34,8 @@ const coverFx = makeStorageFixture('covers/');
|
||||
const appSettingsStub = { getValue: mockGetValue } as unknown as AppSettingsRepository;
|
||||
const usersStub = { getApiKeyColumn: mockGetApiKeyColumn } as unknown as UsersRepository;
|
||||
const svc = new UnsplashService(appSettingsStub, usersStub, new RuntimeEnvService(), coverFx.storage);
|
||||
const searchUnsplashPhotos = svc.searchUnsplashPhotos.bind(svc);
|
||||
const searchUnsplashPhotos = (...args: Parameters<UnsplashService['searchUnsplashPhotos']>) =>
|
||||
asLegacyResult(svc.searchUnsplashPhotos(...args));
|
||||
const getUnsplashKey = svc.getUnsplashKey.bind(svc);
|
||||
const saveUnsplashCover = svc.saveUnsplashCover.bind(svc);
|
||||
const isUnsplashCoverUrl = svc.isUnsplashCoverUrl.bind(svc);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DomainError } from '../../../src/nest/common/domain-error';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { HttpException } from '@nestjs/common';
|
||||
import { VacayController } from '../../../src/nest/vacay/vacay.controller';
|
||||
@@ -83,7 +84,7 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
|
||||
});
|
||||
|
||||
it('maps a sendInvite error to its status', () => {
|
||||
const sendInvite = vi.fn().mockReturnValue({ error: 'Already in a plan', status: 409 });
|
||||
const sendInvite = vi.fn().mockRejectedValue(new DomainError(409, 'Already in a plan'));
|
||||
return thrown(() => makeController({ ...planBase, sendInvite }).invite(user, { user_id: 2 })).then((r) =>
|
||||
expect(r).toEqual({ status: 409, body: { error: 'Already in a plan' } }));
|
||||
});
|
||||
@@ -95,7 +96,7 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
|
||||
});
|
||||
|
||||
it('maps an acceptInvite error', () => {
|
||||
const acceptInvite = vi.fn().mockReturnValue({ error: 'Invite not found', status: 404 });
|
||||
const acceptInvite = vi.fn().mockRejectedValue(new DomainError(404, 'Invite not found'));
|
||||
return thrown(() => makeController({ acceptInvite }).acceptInvite(user, { plan_id: 5 })).then((r) =>
|
||||
expect(r).toEqual({ status: 404, body: { error: 'Invite not found' } }));
|
||||
});
|
||||
@@ -195,7 +196,7 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
|
||||
|
||||
describe('public holidays', () => {
|
||||
it('502 when the upstream country lookup fails', () => {
|
||||
const getCountries = vi.fn().mockResolvedValue({ error: 'upstream down' });
|
||||
const getCountries = vi.fn().mockRejectedValue(new DomainError(502, 'upstream down'));
|
||||
return thrown(() => makeController({ getCountries }).holidayCountries()).then((r) =>
|
||||
expect(r).toEqual({ status: 502, body: { error: 'upstream down' } }));
|
||||
});
|
||||
@@ -206,7 +207,7 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
|
||||
});
|
||||
|
||||
it('502 when the holidays lookup fails', () => {
|
||||
const getHolidays = vi.fn().mockResolvedValue({ error: 'upstream down' });
|
||||
const getHolidays = vi.fn().mockRejectedValue(new DomainError(502, 'upstream down'));
|
||||
return thrown(() => makeController({ getHolidays }).holidays('2026', 'DE')).then((r) =>
|
||||
expect(r).toEqual({ status: 502, body: { error: 'upstream down' } }));
|
||||
});
|
||||
@@ -225,7 +226,7 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
|
||||
});
|
||||
|
||||
it('maps a shareCalendar error to its status', () => {
|
||||
const shareCalendar = vi.fn().mockReturnValue({ error: 'Already shared', status: 400 });
|
||||
const shareCalendar = vi.fn().mockRejectedValue(new DomainError(400, 'Already shared'));
|
||||
return thrown(() => makeController({ shareCalendar }).share(user, { user_id: 2 })).then((r) =>
|
||||
expect(r).toEqual({ status: 400, body: { error: 'Already shared' } }));
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { asLegacyResult } from '../../helpers/domain-error';
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||
|
||||
// ── DB setup (real in-memory SQLite) ─────────────────────────────────────────
|
||||
@@ -902,7 +903,7 @@ describe('acceptInvite', () => {
|
||||
await svc.getOwnPlan(invitee.id); // ensure own plan exists for data migration path
|
||||
await insertMember(ownerPlan.id, invitee.id, 'pending');
|
||||
|
||||
const result = await svc.acceptInvite(invitee.id, ownerPlan.id, undefined);
|
||||
const result = await asLegacyResult(svc.acceptInvite(invitee.id, ownerPlan.id, undefined));
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
const row = await storedFields(VacayPlanMembers, { plan: ownerPlan.id, user: invitee.id }, ['status']) as { status: string } | undefined;
|
||||
@@ -912,7 +913,7 @@ describe('acceptInvite', () => {
|
||||
it('VACAY-SVC-038: returns 404 error when there is no pending invite', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
|
||||
const result = await svc.acceptInvite(user.id, 99999, undefined);
|
||||
const result = await asLegacyResult(svc.acceptInvite(user.id, 99999, undefined));
|
||||
|
||||
expect(result.status).toBe(404);
|
||||
expect(result.error).toBeDefined();
|
||||
@@ -924,7 +925,7 @@ describe('acceptInvite', () => {
|
||||
await svc.getOwnPlan(invitee.id);
|
||||
await insertMember(ownerPlan.id, invitee.id, 'pending');
|
||||
|
||||
await svc.acceptInvite(invitee.id, ownerPlan.id, undefined);
|
||||
await asLegacyResult(svc.acceptInvite(invitee.id, ownerPlan.id, undefined));
|
||||
|
||||
const active = await svc.getActivePlan(invitee.id);
|
||||
expect(active.id).toBe(ownerPlan.id);
|
||||
@@ -1013,9 +1014,9 @@ describe('getAvailableUsers', () => {
|
||||
|
||||
// The picker is only a list. The id comes back from the client, and the MCP
|
||||
// tools reach the same two methods, so refusing has to happen here.
|
||||
const invited = await svc.sendInvite(plan.id, owner.id, 'owner', 'owner@example.test', guest.id);
|
||||
const invited = await asLegacyResult(svc.sendInvite(plan.id, owner.id, 'owner', 'owner@example.test', guest.id));
|
||||
expect(invited.error).toBe('User not found');
|
||||
const shared = await svc.shareCalendar(owner.id, 'owner@example.test', guest.id);
|
||||
const shared = await asLegacyResult(svc.shareCalendar(owner.id, 'owner@example.test', guest.id));
|
||||
expect(shared.error).toBe('User not found');
|
||||
});
|
||||
});
|
||||
@@ -1463,7 +1464,7 @@ describe('shareCalendar', () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: target } = createUser(testDb);
|
||||
|
||||
const result = await svc.shareCalendar(owner.id, owner.email, target.id);
|
||||
const result = await asLegacyResult(svc.shareCalendar(owner.id, owner.email, target.id));
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
const row = await storedRow(VacayShares, { owner: owner.id, user: target.id });
|
||||
@@ -1473,7 +1474,7 @@ describe('shareCalendar', () => {
|
||||
it('VACAY-SVC-049: returns 400 when sharing with yourself', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
|
||||
const result = await svc.shareCalendar(owner.id, owner.email, owner.id);
|
||||
const result = await asLegacyResult(svc.shareCalendar(owner.id, owner.email, owner.id));
|
||||
|
||||
expect(result).toEqual({ error: 'Cannot share with yourself', status: 400 });
|
||||
});
|
||||
@@ -1481,7 +1482,7 @@ describe('shareCalendar', () => {
|
||||
it('VACAY-SVC-050: returns 404 when the target user does not exist', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
|
||||
const result = await svc.shareCalendar(owner.id, owner.email, 99999);
|
||||
const result = await asLegacyResult(svc.shareCalendar(owner.id, owner.email, 99999));
|
||||
|
||||
expect(result).toEqual({ error: 'User not found', status: 404 });
|
||||
});
|
||||
@@ -1489,9 +1490,9 @@ describe('shareCalendar', () => {
|
||||
it('VACAY-SVC-051: returns 400 when the share already exists', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: target } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, target.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, target.id));
|
||||
|
||||
const result = await svc.shareCalendar(owner.id, owner.email, target.id);
|
||||
const result = await asLegacyResult(svc.shareCalendar(owner.id, owner.email, target.id));
|
||||
|
||||
expect(result).toEqual({ error: 'Already shared', status: 400 });
|
||||
});
|
||||
@@ -1501,7 +1502,7 @@ describe('shareCalendar', () => {
|
||||
const { user: member } = createUser(testDb);
|
||||
await insertMember(plan.id, member.id, 'accepted');
|
||||
|
||||
const result = await svc.shareCalendar(owner.id, owner.email, member.id);
|
||||
const result = await asLegacyResult(svc.shareCalendar(owner.id, owner.email, member.id));
|
||||
|
||||
expect(result).toEqual({ error: 'User is already in your calendar', status: 400 });
|
||||
});
|
||||
@@ -1511,7 +1512,7 @@ describe('listShares', () => {
|
||||
it('VACAY-SVC-053: outgoing rows carry the target user info', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: target } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, target.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, target.id));
|
||||
|
||||
const result = await svc.listShares(owner.id);
|
||||
|
||||
@@ -1528,7 +1529,7 @@ describe('listShares', () => {
|
||||
const { user: owner, plan } = await setupUserWithPlan();
|
||||
await svc.setUserColor(owner.id, plan.id, '#ef4444', undefined);
|
||||
const { user: viewer } = await setupUserWithPlan();
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
|
||||
const result = await svc.listShares(viewer.id);
|
||||
|
||||
@@ -1547,8 +1548,8 @@ describe('listShares', () => {
|
||||
const { user: viewer } = await setupUserWithPlan(); // viewer's own color is #6366f1
|
||||
const { user: owner1 } = await setupUserWithPlan(); // default #6366f1
|
||||
const { user: owner2 } = await setupUserWithPlan(); // default #6366f1
|
||||
await svc.shareCalendar(owner1.id, owner1.email, viewer.id);
|
||||
await svc.shareCalendar(owner2.id, owner2.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner1.id, owner1.email, viewer.id));
|
||||
await asLegacyResult(svc.shareCalendar(owner2.id, owner2.email, viewer.id));
|
||||
|
||||
const { incoming } = await svc.listShares(viewer.id);
|
||||
|
||||
@@ -1564,7 +1565,7 @@ describe('removeShare', () => {
|
||||
it('VACAY-SVC-056: the owner can revoke their share', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
const shareId = (await svc.listShares(owner.id)).outgoing[0].id as number;
|
||||
|
||||
expect(await svc.removeShare(shareId, owner.id)).toBe(true);
|
||||
@@ -1575,7 +1576,7 @@ describe('removeShare', () => {
|
||||
it('VACAY-SVC-057: the recipient can remove a share they received', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
const shareId = (await svc.listShares(viewer.id)).incoming[0].id;
|
||||
|
||||
expect(await svc.removeShare(shareId, viewer.id)).toBe(true);
|
||||
@@ -1585,7 +1586,7 @@ describe('removeShare', () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: viewer } = createUser(testDb);
|
||||
const { user: stranger } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
const shareId = (await svc.listShares(owner.id)).outgoing[0].id as number;
|
||||
|
||||
expect(await svc.removeShare(shareId, stranger.id)).toBe(false);
|
||||
@@ -1600,7 +1601,7 @@ describe('setShareHidden', () => {
|
||||
it('VACAY-SVC-059: the recipient can hide and unhide the shared calendar', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
const shareId = (await svc.listShares(viewer.id)).incoming[0].id;
|
||||
|
||||
expect(await svc.setShareHidden(shareId, viewer.id, true)).toBe(true);
|
||||
@@ -1616,7 +1617,7 @@ describe('setShareHidden', () => {
|
||||
it('VACAY-SVC-060: the owner cannot toggle the recipient hidden flag', async () => {
|
||||
const { user: owner } = await setupUserWithPlan();
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
const shareId = (await svc.listShares(owner.id)).outgoing[0].id as number;
|
||||
|
||||
expect(await svc.setShareHidden(shareId, owner.id, true)).toBe(false);
|
||||
@@ -1631,7 +1632,7 @@ describe('getShareAvailableUsers', () => {
|
||||
const { user: member } = createUser(testDb);
|
||||
await insertMember(plan.id, member.id, 'accepted');
|
||||
const { user: shared } = createUser(testDb);
|
||||
await svc.shareCalendar(owner.id, owner.email, shared.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, shared.id));
|
||||
const { user: unrelated } = createUser(testDb);
|
||||
|
||||
const ids = (await svc.getShareAvailableUsers(owner.id) as { id: number }[]).map(u => u.id);
|
||||
@@ -1652,7 +1653,7 @@ describe('getSharedCalendars', () => {
|
||||
await svc.toggleEntry(owner.id, plan.id, '2025-06-10', 1);
|
||||
await svc.toggleEntry(owner.id, plan.id, '2025-06-11', 0.5);
|
||||
await svc.toggleEntry(member.id, plan.id, '2025-06-12', 1);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
|
||||
const calendars = await svc.getSharedCalendars(viewer.id, '2025');
|
||||
|
||||
@@ -1671,7 +1672,7 @@ describe('getSharedCalendars', () => {
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await updateRows(await orm(), VacayPlans, { id: plan.id }, { company_holidays_enabled: 0 });
|
||||
await svc.toggleCompanyHoliday(plan.id, '2025-12-24', 'Christmas Eve', undefined);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
|
||||
const calendars = await svc.getSharedCalendars(viewer.id, '2025');
|
||||
|
||||
@@ -1683,7 +1684,7 @@ describe('getSharedCalendars', () => {
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await updateRows(await orm(), VacayPlans, { id: plan.id }, { company_holidays_enabled: 1 });
|
||||
await svc.toggleCompanyHoliday(plan.id, '2025-12-24', 'Christmas Eve', undefined);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
|
||||
const calendars = await svc.getSharedCalendars(viewer.id, '2025');
|
||||
|
||||
@@ -1711,7 +1712,7 @@ describe('getSharedCalendars', () => {
|
||||
await insertMember(hostPlan.id, owner.id, 'accepted');
|
||||
const { user: viewer } = createUser(testDb);
|
||||
await svc.toggleEntry(owner.id, hostPlan.id, '2025-03-03', 1);
|
||||
await svc.shareCalendar(owner.id, owner.email, viewer.id);
|
||||
await asLegacyResult(svc.shareCalendar(owner.id, owner.email, viewer.id));
|
||||
|
||||
const calendars = await svc.getSharedCalendars(viewer.id, '2025');
|
||||
|
||||
@@ -1812,9 +1813,9 @@ describe('quirk fixes', () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const fresh = await freshVacayService();
|
||||
|
||||
expect(await fresh.getCountries()).toEqual({ error: 'Failed to fetch countries' });
|
||||
expect(await asLegacyResult(fresh.getCountries())).toEqual({ error: 'Failed to fetch countries', status: 502 });
|
||||
// Nothing cached: a retry hits the network again.
|
||||
expect(await fresh.getCountries()).toEqual({ error: 'Failed to fetch countries' });
|
||||
expect(await asLegacyResult(fresh.getCountries())).toEqual({ error: 'Failed to fetch countries', status: 502 });
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
expect(fetchMock).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
@@ -1825,7 +1826,7 @@ describe('quirk fixes', () => {
|
||||
const fresh = await freshVacayService();
|
||||
|
||||
for (const [year, country] of [['../../..', 'DE'], ['2026', 'DE/../../x'], ['20xx', 'DE'], ['2026', 'DEU']]) {
|
||||
expect(await fresh.getHolidays(year, country)).toEqual({ error: 'Failed to fetch holidays' });
|
||||
expect(await asLegacyResult(fresh.getHolidays(year, country))).toEqual({ error: 'Failed to fetch holidays', status: 502 });
|
||||
}
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -1835,8 +1836,9 @@ describe('quirk fixes', () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const fresh = await freshVacayService();
|
||||
|
||||
expect(await fresh.getSchoolHolidayRegions('DE&countryIsoCode=FR')).toEqual({
|
||||
expect(await asLegacyResult(fresh.getSchoolHolidayRegions('DE&countryIsoCode=FR'))).toEqual({
|
||||
error: 'Failed to fetch school holiday regions',
|
||||
status: 502,
|
||||
});
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -1850,8 +1852,8 @@ describe('quirk fixes', () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const fresh = await freshVacayService();
|
||||
|
||||
expect(await fresh.getCountries()).toEqual({ error: 'Failed to fetch countries' });
|
||||
expect(await fresh.getHolidays('2026', 'DE')).toEqual({ error: 'Failed to fetch holidays' });
|
||||
expect(await asLegacyResult(fresh.getCountries())).toEqual({ error: 'Failed to fetch countries', status: 502 });
|
||||
expect(await asLegacyResult(fresh.getHolidays('2026', 'DE'))).toEqual({ error: 'Failed to fetch holidays', status: 502 });
|
||||
});
|
||||
|
||||
it('VACAY-SVC-070d: a chunked provider body past the cap reads as the usual fetch error', async () => {
|
||||
@@ -1876,8 +1878,8 @@ describe('quirk fixes', () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const fresh = await freshVacayService();
|
||||
|
||||
expect(await fresh.getHolidays('2026', 'DE')).toEqual({ error: 'Failed to fetch holidays' });
|
||||
expect(await fresh.getCountries()).toEqual({ error: 'Failed to fetch countries' });
|
||||
expect(await asLegacyResult(fresh.getHolidays('2026', 'DE'))).toEqual({ error: 'Failed to fetch holidays', status: 502 });
|
||||
expect(await asLegacyResult(fresh.getCountries())).toEqual({ error: 'Failed to fetch countries', status: 502 });
|
||||
});
|
||||
|
||||
it('VACAY-SVC-071: applyHolidayCalendars honors the cache TTL', async () => {
|
||||
|
||||
Reference in New Issue
Block a user