Skip to content

Commit

Permalink
chore: update unit test to use more realistic data
Browse files Browse the repository at this point in the history
  • Loading branch information
VickyStash committed Jan 31, 2025
1 parent c8511be commit 7c0fde2
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions tests/unit/parsePushNotificationPayloadTest.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import parsePushNotificationPayload from '@libs/Notification/PushNotification/parsePushNotificationPayload';

const payloadWithOnyxData = {
type: 'reportComment',
title: 'Test Payload',
onyxData: [
{
key: 'reportActions_2170976176751360',
onyxMethod: 'merge',
value: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'2463291366241014308': {
actionName: 'ADDCOMMENT',
reportID: '2170976176751360',
reportActionID: '2463291366241014308',
message: [
{
type: 'COMMENT',
html: 'Hello world!',
text: 'Hello world!',
},
],
},
},
},
],
lastUpdateID: 4024059044,
previousUpdateID: 4024059043,
reportID: 2170976176751360,
reportActionID: '2463291366241014308',
roomName: '',
app: 'new',
};
// gzip compressed json string
const compressedPayloadWithOnyxData =
'H4sIAAAAAAAAA5WQT0/DMAzFv0rJeYe0zVrKbVqR4NDBYZzQhCxqbRVJEyXen6rqd6fJmBjQC7f4/ew8P/eMOoPsLmIWjba01EphS2wWMWpIBrJGR9EzdFJD7YFuu1MJBCN77dkHdt/ji3dqdOvekjjnRZ7FeZbP4zTjl7EKaadr36/QbtHLB5B7b9OzRGRpUoztWSJiHouU3wYdwqcrUGGbRVkun6rqfrX202fbx9KTKdPrtb66Jlxmfh/nYIvnTJebXBntSEkvPaCUOjpqK+ubcCU80R992AzDsBmpBEcvpgbCYC54Ivi84EKMzFg8NHrvpnj6M9rvZP8JZrVWl9v5GozxzxaPbPgE0MCh7v4BAAA=';

describe('parsePushNotificationPayload', () => {
it("returns 'undefined' for missing payload", () => {
expect(parsePushNotificationPayload(undefined)).toBeUndefined();
});

it('returns untouched input when provided with raw json', () => {
const payload = {key: 'value'};
expect(parsePushNotificationPayload(payload)).toStrictEqual(payload);
expect(parsePushNotificationPayload(payloadWithOnyxData)).toStrictEqual(payloadWithOnyxData);
});

it('returns correct json when provided with stringified json', () => {
const json = {key: 'value'};
const payload = JSON.stringify(json);
expect(parsePushNotificationPayload(payload)).toStrictEqual(json);
const stringifiedPayload = JSON.stringify(payloadWithOnyxData);
expect(parsePushNotificationPayload(stringifiedPayload)).toStrictEqual(payloadWithOnyxData);
});

it('returns correct json when provided with gzip compressed json string', () => {
const json = {key: 'value'};
// gzip compressed json string
const payload = 'H4sIAAAAAAAAA6tWyk6tVLJSKkvMKU1VqgUAv5wYPw8AAAA=';
expect(parsePushNotificationPayload(payload)).toStrictEqual(json);
expect(parsePushNotificationPayload(compressedPayloadWithOnyxData)).toStrictEqual(payloadWithOnyxData);
});
});

0 comments on commit 7c0fde2

Please sign in to comment.