Skip to content

Commit

Permalink
Add tests for push
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejKolar committed Aug 21, 2020
1 parent d8e0cf0 commit 183ce5a
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions src/push.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const PushNotifications = require("node-pushnotifications");
const push = require("./push");

const mockSend = jest.fn();
jest.mock("node-pushnotifications", () => {
return jest.fn().mockImplementation(() => ({
send: mockSend,
}));
});

describe("run", () => {
afterEach(() => {
PushNotifications.mockClear();
mockSend.mockClear();
});

test("calls push with correct data for p8", () => {
const config = {
type: "p8",
key: "key",
teamId: "teamId",
keyId: "keyId",
production: false,
pushToken: "token",
bundleId: "bundleId",
title: "title",
body: "body",
badge: 1,
sound: "sound",
};

push.run(config);

const settings = {
apn: {
production: false,
token: { key: "key", keyId: "keyId", teamId: "teamId" },
},
};

const token = ["token"];

const data = {
badge: 1,
body: "body",
sound: "sound",
title: "title",
topic: "bundleId",
};

expect(PushNotifications).toHaveBeenCalledWith(settings);
expect(mockSend).toHaveBeenCalledTimes(1);
expect(mockSend).toHaveBeenCalledWith(token, data);
});

test("calls push with correct data for pem", () => {
const config = {
type: "pem",
cert: "cert",
key: "key",
production: false,
pushToken: "token",
bundleId: "bundleId",
title: "title",
body: "body",
badge: 1,
sound: "sound",
};

push.run(config);

const settings = {
apn: {
cert: "cert",
key: "key",
production: false,
},
};

const token = ["token"];

const data = {
badge: 1,
body: "body",
sound: "sound",
title: "title",
topic: "bundleId",
};

expect(PushNotifications).toHaveBeenCalledWith(settings);
expect(mockSend).toHaveBeenCalledTimes(1);
expect(mockSend).toHaveBeenCalledWith(token, data);
});

test("calls push with correct data for firebase", () => {
const config = {
type: "firebase",
key: "key",
pushToken: "token",
bundleId: "bundleId",
title: "title",
body: "body",
badge: 1,
sound: "sound",
};

push.run(config);

const settings = {
gcm: {
id: "key",
},
};

const token = ["token"];

const data = {
badge: 1,
body: "body",
sound: "sound",
title: "title",
topic: "bundleId",
};

expect(PushNotifications).toHaveBeenCalledWith(settings);
expect(mockSend).toHaveBeenCalledTimes(1);
expect(mockSend).toHaveBeenCalledWith(token, data);
});
});

0 comments on commit 183ce5a

Please sign in to comment.