Skip to content

Commit

Permalink
Convert lastModified date to GMT string per spec (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
notlmn committed Feb 6, 2023
1 parent 09ebdf9 commit 31d87ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function getNotificationCount() {
const {headers, json: notifications} = await getNotificationResponse({maxItems: 1});

const interval = Number(headers.get('X-Poll-Interval'));
const lastModified = (new Date(headers.get('Last-Modified'))).toISOString();
const lastModified = (new Date(headers.get('Last-Modified'))).toGMTString();
const linkHeader = headers.get('Link');

if (linkHeader === null) {
Expand Down
2 changes: 1 addition & 1 deletion source/lib/notifications-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function playNotificationSound() {
}

export async function checkNotifications(lastModified) {
let notifications = await getNotifications({lastModified});
let notifications = await getNotifications({lastModified: lastModified.toGMTString()});
const {showDesktopNotif, playNotifSound, filterNotifications} = await optionsStorage.getAll();

if (filterNotifications) {
Expand Down
6 changes: 3 additions & 3 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ test.serial('#getNotificationCount promise resolves response of 0 notifications
global.fetch = fakeFetch();

const response = await service.getNotificationCount();
t.deepEqual(response, {count: 0, interval: 60, lastModified: '1970-01-01T00:00:00.000Z'});
t.deepEqual(response, {count: 0, interval: 60, lastModified: 'Thu, 01 Jan 1970 00:00:00 GMT'});
});

test.serial('#getNotificationCount promise resolves response of N notifications according to Link header', async t => {
Expand All @@ -168,7 +168,7 @@ test.serial('#getNotificationCount promise resolves response of N notifications
}
});

t.deepEqual(await service.getNotificationCount(), {count: 2, interval: 60, lastModified: '1970-01-01T00:00:00.000Z'});
t.deepEqual(await service.getNotificationCount(), {count: 2, interval: 60, lastModified: 'Thu, 01 Jan 1970 00:00:00 GMT'});

global.fetch = fakeFetch({
headers: {
Expand All @@ -179,7 +179,7 @@ test.serial('#getNotificationCount promise resolves response of N notifications
}
});

t.deepEqual(await service.getNotificationCount(), {count: 3, interval: 60, lastModified: '1970-01-01T00:00:00.000Z'});
t.deepEqual(await service.getNotificationCount(), {count: 3, interval: 60, lastModified: 'Thu, 01 Jan 1970 00:00:00 GMT'});
});

test.serial('#makeApiRequest returns rejected promise for 4xx status codes', async t => {
Expand Down

0 comments on commit 31d87ed

Please sign in to comment.