mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
99a8701bd4
- GET /api/trips/:tripId/reservations/google-wallet answers whether this server can make Google Wallet passes: passes on, and the TREK services' signer with its Google route mounted (it is once liketrek has a Wallet issuer). The probe is kept for ten minutes. - The Google route is derived from TREK_WALLET_SIGNER_URL by its path, the query kept; a signer URL that does not end in /pass has none, and the booking is refused with a 404 instead of going to the Apple signer. - End-to-end tests for the save link: owner, stranger, another trip, no issuer yet, a link that is not Google Wallet, and the availability. - Italian and Hungarian wording of the button.
72 lines
2.8 KiB
TypeScript
72 lines
2.8 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');
|
|
});
|
|
|
|
it('WALLET-C-004: says whether Google Wallet works on this server', async () => {
|
|
const googleAvailable = vi.fn(async () => false);
|
|
const controller = new WalletPassController({ googleAvailable } as never);
|
|
await expect(controller.googleAvailability()).resolves.toEqual({ available: false });
|
|
});
|
|
});
|