From b11f3cbee25b60d14e572bbcad4b01a2c4a7d2a6 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 12 Apr 2016 07:46:53 -0400 Subject: [PATCH 1/2] Sets _id to objectId in _PushStatus (fixes #1457) --- spec/PushController.spec.js | 1 + src/pushStatusHandler.js | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index 9a2c549c94..37b6847a61 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -295,6 +295,7 @@ describe('PushController', () => { expect(results.length).toBe(1); let result = results[0]; expect(result.createdAt instanceof Date).toBe(true); + expect(result.id.length).toBe(10); expect(result.get('source')).toEqual('rest'); expect(result.get('query')).toEqual(JSON.stringify({})); expect(result.get('payload')).toEqual(payload.data); diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index 833d785535..b6236cb3f6 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -25,7 +25,7 @@ export default function pushStatusHandler(config) { let now = new Date(); let data = body.data || {}; let object = { - objectId, + _id: objectId, pushTime: now.toISOString(), _created_at: now, query: JSON.stringify(where), @@ -44,7 +44,7 @@ export default function pushStatusHandler(config) { return collection.insertOne(object); }).then((res) => { pushStatus = { - objectId: object.objectId + objectId }; return Promise.resolve(pushStatus); }) @@ -56,7 +56,7 @@ export default function pushStatusHandler(config) { return initialPromise.then(() => { return collection(); }).then((collection) => { - return collection.updateOne({status:"pending", objectId: pushStatus.objectId}, {$set: {status: "running"}}); + return collection.updateOne({status:"pending", _id: objectId}, {$set: {status: "running"}}); }); } @@ -93,7 +93,7 @@ export default function pushStatusHandler(config) { return initialPromise.then(() => { return collection(); }).then((collection) => { - return collection.updateOne({status:"running", objectId: pushStatus.objectId}, {$set: update}); + return collection.updateOne({status:"running", _id: objectId}, {$set: update}); }); } @@ -106,7 +106,7 @@ export default function pushStatusHandler(config) { return initialPromise.then(() => { return collection(); }).then((collection) => { - return collection.updateOne({objectId: pushStatus.objectId}, {$set: update}); + return collection.updateOne({_id: objectId}, {$set: update}); }); } From 0bc4832a60a0578755a2f84ede6e8856d615f175 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 12 Apr 2016 07:54:42 -0400 Subject: [PATCH 2/2] _PushStatus stores serialized payload (fixes #1458) --- spec/PushController.spec.js | 3 ++- src/pushStatusHandler.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index 37b6847a61..9dd96bc9a9 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -298,7 +298,8 @@ describe('PushController', () => { expect(result.id.length).toBe(10); expect(result.get('source')).toEqual('rest'); expect(result.get('query')).toEqual(JSON.stringify({})); - expect(result.get('payload')).toEqual(payload.data); + expect(typeof result.get('payload')).toEqual("string"); + expect(JSON.parse(result.get('payload'))).toEqual(payload.data); expect(result.get('status')).toEqual('succeeded'); expect(result.get('numSent')).toEqual(10); expect(result.get('sentPerType')).toEqual({ diff --git a/src/pushStatusHandler.js b/src/pushStatusHandler.js index b6236cb3f6..d9cf23f597 100644 --- a/src/pushStatusHandler.js +++ b/src/pushStatusHandler.js @@ -24,18 +24,19 @@ export default function pushStatusHandler(config) { let setInitial = function(body = {}, where, options = {source: 'rest'}) { let now = new Date(); let data = body.data || {}; + let payloadString = JSON.stringify(data); let object = { _id: objectId, pushTime: now.toISOString(), _created_at: now, query: JSON.stringify(where), - payload: body.data, + payload: payloadString, source: options.source, title: options.title, expiry: body.expiration_time, status: "pending", numSent: 0, - pushHash: md5Hash(JSON.stringify(data)), + pushHash: md5Hash(payloadString), // lockdown! _wperm: [], _rperm: []