Files
TREK/server/tests/unit/nest/wallet-pass/wallet-pass.controller.test.ts
T
Maurice d41a4f0827 feat(server): name the event in a push and offer a booking as a Google Wallet pass
The push payload carries the event it reports, so the Android app can file a
notification under a channel of its own (chat, trip updates, invitations).
A browser and the iOS extension ignore the field.

GET /api/trips/:tripId/reservations/:id/wallet-pass/google sends the same
request the Apple Wallet signer takes to the TREK services' Google route and
answers with the signed save-to-wallet link the Android app opens. Off with the
other TREK services, and a clear 404 while liketrek has no Wallet issuer yet.
2026-11-07 14:11:58 +01:00

66 lines
2.5 KiB
TypeScript

import { DomainError } from '../../../../src/nest/common/domain-error';
import { WalletPassController } from '../../../../src/nest/wallet-pass/wallet-pass.controller';
import type { User } from '../../../../src/types';
import { describe, expect, it, vi } from 'vitest';
function response() {
const res = {
headers: {} as Record<string, string>,
statusCode: 0,
contentType: '',
body: undefined as unknown,
set: vi.fn((name: string, value: string) => {
res.headers[name] = value;
return res;
}),
status: vi.fn((code: number) => {
res.statusCode = code;
return res;
}),
type: vi.fn((t: string) => {
res.contentType = t;
return res;
}),
send: vi.fn((body: unknown) => {
res.body = body;
return res;
}),
};
return res;
}
const user = { id: 5 } as User;
describe('WalletPassController', () => {
it('WALLET-C-001: answers the pass as a download that is never cached, in the asked language', async () => {
const passFor = vi.fn(async () => ({ bytes: Buffer.from('PK\u0003\u0004'), filename: 'LH-716.pkpass' }));
const controller = new WalletPassController({ passFor } as never);
const res = response();
await controller.pass(user, 42, 7, 'ja', res as never);
expect(passFor).toHaveBeenCalledWith(5, 42, 7, 'ja');
expect(res.statusCode).toBe(200);
expect(res.contentType).toBe('application/vnd.apple.pkpass');
expect(res.headers['Content-Disposition']).toBe('attachment; filename="LH-716.pkpass"');
expect(res.headers['Cache-Control']).toBe('no-store');
});
it('WALLET-C-002: an unknown language falls back to English; a refusal is passed on', async () => {
const passFor = vi.fn(async () => {
throw new DomainError(422, 'A booking needs a date for a Wallet pass');
});
const controller = new WalletPassController({ passFor } as never);
await expect(controller.pass(user, 42, 7, 'klingon', response() as never)).rejects.toBeInstanceOf(DomainError);
expect(passFor).toHaveBeenCalledWith(5, 42, 7, 'en');
});
it('WALLET-C-003: Google Wallet answers the save link as JSON, in the asked language', async () => {
const googleSaveUrlFor = vi.fn(async () => 'https://pay.google.com/gp/v/save/abc');
const controller = new WalletPassController({ googleSaveUrlFor } as never);
await expect(controller.google(user, 42, 7, 'fr')).resolves.toEqual({
saveUrl: 'https://pay.google.com/gp/v/save/abc',
});
expect(googleSaveUrlFor).toHaveBeenCalledWith(5, 42, 7, 'fr');
});
});