mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-04 21:15:50 +00:00
fix(gui): read push messages delivered under data
This commit is contained in:
1 parent
01de7af0ae
commit
1222878645
2 files changed
+11
-1
No files matched your search
+4
-1
@@ -82,7 +82,10 @@ function readPushPayload (pushData) {
|
||||
} catch ( _e ) {
|
||||
return null;
|
||||
}
|
||||
let message = payload && typeof payload === 'object' ? payload.puter : null;
|
||||
// Providers that only carry string data deliver it under `data`.
|
||||
let message = payload && typeof payload === 'object'
|
||||
? (payload.puter ?? payload.data?.puter)
|
||||
: null;
|
||||
if ( typeof message === 'string' ) {
|
||||
try {
|
||||
message = JSON.parse(message);
|
||||
|
||||
@@ -90,6 +90,13 @@ describe('service worker helpers', () => {
|
||||
expect(context.readPushPayload(pushData({ puter: JSON.stringify(message) }))).toEqual(message);
|
||||
});
|
||||
|
||||
it('reads the message from string data under `data.puter`', () => {
|
||||
const message = { uid: 'n2', title: 'Hello' };
|
||||
const payload = { data: { puter: JSON.stringify(message) }, from: '123', messageId: 'm1' };
|
||||
expect(context.readPushPayload(pushData(payload))).toEqual(message);
|
||||
expect(context.readPushPayload(pushData({ data: { other: 'x' } }))).toBeNull();
|
||||
});
|
||||
|
||||
it('reads nothing from a missing, garbled or misplaced payload', () => {
|
||||
expect(context.readPushPayload(null)).toBeNull();
|
||||
expect(context.readPushPayload({ json: () => { throw new SyntaxError('bad'); } })).toBeNull();
|
||||
|
||||
Reference in new issue
Block a user