Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,50 @@ describe("makeRelayDeviceRegistrationRequest", () => {
}).pipe(Effect.provide(layerRelayTest));
});

it.effect(
"keeps notifications enabled when permission is granted but the push token is missing",
() => {
vi.mocked(loadPreferences).mockResolvedValue({ liveActivitiesEnabled: true });
vi.spyOn(Platform, "OS", "get").mockReturnValue("ios");
vi.spyOn(Platform, "Version", "get").mockReturnValue(18);
vi.mocked(Notifications.getPermissionsAsync).mockResolvedValue({
granted: true,
} as Awaited<ReturnType<typeof Notifications.getPermissionsAsync>>);
vi.mocked(Notifications.getDevicePushTokenAsync).mockRejectedValue(new Error("no token yet"));
const registrations: unknown[] = [];
vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => {
const request = new Request(input, init);
if (request.url.endsWith("/v1/client/dpop-token")) {
return Response.json({
access_token: "dpop",
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
token_type: "DPoP",
expires_in: 300,
scope: "mobile:registration",
});
}
registrations.push(await request.json());
return Response.json({ ok: true });
});
Constants.expoConfig!.extra = { relay: { url: "https://missing-token-relay.example.test" } };
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk"), "user-a");
return Effect.gen(function* () {
yield* runBackgroundOperations();
expect(registrations.at(-1)).toMatchObject({
preferences: { notificationsEnabled: true, liveActivitiesEnabled: true },
});
expect(registrations.at(-1)).not.toHaveProperty("pushToken");
}).pipe(
Effect.provideService(FetchHttpClient.Fetch, globalThis.fetch),
Effect.provide(
ManagedRelayLayer.layer("https://missing-token-relay.example.test").pipe(
Layer.provide(Layer.mergeAll(FetchHttpClient.layer, Dpop.layer)),
),
),
);
},
);

it.effect.each(["ios", "android"] as const)(
"does not enable %s notifications when a token rotates after permission is revoked",
(os) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ const nativePushTokenRegistration = Effect.fn("remoteRegistration.nativePushToke
token?.type === Platform.OS && typeof token.data === "string" && token.data.trim().length > 0
? token.data.trim()
: null;
// Permission/channel state gates alerts. A missing token must not publish
// notificationsEnabled:false or Live Activity jobs strip their banners while
// Settings still shows Device Notifications on.
return {
notificationsEnabled: alertsEnabled && pushToken !== null,
notificationsEnabled: alertsEnabled,
pushToken,
notificationPermissionGranted: permissions.granted,
};
Expand Down
Loading
Loading