Skip to content

Commit

Permalink
Merge pull request #372 from jamccomb92/PLATFORM-410
Browse files Browse the repository at this point in the history
Platform 410
  • Loading branch information
hopetambala authored Jun 12, 2021
2 parents 114592f + aae32a7 commit cc088d7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
13 changes: 13 additions & 0 deletions _tests_/integration/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions _tests_/run-cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
28 changes: 28 additions & 0 deletions cloud/src/definer/auth.definer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}));
4 changes: 2 additions & 2 deletions cloud/src/definer/crud.definer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand All @@ -75,7 +75,7 @@
"collectCoverage": true
},
"pre-commit": [
"test-local"
"test"
],
"repository": {
"type": "git",
Expand Down

0 comments on commit cc088d7

Please sign in to comment.