mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
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.
This commit is contained in:
@@ -188,6 +188,7 @@ describe('WebPushService delivery', () => {
|
||||
body: MSG.body,
|
||||
url: '/trips/12',
|
||||
tag: 'collab_message:/trips/12',
|
||||
event: 'collab_message',
|
||||
});
|
||||
|
||||
const [row] = await rows(user.id);
|
||||
@@ -477,11 +478,13 @@ describe('buildPushPayload', () => {
|
||||
body: MSG.body,
|
||||
url: '/trips/12',
|
||||
tag: 'collab_message:/trips/12',
|
||||
event: 'collab_message',
|
||||
});
|
||||
// Without a trip to collapse on there is no tag at all, never one for every chat everywhere.
|
||||
expect(buildPushPayload({ ...MSG, navigateTarget: undefined })).toEqual({
|
||||
title: MSG.title,
|
||||
body: MSG.body,
|
||||
event: 'collab_message',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -490,7 +493,7 @@ describe('buildPushPayload', () => {
|
||||
expect(others.length).toBeGreaterThan(5);
|
||||
for (const event of others) {
|
||||
const payload = buildPushPayload({ ...MSG, event });
|
||||
expect(payload, event).toEqual({ title: MSG.title, body: MSG.body, url: '/trips/12' });
|
||||
expect(payload, event).toEqual({ title: MSG.title, body: MSG.body, url: '/trips/12', event });
|
||||
expect(payload, event).not.toHaveProperty('tag');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,4 +53,13 @@ describe('WalletPassController', () => {
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -189,4 +189,34 @@ describe('WalletPassService', () => {
|
||||
expect(words.seat).toBe('Sitzplatz');
|
||||
expect((await loadWalletWords('xx')).seat).toBe('Seat');
|
||||
});
|
||||
|
||||
it('WALLET-S-008: Google Wallet gets the same request at the Google route of the signer and answers its save link', async () => {
|
||||
make();
|
||||
const saveUrl = 'https://pay.google.com/gp/v/save/eyJhbGciOi.payload.sig';
|
||||
signerAnswers(200, JSON.stringify({ saveUrl }), 'application/json');
|
||||
await expect(service.googleSaveUrlFor(1, 42, 7, 'de')).resolves.toBe(saveUrl);
|
||||
const [url, init] = safeFetchAdminConfigured.mock.calls[0] as [string, RequestInit];
|
||||
expect(url).toBe('https://push.liketrek.com/v1/wallet/google');
|
||||
const body = JSON.parse(String(init.body));
|
||||
expect(body.kind).toBe('hotel');
|
||||
expect(body.title).toBe('Hotel Granvia Kyoto');
|
||||
});
|
||||
|
||||
it('WALLET-S-009: Google Wallet refusals: off, not set up yet, busy, or a link that is not from Google', async () => {
|
||||
make('off');
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(404);
|
||||
make();
|
||||
signerAnswers(404, 'not found', 'text/plain');
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(404);
|
||||
signerAnswers(429, 'slow down', 'text/plain');
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(429);
|
||||
signerAnswers(200, JSON.stringify({ saveUrl: 'https://evil.example/save' }), 'application/json');
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(502);
|
||||
signerAnswers(200, 'not json', 'application/json');
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(502);
|
||||
safeFetchAdminConfigured.mockRejectedValueOnce(new Error('ECONNREFUSED'));
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(502);
|
||||
reservations.getReservationWithJoins.mockResolvedValueOnce({ ...ROW, trip_id: 99 });
|
||||
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user