Skip to content

Commit edc7720

Browse files
committed
Add tests that verify installationId in Cloud Code triggers.
1 parent c4fa3f0 commit edc7720

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

spec/ParseAPI.spec.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,80 @@ describe('miscellaneous', function() {
749749
});
750750
});
751751

752+
it('test beforeSave/afterSave get installationId', function(done) {
753+
let triggerTime = 0;
754+
Parse.Cloud.beforeSave('GameScore', function(req, res) {
755+
triggerTime++;
756+
expect(triggerTime).toEqual(1);
757+
expect(req.installationId).toEqual('yolo');
758+
res.success();
759+
});
760+
Parse.Cloud.afterSave('GameScore', function(req) {
761+
triggerTime++;
762+
expect(triggerTime).toEqual(2);
763+
expect(req.installationId).toEqual('yolo');
764+
});
765+
766+
var headers = {
767+
'Content-Type': 'application/json',
768+
'X-Parse-Application-Id': 'test',
769+
'X-Parse-REST-API-Key': 'rest',
770+
'X-Parse-Installation-Id': 'yolo'
771+
};
772+
request.post({
773+
headers: headers,
774+
url: 'http://localhost:8378/1/classes/GameScore',
775+
body: JSON.stringify({ a: 'b' })
776+
}, (error, response, body) => {
777+
expect(error).toBe(null);
778+
expect(triggerTime).toEqual(2);
779+
780+
Parse.Cloud._removeHook("Triggers", "beforeSave", "GameScore");
781+
Parse.Cloud._removeHook("Triggers", "afterSave", "GameScore");
782+
done();
783+
});
784+
});
785+
786+
it('test beforeDelete/afterDelete get installationId', function(done) {
787+
let triggerTime = 0;
788+
Parse.Cloud.beforeDelete('GameScore', function(req, res) {
789+
triggerTime++;
790+
expect(triggerTime).toEqual(1);
791+
expect(req.installationId).toEqual('yolo');
792+
res.success();
793+
});
794+
Parse.Cloud.afterDelete('GameScore', function(req) {
795+
triggerTime++;
796+
expect(triggerTime).toEqual(2);
797+
expect(req.installationId).toEqual('yolo');
798+
});
799+
800+
var headers = {
801+
'Content-Type': 'application/json',
802+
'X-Parse-Application-Id': 'test',
803+
'X-Parse-REST-API-Key': 'rest',
804+
'X-Parse-Installation-Id': 'yolo'
805+
};
806+
request.post({
807+
headers: headers,
808+
url: 'http://localhost:8378/1/classes/GameScore',
809+
body: JSON.stringify({ a: 'b' })
810+
}, (error, response, body) => {
811+
expect(error).toBe(null);
812+
request.del({
813+
headers: headers,
814+
url: 'http://localhost:8378/1/classes/GameScore/' + JSON.parse(body).objectId
815+
}, (error, response, body) => {
816+
expect(error).toBe(null);
817+
expect(triggerTime).toEqual(2);
818+
819+
Parse.Cloud._removeHook("Triggers", "beforeDelete", "GameScore");
820+
Parse.Cloud._removeHook("Triggers", "afterDelete", "GameScore");
821+
done();
822+
});
823+
});
824+
});
825+
752826
it('test cloud function query parameters', (done) => {
753827
Parse.Cloud.define('echoParams', (req, res) => {
754828
res.success(req.params);

0 commit comments

Comments
 (0)