| ... | ... | @@ -924,4 +924,47 @@ describe("makeRelayDeviceRegistrationRequest", () => { |
| 924 | 924 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 925 | 925 | expect(widgetMocks.start).toHaveBeenCalledTimes(1); |
| 926 | 926 | }); |
| 927 | it.effect( |
| 928 | "does not enable notifications when a token rotates after permission is revoked", |
| 929 | () => { |
| 930 | const registrations: unknown[] = []; |
| 931 | vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => { |
| 932 | const request = new Request(input, init); |
| 933 | if (request.url.endsWith("/v1/client/dpop-token")) { |
| 934 | return Response.json({ |
| 935 | access_token: "dpop", |
| 936 | issued_token_type: "urn:ietf:params:oauth:token-type:access_token", |
| 937 | token_type: "DPoP", |
| 938 | expires_in: 300, |
| 939 | scope: "mobile:registration", |
| 940 | }); |
| 941 | } |
| 942 | registrations.push(await request.json()); |
| 943 | return Response.json({ ok: true }); |
| 944 | }); |
| 945 | Constants.expoConfig!.extra = { relay: { url: "https://permission-relay.example.test" } }; |
| 946 | setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk"), "user-a"); |
| 947 | return Effect.gen(function* () { |
| 948 | yield* runBackgroundOperations(); |
| 949 | expect(registrations.at(-1)).toMatchObject({ preferences: { notificationsEnabled: true } }); |
| 950 | vi.mocked(Notifications.getPermissionsAsync).mockResolvedValueOnce({ |
| 951 | granted: false, |
| 952 | } as Awaited<ReturnType<typeof Notifications.getPermissionsAsync>>); |
| 953 | const listener = vi.mocked(Notifications.addPushTokenListener).mock.calls.at(-1)![0]; |
| 954 | listener({ type: "ios", data: "rotated" }); |
| 955 | yield* runBackgroundOperations(); |
| 956 | expect(registrations.at(-1)).toMatchObject({ |
| 957 | preferences: { notificationsEnabled: false }, |
| 958 | }); |
| 959 | expect(registrations.at(-1)).not.toHaveProperty("pushToken"); |
| 960 | }).pipe( |
| 961 | Effect.provideService(FetchHttpClient.Fetch, globalThis.fetch), |
| 962 | Effect.provide( |
| 963 | managedRelayClientLayer("https://permission-relay.example.test").pipe( |
| 964 | Layer.provide(Layer.mergeAll(FetchHttpClient.layer, cryptoLayer)), |
| 965 | ), |
| 966 | ), |
| 967 | ); |
| 968 | }, |
| 969 | ); |
| 927 | 970 | }); |