fix(wallet): offer Google Wallet only where it works, and never post it to the Apple route

- 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.
This commit is contained in:
Maurice
2026-11-07 14:50:17 +01:00
parent 924836be31
commit 99a8701bd4
8 changed files with 185 additions and 9 deletions
@@ -62,4 +62,10 @@ describe('WalletPassController', () => {
});
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 });
});
});
@@ -3,7 +3,12 @@ import { DomainError } from '../../../../src/nest/common/domain-error';
import { RateLimitService } from '../../../../src/nest/common/rate-limit.service';
import { ReservationsReadService } from '../../../../src/nest/reservations/reservations-read.service';
import { WalletPassModule } from '../../../../src/nest/wallet-pass/wallet-pass.module';
import { filenameOf, parseMetadata, WalletPassService } from '../../../../src/nest/wallet-pass/wallet-pass.service';
import {
filenameOf,
googleSignerUrl,
parseMetadata,
WalletPassService,
} from '../../../../src/nest/wallet-pass/wallet-pass.service';
import { loadWalletWords, walletLanguage } from '../../../../src/nest/wallet-pass/wallet-pass.words';
import { createSnapshotTestDb } from '../../../helpers/db-mock';
import { createTestModule, type TestModule } from '../../../helpers/test-module';
@@ -219,4 +224,48 @@ describe('WalletPassService', () => {
reservations.getReservationWithJoins.mockResolvedValueOnce({ ...ROW, trip_id: 99 });
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(404);
});
it('WALLET-S-010: the Google route sits beside /pass, query kept; any other signer URL has none', async () => {
expect(googleSignerUrl('https://push.liketrek.com/v1/wallet/pass')).toBe(
'https://push.liketrek.com/v1/wallet/google',
);
expect(googleSignerUrl('https://signer.example/v1/wallet/pass/?key=x')).toBe(
'https://signer.example/v1/wallet/google?key=x',
);
expect(googleSignerUrl('https://signer.example/v1/sign')).toBeNull();
expect(googleSignerUrl('not a url')).toBeNull();
make();
config.walletPassUrl = 'https://signer.example/v1/sign';
try {
expect(await refusal(service.googleSaveUrlFor(1, 42, 7, 'en'))).toBe(404);
expect(safeFetchAdminConfigured).not.toHaveBeenCalled();
} finally {
config.walletPassUrl = 'https://push.liketrek.com/v1/wallet/pass';
}
});
it('WALLET-S-011: Google Wallet counts as available once the signer has the route, asked once in ten minutes', async () => {
const probe = (s: number) => safeFetchAdminConfigured.mockResolvedValueOnce(new Response('', { status: s }));
const fresh = () => ((service as unknown as { googleProbe: unknown }).googleProbe = null);
make('off');
fresh();
expect(await service.googleAvailable()).toBe(false);
expect(safeFetchAdminConfigured).not.toHaveBeenCalled();
make();
fresh();
probe(404);
expect(await service.googleAvailable()).toBe(false);
expect(await service.googleAvailable()).toBe(false);
expect(safeFetchAdminConfigured).toHaveBeenCalledTimes(1);
expect((safeFetchAdminConfigured.mock.calls[0] as [string, RequestInit])[0]).toBe(
'https://push.liketrek.com/v1/wallet/google',
);
fresh();
probe(405);
expect(await service.googleAvailable()).toBe(true);
fresh();
safeFetchAdminConfigured.mockRejectedValueOnce(new Error('ECONNREFUSED'));
expect(await service.googleAvailable()).toBe(false);
fresh();
});
});