mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-15 07:36:27 -05:00
Fix browser notification missing the dynamic part Closes #2443
This commit is contained in:
@@ -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)/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user