mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(push): make a new subscription deliver for its account at once
Subscribing re-enabled a disabled channel but left the failure counter and cooldown on one that was still enabled. Failures counted before the new subscription (no browser left, a push service outage) kept every reminder skipped until the cooldown ran out, and one more transient failure switched the channel off. Subscribing now resets them too. A browser also kept the row of an account whose session ended without a sign-out, so the next person on it saw that account's reminders. An endpoint is one browser: subscribing now removes other accounts' rows for it, and the settings card, which posts its subscription on open, claims the browser for whoever uses it now.
This commit is contained in:
1 parent
38299f7c6e
commit
94ea48d723
3 files changed
+89
-4
No files matched your search
@@ -1060,4 +1060,25 @@ describe("the operator's instance-wide channel switches", () => {
|
||||
expect(decrypt(subscriptions[0].auth)).toBe(SUBSCRIPTION.keys.auth);
|
||||
expect((await channel(user.id, "WEB_PUSH"))?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("hands a browser's subscription to the account that subscribed it last", async () => {
|
||||
await switchGlobal({ webPushGlobal: true });
|
||||
const before = await makeUser();
|
||||
const after = await makeUser();
|
||||
for (const user of [before, after]) {
|
||||
const res = await callRoute(subscribeWebPush, {
|
||||
method: "POST",
|
||||
route: "/api/notifications/web-push",
|
||||
body: SUBSCRIPTION,
|
||||
auth: await makeSession(user),
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
}
|
||||
|
||||
const rows = await prisma.pushSubscription.findMany({
|
||||
where: { endpoint: SUBSCRIPTION.endpoint },
|
||||
select: { userId: true },
|
||||
});
|
||||
expect(rows).toEqual([{ userId: after.id }]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user