mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
37a4e84360
"Add to Apple Wallet" on a booking in the iOS app turns it into a TREK pass: a boarding pass from and to for flights, trains, buses and boats, check-in and check-out for a stay, pickup and drop-off for a car, the time for anything else, with the confirmation code as a QR code. Wallet brings it up on the lock screen around its time and place: times carry the offset of the endpoint's zone (looked up from the coordinates where the endpoint has none), stays and restaurants their place's coordinates. The labels come from the booking forms' own strings, so nothing new to translate on the pass. Only liketrek holds the Pass Type ID certificate, so the server sends the pass's texts to the TREK services' signer (TREK_WALLET_PASS_URL, push.liketrek.com) once per tap; it stores nothing, and TREK_SERVICES=off turns it off with the other services. Texts are cleaned of links and shortened here, the answer must be a .pkpass within 512 KB, and a user gets 20 passes a minute. - New wallet-pass domain: GET /api/trips/:tripId/reservations/:id/wallet-pass behind the trip guard, the booking checked to belong to the trip; trip title and place come from the reservations domain (findPassContext) - MWalletButton in the transport and booking sheets, only where the app binary has the wallet feature; undated bookings and failures are told apart - TREK_WALLET_PASS_URL in .env.example, compose, Helm and the wiki
57 lines
2.0 KiB
TypeScript
57 lines
2.0 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');
|
|
});
|
|
});
|