Push status nits (#1462)
* Sets _id to objectId in _PushStatus (fixes #1457) * _PushStatus stores serialized payload (fixes #1458)
This commit is contained in:
@@ -295,9 +295,11 @@ describe('PushController', () => {
|
|||||||
expect(results.length).toBe(1);
|
expect(results.length).toBe(1);
|
||||||
let result = results[0];
|
let result = results[0];
|
||||||
expect(result.createdAt instanceof Date).toBe(true);
|
expect(result.createdAt instanceof Date).toBe(true);
|
||||||
|
expect(result.id.length).toBe(10);
|
||||||
expect(result.get('source')).toEqual('rest');
|
expect(result.get('source')).toEqual('rest');
|
||||||
expect(result.get('query')).toEqual(JSON.stringify({}));
|
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('status')).toEqual('succeeded');
|
||||||
expect(result.get('numSent')).toEqual(10);
|
expect(result.get('numSent')).toEqual(10);
|
||||||
expect(result.get('sentPerType')).toEqual({
|
expect(result.get('sentPerType')).toEqual({
|
||||||
|
|||||||
@@ -24,18 +24,19 @@ export default function pushStatusHandler(config) {
|
|||||||
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
let data = body.data || {};
|
let data = body.data || {};
|
||||||
|
let payloadString = JSON.stringify(data);
|
||||||
let object = {
|
let object = {
|
||||||
objectId,
|
_id: objectId,
|
||||||
pushTime: now.toISOString(),
|
pushTime: now.toISOString(),
|
||||||
_created_at: now,
|
_created_at: now,
|
||||||
query: JSON.stringify(where),
|
query: JSON.stringify(where),
|
||||||
payload: body.data,
|
payload: payloadString,
|
||||||
source: options.source,
|
source: options.source,
|
||||||
title: options.title,
|
title: options.title,
|
||||||
expiry: body.expiration_time,
|
expiry: body.expiration_time,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
numSent: 0,
|
numSent: 0,
|
||||||
pushHash: md5Hash(JSON.stringify(data)),
|
pushHash: md5Hash(payloadString),
|
||||||
// lockdown!
|
// lockdown!
|
||||||
_wperm: [],
|
_wperm: [],
|
||||||
_rperm: []
|
_rperm: []
|
||||||
@@ -44,7 +45,7 @@ export default function pushStatusHandler(config) {
|
|||||||
return collection.insertOne(object);
|
return collection.insertOne(object);
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
pushStatus = {
|
pushStatus = {
|
||||||
objectId: object.objectId
|
objectId
|
||||||
};
|
};
|
||||||
return Promise.resolve(pushStatus);
|
return Promise.resolve(pushStatus);
|
||||||
})
|
})
|
||||||
@@ -56,7 +57,7 @@ export default function pushStatusHandler(config) {
|
|||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
return collection();
|
return collection();
|
||||||
}).then((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 +94,7 @@ export default function pushStatusHandler(config) {
|
|||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
return collection();
|
return collection();
|
||||||
}).then((collection) => {
|
}).then((collection) => {
|
||||||
return collection.updateOne({status:"running", objectId: pushStatus.objectId}, {$set: update});
|
return collection.updateOne({status:"running", _id: objectId}, {$set: update});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ export default function pushStatusHandler(config) {
|
|||||||
return initialPromise.then(() => {
|
return initialPromise.then(() => {
|
||||||
return collection();
|
return collection();
|
||||||
}).then((collection) => {
|
}).then((collection) => {
|
||||||
return collection.updateOne({objectId: pushStatus.objectId}, {$set: update});
|
return collection.updateOne({_id: objectId}, {$set: update});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user