diff --git a/test/api/unit/libs/pushNotifications.js b/test/api/unit/libs/pushNotifications.js index ba09d4cdce..e8299c871e 100644 --- a/test/api/unit/libs/pushNotifications.js +++ b/test/api/unit/libs/pushNotifications.js @@ -1,13 +1,15 @@ -import requireAgain from 'require-again'; import apn from 'apn/mock'; +import _ from 'lodash'; import nconf from 'nconf'; import gcmLib from 'node-gcm'; // works with FCM notifications too import { model as User } from '../../../../website/server/models/user'; +import { + sendNotification as sendPushNotification, + MAX_MESSAGE_LENGTH, +} from '../../../../website/server/libs/pushNotifications'; describe('pushNotifications', () => { let user; - let sendPushNotification; - const pathToPushNotifications = '../../../../website/server/libs/pushNotifications'; let fcmSendSpy; let apnSendSpy; @@ -28,8 +30,6 @@ describe('pushNotifications', () => { on: () => null, send: apnSendSpy, }); - - sendPushNotification = requireAgain(pathToPushNotifications).sendNotification; }); afterEach(() => { @@ -86,6 +86,67 @@ describe('pushNotifications', () => { expect(apnSendSpy).to.not.have.been.called; }); + it('cuts the message to 300 chars', () => { + const longMessage = `12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345`; + + expect(longMessage.length > MAX_MESSAGE_LENGTH).to.equal(true); + + const details = { + identifier, + title, + message: longMessage, + payload: { + message: longMessage, + }, + }; + + sendPushNotification(user, details); + + expect(details.message).to.equal(_.truncate(longMessage, { length: MAX_MESSAGE_LENGTH })); + expect(details.payload.message) + .to.equal(_.truncate(longMessage, { length: MAX_MESSAGE_LENGTH })); + + expect(details.message.length).to.equal(MAX_MESSAGE_LENGTH); + expect(details.payload.message.length).to.equal(MAX_MESSAGE_LENGTH); + }); + + it('cuts the message to 300 chars (no payload)', () => { + const longMessage = `12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345 + 12345 12345 12345 12345 12345 12345 12345 12345 12345 12345`; + + expect(longMessage.length > MAX_MESSAGE_LENGTH).to.equal(true); + + const details = { + identifier, + title, + message: longMessage, + }; + + sendPushNotification(user, details); + + expect(details.message).to.equal(_.truncate(longMessage, { length: MAX_MESSAGE_LENGTH })); + expect(details.message.length).to.equal(MAX_MESSAGE_LENGTH); + }); + // TODO disabled because APN relies on a Promise xit('uses APN for iOS devices', () => { user.pushDevices.push({ diff --git a/test/api/unit/libs/webhooks.test.js b/test/api/unit/libs/webhooks.test.js index 47f44cdc66..5a781ea129 100644 --- a/test/api/unit/libs/webhooks.test.js +++ b/test/api/unit/libs/webhooks.test.js @@ -16,7 +16,7 @@ import { defer, sleep, } from '../../../helpers/api-unit.helper'; - +import logger from '../../../../website/server/libs/logger'; describe('webhooks', () => { let webhooks; let @@ -356,6 +356,7 @@ describe('webhooks', () => { }); it('records failures', async () => { + sinon.stub(logger, 'error'); const body = {}; sendWebhook.send(user, body); @@ -369,6 +370,9 @@ describe('webhooks', () => { expect(user.webhooks[0].failures).to.equal(1); expect((Date.now() - user.webhooks[0].lastFailureAt.getTime()) < 10000).to.be.true; + + expect(logger.error).to.be.calledOnce; + logger.error.restore(); }); it('disables a webhook after 10 failures', async () => { diff --git a/website/client/src/components/shops/market/categoryRow.vue b/website/client/src/components/shops/market/categoryRow.vue index eb4a79b6c4..92012294b6 100644 --- a/website/client/src/components/shops/market/categoryRow.vue +++ b/website/client/src/components/shops/market/categoryRow.vue @@ -11,6 +11,12 @@ {{ $t('maxBuyGems') }}

{{ item.text }}

+
+ {{ limitedString }} +