diff --git a/_tests_/integration/auth.test.js b/_tests_/integration/auth.test.js index 6b61c78a..97e3e776 100644 --- a/_tests_/integration/auth.test.js +++ b/_tests_/integration/auth.test.js @@ -38,6 +38,19 @@ describe('role testing', () => { }); }); + it('should add a push token to the existing user', async () => { + const credentials = { + userId: adminRoleID, + expoPushToken: 'TestExpoPushToken', + }; + return cloudFunctions.addUserPushToken(credentials).then((result) => { + const jsonString = JSON.stringify(result); + const jsonValues = JSON.parse(jsonString); + + expect(jsonValues.expoPushToken).toEqual('TestExpoPushToken'); + }); + }); + it('should add a user to same orginzation with contributor role', async () => { const credentials = { firstname: 'Jon', diff --git a/_tests_/run-cloud.js b/_tests_/run-cloud.js index 231197c9..b29bc793 100644 --- a/_tests_/run-cloud.js +++ b/_tests_/run-cloud.js @@ -76,6 +76,9 @@ const cloudFunctions = { organizationVerified: (params) => Parse.Cloud .run('organizationVerified', params) .then((response) => response), + addUserPushToken: (params) => Parse.Cloud + .run('addUserPushToken', params) + .then((response) => response), }; module.exports = { cloudFunctions }; diff --git a/cloud/src/definer/auth.definer.js b/cloud/src/definer/auth.definer.js index d3a0b29b..6ba857e8 100644 --- a/cloud/src/definer/auth.definer.js +++ b/cloud/src/definer/auth.definer.js @@ -186,3 +186,31 @@ Parse.Cloud.define('deleteUser', (request) => new Promise((resolve, reject) => { reject(error); }); })); + +/** ****************************************** +ADD USER PUSH TOKEN +Adds the users expo push notification to the user object + +Input Paramaters: + userId - objectId for the user + expoPushToken - expo's generated push token for the user (frontend) +******************************************* */ +Parse.Cloud.define('addUserPushToken', (request) => new Promise((resolve, reject) => { + const { userId, expoPushToken } = request.params; + const user = new Parse.User(); + user.set('id', userId); + const query = new Parse.Query(Parse.User); + query.get(userId) + .then((userObj) => { + userObj.set('expoPushToken', expoPushToken); + userObj.save(null, { useMasterKey: true }).then((updatedUser) => { + resolve(updatedUser); + }, (error1) => { + // unable to update user object + reject(error1); + }); + }, (error2) => { + // unable to find userId + reject(error2); + }); +})); diff --git a/cloud/src/definer/crud.definer.js b/cloud/src/definer/crud.definer.js index 568dfb6c..3481f248 100644 --- a/cloud/src/definer/crud.definer.js +++ b/cloud/src/definer/crud.definer.js @@ -128,7 +128,7 @@ Parse.Cloud.define('postObjectsToClass', (request) => new Promise((resolve, reje const point = new Parse.GeoPoint(localObject.latitude, localObject.longitude); surveyPoint.set('location', point); - if(request.params.parseUser) { + if (request.params.parseUser) { userObject.id = String(request.params.parseUser); surveyPoint.set('parseUser', userObject); } @@ -177,7 +177,7 @@ Parse.Cloud.define('postObjectsToClassWithRelation', (request) => new Promise((r residentIdForm.id = String(request.params.parseParentClassID); supplementaryForm.set('client', residentIdForm); - if(request.params.parseUser) { + if (request.params.parseUser) { userObject.id = String(request.params.parseUser); supplementaryForm.set('parseUser', userObject); } diff --git a/package.json b/package.json index c52252d2..6cac83cc 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ }, "scripts": { "dashboard": "parse-dashboard --dev --appId myAppId --masterKey myMasterKey --serverURL http://localhost:1337/parse --appName PuenteCloudCode", - "test-local": "env-cmd -f .env.dev jest", - "test": "env-cmd -f .env.staging jest && codecov", + "test": "env-cmd -f .env.dev jest", + "test-staging": "env-cmd -f .env.staging jest && codecov", "start": "node -r esm index.js", "start-with-dash": "concurrently \"npm run start\" \"npm run dashboard\"", "start-with-db": "concurrently \"sudo mongod\" \"npm run start\"", @@ -75,7 +75,7 @@ "collectCoverage": true }, "pre-commit": [ - "test-local" + "test" ], "repository": { "type": "git",