Skip to content

Commit

Permalink
Push notifications (#7682)
Browse files Browse the repository at this point in the history
* Fix Social Push notifications

* Fix code formatting issues

* Fix commented issues

* Fix Syntax errors

* update push notify dependency

* specify push-notify version

* change how apn key is loaded

* feat(push-notifications): improve logging

* feat(push-notifications): disable v2 push notifications

* test(push-notifications): add unit tests and improve integration ones

* fix(push-notifications): throw when required params are missing

* fix(tests): correct descriptions and remove wrong comment

* fix(push-notifications): trim APN key

* fix(apn): log feedback only if it has data

* fix(apn): load cert and key differently

* fix(tests): correctly load apn during tests

* download creds from S3 and create AWS lib

* convert s3 buffer to a string

* fix(apn): remove console.log and do not use cert twice

* invert key and cert, disable failing test

* invert key and cert
  • Loading branch information
paglias authored Jun 22, 2016
1 parent 09c7c45 commit 08d7727
Show file tree
Hide file tree
Showing 26 changed files with 624 additions and 291 deletions.
13 changes: 10 additions & 3 deletions common/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@
"emailNotifications": "Email Notifications",
"wonChallenge": "You won a Challenge!",
"newPM": "Received Private Message",
"newPMInfo": "New Message from <%= name %>: <%= message %>",
"sentGems": "Sent gems!",
"giftedGems": "Gifted Gems",
"giftedGemsInfo": "<%= amount %> Gems - by <%= name %>",
"giftedGemsInfo": "<%= name %> gifted you <%= amount %> Gems",
"giftedSubscription": "Gifted Subscription",
"giftedSubscriptionInfo": "<%= name %> gifted you a <%= months %> Subscription",
"invitedParty": "Invited To Party",
"invitedGuild": "Invited To Guild",
"importantAnnouncements": "Your account is inactive",
Expand All @@ -126,6 +128,7 @@
"unsubscribedTextOthers": "You won't receive any other email from Habitica.",
"unsubscribeAllEmails": "Check to Unsubscribe from Emails",
"unsubscribeAllEmailsText": "By checking this box, I certify that I understand that by unsubscribing from all emails, Habitica will never be able to notify me via email about important changes to the site or my account.",
"unsubscribeAllPush": "Check to Unsubscribe from all Push Notifications",
"correctlyUnsubscribedEmailType": "Correctly unsubscribed from \"<%= emailType %>\" emails.",
"subscriptionRateText": "Recurring $<%= price %> USD every <%= months %> months",
"recurringText": "recurring",
Expand All @@ -138,8 +141,8 @@
"promoCode": "Promo Code",
"promoCodeApplied": "Promo Code Applied! Check your inventory",
"promoPlaceholder": "Enter Promotion Code",
"couponText": "We sometimes have events and give out coupon codes for special gear. (eg, those who stop by our Wondercon booth)",
"displayInviteToPartyWhenPartyIs1": "Display Invite To Party button when party has 1 member.",
"couponText": "We sometimes have events and give out coupon codes for special gear. (eg, those who stop by our Wondercon booth)",
"saveCustomDayStart": "Save Custom Day Start",
"registration": "Registration",
"addLocalAuth": "Add local authentication:",
Expand All @@ -152,8 +155,11 @@
"invalidUrl": "invalid url",
"invalidEnabled": "the \"enabled\" parameter should be a boolean",
"regIdRequired": "RegId is required",
"invalidPushClient": "Invalid client. Only Official Habitica clients can receive push notifications.",
"pushDeviceAdded": "Push device added successfully",
"pushDeviceAlreadyAdded": "The user already has the push device",
"pushDeviceNotFound": "The user has no push device with this id.",
"pushDeviceRemoved": "Push device removed successfully.",
"add": "Add",
"buyGemsGoldCap": "Cap raised to <%= amount %>",
"mysticHourglass": "<%= amount %> Mystic Hourglass",
Expand All @@ -168,5 +174,6 @@
"amazonPayments": "Amazon Payments",
"timezone": "Time Zone",
"timezoneUTC": "Habitica uses the time zone set on your PC, which is: <strong><%= utc %></strong>",
"timezoneInfo": "If that time zone is wrong, first reload this page using your browser's reload or refresh button to ensure that Habitica has the most recent information. If it is still wrong, adjust the time zone on your PC and then reload this page again.<br><br> <strong>If you use Habitica on other PCs or mobile devices, the time zone must be the same on them all.</strong> If your Dailies have been resetting at the wrong time, repeat this check on all other PCs and on a browser on your mobile devices."
"timezoneInfo": "If that time zone is wrong, first reload this page using your browser's reload or refresh button to ensure that Habitica has the most recent information. If it is still wrong, adjust the time zone on your PC and then reload this page again.<br><br> <strong>If you use Habitica on other PCs or mobile devices, the time zone must be the same on them all.</strong> If your Dailies have been resetting at the wrong time, repeat this check on all other PCs and on a browser on your mobile devices.",
"push": "Push"
}
3 changes: 0 additions & 3 deletions common/script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ import blockUser from './ops/blockUser';
import clearPMs from './ops/clearPMs';
import deletePM from './ops/deletePM';
import reroll from './ops/reroll';
import addPushDevice from './ops/addPushDevice';
import reset from './ops/reset';
import markPmsRead from './ops/markPMSRead';

Expand Down Expand Up @@ -191,7 +190,6 @@ api.ops = {
clearPMs,
deletePM,
reroll,
addPushDevice,
reset,
markPmsRead,
};
Expand Down Expand Up @@ -272,7 +270,6 @@ api.wrap = function wrapUser (user, main = true) {
addWebhook: _.partial(importedOps.addWebhook, user),
updateWebhook: _.partial(importedOps.updateWebhook, user),
deleteWebhook: _.partial(importedOps.deleteWebhook, user),
addPushDevice: _.partial(importedOps.addPushDevice, user),
clearPMs: _.partial(importedOps.clearPMs, user),
deletePM: _.partial(importedOps.deletePM, user),
blockUser: _.partial(importedOps.blockUser, user),
Expand Down
41 changes: 0 additions & 41 deletions common/script/ops/addPushDevice.js

This file was deleted.

2 changes: 0 additions & 2 deletions common/script/ops/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import deleteTag from './deleteTag';
import addWebhook from './addWebhook';
import updateWebhook from './updateWebhook';
import deleteWebhook from './deleteWebhook';
import addPushDevice from './addPushDevice';
import clearPMs from './clearPMs';
import deletePM from './deletePM';
import blockUser from './blockUser';
Expand Down Expand Up @@ -68,7 +67,6 @@ module.exports = {
addWebhook,
updateWebhook,
deleteWebhook,
addPushDevice,
clearPMs,
deletePM,
blockUser,
Expand Down
5 changes: 1 addition & 4 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@
"LOGGLY_ACCOUNT": "account",
"PUSH_CONFIGS": {
"GCM_SERVER_API_KEY": "",
"APN_PEM_FILES": {
"KEY": "key.pem",
"CERT": "cert.pem"
}
"APN_ENABLED": "true"
},
"FIREBASE": {
"APP": "app-name",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"paypal-rest-sdk": "^1.2.1",
"pretty-data": "^0.40.0",
"ps-tree": "^1.0.0",
"push-notify": "^1.1.1",
"push-notify": "habitrpg/push-notify#v1.2.0",
"request": "~2.72.0",
"rimraf": "^2.4.3",
"run-sequence": "^1.1.4",
Expand Down
32 changes: 32 additions & 0 deletions test/api/v3/integration/user/DELETE-user_push_device.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';

describe('DELETE /user/push-devices', () => {
let user;
let regId = '10';
let type = 'ios';

beforeEach(async () => {
user = await generateUser();
});

it('returns an error if user does not have the push device', async () => {
await expect(user.del(`/user/push-devices/${regId}`))
.to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('pushDeviceNotFound'),
});
});

it('removes a push device from the user', async () => {
await user.post('/user/push-devices', {type, regId});
let response = await user.del(`/user/push-devices/${regId}`);
await user.sync();

expect(response.message).to.equal(t('pushDeviceRemoved'));
expect(user.pushDevices.length).to.equal(0);
});
});
35 changes: 0 additions & 35 deletions test/api/v3/integration/user/POST-user_addPushDevice.test.js

This file was deleted.

60 changes: 60 additions & 0 deletions test/api/v3/integration/user/POST-user_push_device.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';

describe('POST /user/push-devices', () => {
let user;
let regId = '10';
let type = 'ios';

beforeEach(async () => {
user = await generateUser();
});

it('returns an error when regId is not provided', async () => {
await expect(user.post('/user/push-devices'), {type})
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});

it('returns an error when type is not provided', async () => {
await expect(user.post('/user/push-devices', {regId}))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});

it('returns an error when type is not valid', async () => {
await expect(user.post('/user/push-devices', {regId, type: 'invalid'}))
.to.eventually.be.rejected.and.to.eql({
code: 400,
error: 'BadRequest',
message: 'Invalid request parameters.',
});
});

it('returns an error if user already has the push device', async () => {
await user.post('/user/push-devices', {type, regId});
await expect(user.post('/user/push-devices', {type, regId}))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('pushDeviceAlreadyAdded'),
});
});

it('adds a push device to the user', async () => {
let response = await user.post('/user/push-devices', {type, regId});
await user.sync();

expect(response.message).to.equal(t('pushDeviceAdded'));
expect(user.pushDevices[0].type).to.equal(type);
expect(user.pushDevices[0].regId).to.equal(regId);
});
});
Loading

0 comments on commit 08d7727

Please sign in to comment.