fix(native): location at the accuracy asked for, and a Play payment that clears later is redeemed

- The location shim runs at high accuracy only while a watcher wants it and
  drops back once that watcher is gone, instead of keeping the 2 s GPS rate
  for the rest of the session.
- The purchase client can hand over a Play subscription that was paid but
  never delivered (a pending payment that cleared later), and the plans screen
  redeems it at once, as a restore would, before Google Play refunds it after
  three days.
This commit is contained in:
Maurice
2026-11-07 14:57:50 +01:00
parent c1c71a12cf
commit 46f4cab1b7
6 changed files with 120 additions and 7 deletions
+38
View File
@@ -7,6 +7,8 @@ const shell = vi.hoisted(() => ({
storePurchase: vi.fn(),
storeFinish: vi.fn(),
storeRestore: vi.fn(),
storeUnfinished: vi.fn(),
addListener: vi.fn(),
}));
vi.mock('./platform', () => ({ isNativeIos: () => platform.ios, isNativeAndroid: () => platform.android }));
@@ -175,4 +177,40 @@ describe('native client on Android (Google Play Billing)', () => {
await nativeIapClient.finish(purchase!);
expect(shell.storeFinish).toHaveBeenCalledWith({ transactionId: 'token-2' });
});
it('hands a payment that cleared later over to the shell, and tells it when one clears', async () => {
shell.storeUnfinished.mockResolvedValue({
purchaseToken: 'late',
transactionId: 'late',
productId: 'cloud.plus.monthly',
});
expect(await nativeIapClient.unfinished()).toEqual({
platform: 'google',
productId: 'cloud.plus.monthly',
receipt: 'late',
transactionId: 'late',
});
expect(shell.storeUnfinished).toHaveBeenCalledWith({ prefix: 'cloud.' });
shell.storeUnfinished.mockResolvedValue({});
expect(await nativeIapClient.unfinished()).toBeNull();
shell.storeUnfinished.mockRejectedValue({ code: 'UNIMPLEMENTED' });
expect(await nativeIapClient.unfinished()).toBeNull();
shell.addListener.mockResolvedValue({ remove: vi.fn() });
const listener = vi.fn();
nativeIapClient.onTransaction(listener);
const [event, handler] = shell.addListener.mock.calls[0] as [string, () => void];
expect(event).toBe('storeTransaction');
handler();
expect(listener).toHaveBeenCalledTimes(1);
});
it('on iOS leaves an interrupted purchase to the restore, as StoreKit does', async () => {
platform.ios = true;
platform.android = false;
expect(await nativeIapClient.unfinished()).toBeNull();
nativeIapClient.onTransaction(vi.fn());
expect(shell.storeUnfinished).not.toHaveBeenCalled();
expect(shell.addListener).not.toHaveBeenCalled();
});
});