Bug 1933302 - Make sure last update of in-app notifications is initialized to a sensible value. r=arschmitz

And extend test to make sure initialization runs

Differential Revision: https://phabricator.services.mozilla.com/D229994

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Giger 2024-11-26 05:42:15 +00:00
Родитель d5c2ac9b8e
Коммит 23b7ce1b2a
2 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -167,6 +167,9 @@ export const InAppNotifications = {
if (typeof data.seeds !== "object") { if (typeof data.seeds !== "object") {
data.seeds = {}; data.seeds = {};
} }
if (!Number.isInteger(data.lastUpdate) || data.lastUpdate > Date.now()) {
data.lastUpdate = 0;
}
return data; return data;
}, },

Просмотреть файл

@ -79,6 +79,22 @@ add_task(function test_initializedData() {
"Should register update callback" "Should register update callback"
); );
Assert.ok(NotificationUpdater._interval, "Should initialize updater"); Assert.ok(NotificationUpdater._interval, "Should initialize updater");
Assert.deepEqual(
InAppNotifications._jsonFile.data.interactedWith,
[],
"Should initialize interacted with notifications"
);
Assert.deepEqual(
InAppNotifications._jsonFile.data.seeds,
{},
"Should initialize seeds"
);
Assert.equal(
InAppNotifications._jsonFile.data.lastUpdate,
0,
"Should initialize lastUpdate to 0"
);
}); });
add_task(async function test_noReinitialization() { add_task(async function test_noReinitialization() {