Fix browser notification missing the dynamic part Closes #2443

This commit is contained in:
Kalle
2025-10-28 19:27:49 +02:00
parent 74b2a45b8e
commit d6b0e2aa0b
2 changed files with 48 additions and 5 deletions

View File

@@ -342,4 +342,46 @@ describe("notify() - web push notifications", () => {
expect(mockSendNotification).not.toHaveBeenCalled();
});
test("formats timestamp for scrim notifications", async () => {
const mockSubscription = {
endpoint: "https://fcm.googleapis.com/fcm/send/test",
keys: {
auth: "test-auth-key",
p256dh: "test-p256dh-key",
},
};
vi.spyOn(
NotificationRepository,
"subscriptionsByUserIds",
).mockResolvedValue([
{
id: 1,
subscription: mockSubscription,
},
]);
mockWebPushEnabled.value = true;
const testTimestamp = new Date("2024-01-15T15:30:00Z").getTime();
await notify({
userIds: [1],
notification: {
type: "SCRIM_SCHEDULED",
meta: { id: 1, at: testTimestamp },
},
});
expect(mockSendNotification).toHaveBeenCalledTimes(1);
const callArgs = mockSendNotification.mock.calls[0][1];
const payload = JSON.parse(callArgs);
expect(payload.title).toBe("Scrim Scheduled");
expect(payload.body).toMatch(
/New scrim scheduled at \d+\/\d+, \d+:\d+ (AM|PM)/,
);
});
});

View File

@@ -7,7 +7,10 @@ import i18next from "../../../modules/i18n/i18next.server";
import { logger } from "../../../utils/logger";
import * as NotificationRepository from "../NotificationRepository.server";
import type { Notification } from "../notifications-types";
import { notificationLink } from "../notifications-utils";
import {
mapMetaForTranslation,
notificationLink,
} from "../notifications-utils";
import webPush, { webPushEnabled } from "./webPush.server";
/**
@@ -141,12 +144,10 @@ function pushNotificationOptions(
): Parameters<ServiceWorkerRegistration["showNotification"]>[1] & {
title: string;
} {
const meta = mapMetaForTranslation(notification, "en-US");
return {
title: t(`common:notifications.title.${notification.type}`),
body: t(
`common:notifications.text.${notification.type}`,
notification.meta,
),
body: t(`common:notifications.text.${notification.type}`, meta),
icon: notification.pictureUrl ?? "/static-assets/img/app-icon.png",
data: { url: notificationLink(notification) },
};