Skip to content

Commit

Permalink
Merge pull request hopetambala#526 from hopetambala/PLATFORM-602
Browse files Browse the repository at this point in the history
Platform 602 - Add slackbot module
  • Loading branch information
hopetambala committed Dec 14, 2022
2 parents 80cd351 + 25065ad commit 96f58f5
Show file tree
Hide file tree
Showing 18 changed files with 997 additions and 773 deletions.
4 changes: 4 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ PARSE_JAVASCRIPT_KEY=_PLACEHOLDER_
PARSE_SERVER_URL="http://localhost:1337/parse"
PUENTE_SMS_EMAIL_API_URL=http://puentes-messaging-microservice.com
PUENTE_MANAGE_URL=https://sample-puente-manage.app/"

SLACK_TOKEN=""
SLACK_DEV_CHANNEL=""
SLACK_PROD_CHANNEL=""
4 changes: 0 additions & 4 deletions .env.staging

This file was deleted.

59 changes: 32 additions & 27 deletions .github/workflows/jest.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
name: Jest Tests

env:
PARSE_ENV : "dev"
PARSE_APP_ID : "myAppId"
PARSE_JAVASCRIPT_KEY : "_PLACEHOLDER_"
PARSE_SERVER_URL : "http://localhost:1337/parse"
PARSE_ENV: "dev"
PARSE_APP_ID: "myAppId"
PARSE_JAVASCRIPT_KEY: "_PLACEHOLDER_"
PARSE_SERVER_URL: "http://localhost:1337/parse"
PUENTE_ENV: "dev"
PUENTE_SMS_EMAIL_API_URL: "http://puentes-messaging-microservice.com"
PUENTE_MANAGE_URL: "https://sample-puente-manage.app/"
SLACK_TOKEN: ""
SLACK_DEV_CHANNEL: ""
SLACK_PROD_CHANNEL: ""

on:
push:
branches:
branches:
- master
- dev
pull_request:
branches:
- master
- dev
branches:
- master
- dev
jobs:
jest-testing:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x,14.x]
node-version: [14.x, 16.x]
services:
mongodb:
image: mongo:4.4
ports:
- 27017:27017
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Puente CloudCode Dependencies
run: |
npm install
- name: Lint
run: |
npm run lint
- name: Start App and Test Jest
run: |
npm run start &
sleep 40 &&
npm run test-github-actions
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Puente CloudCode Dependencies
run: |
npm install
- name: Lint
run: |
npm run lint
- name: Start App and Test Jest
run: |
npm run start &
sleep 40 &&
npm run test-github-actions
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ logs
*.DS_Store
/coverage
.parse.local
.env.staging
.env.prod

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.10.2](https://github.com/hopetambala/puente-node-cloudcode/compare/v1.10.1...v1.10.2) (2022-12-14)

### [1.10.1](https://github.com/hopetambala/puente-node-cloudcode/compare/v1.10.0...v1.10.1) (2022-12-13)

## [1.10.0](https://github.com/hopetambala/puente-node-cloudcode/compare/v1.9.0...v1.10.0) (2022-12-13)


### Features

* add slackbot to posting ([b5a9af4](https://github.com/hopetambala/puente-node-cloudcode/commit/b5a9af4ea4843e7339532dfb4ed896abb71804be))


### Bug Fixes

* offline post survey hook ([33db521](https://github.com/hopetambala/puente-node-cloudcode/commit/33db521fa976f1f0f8fe322f8c4449d9a1ab25be))
* return statement if no data ([47db31d](https://github.com/hopetambala/puente-node-cloudcode/commit/47db31db0f0975c8c2b2c683fd3388d05337aa74))

## [1.9.0](https://github.com/hopetambala/puente-node-cloudcode/compare/v1.5.0...v1.9.0) (2022-10-10)


Expand Down
199 changes: 112 additions & 87 deletions _tests_/integration/crud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,96 +44,121 @@ describe('crud testing', () => {
});
});

// it('should post an obj to class with relation to post with variety of classes', async () => {
// const postParams = {
// parseParentClass: 'SurveyData',
// parseParentClassID: postID1,
// localObject: [
// {
// tag: 'Vitals',
// key: 'height',
// value: '4',
// },
// {
// tag: 'HistoryMedical',
// key: 'majorEvents',
// value: null,
// },
// {
// tag: 'Prescriptions',
// key: 'name',
// value: 'Greetings__',
// },
// {
// tag: 'Allergies',
// key: 'substance',
// value: 'Tester',
// },
// {
// tag: 'EvaluationSurgical',
// key: 'AssessmentandEvaluationSurgical',
// value: 'Have',
// },
// {
// tag: 'EvaluationMedical',
// key: 'chronic_condition_hypertension',
// value: 'swell',
// },
// {
// tag: 'HistoryEnvironmentalHealth',
// key: 'yearsLivedinthecommunity',
// value: 'day!',
// },
// ],
// };
it('should post object to Supplementary Class with Relation to SurveyData', async () => {
const postParams = {
parseParentClass: 'SurveyData',
parseParentClassID: postID1,
parseClass: 'Vitals',
signature: 'Test',
photoFile: 'TestPicture',
parseUser: 'undefined',
localObject: {
height: '6',
weight: '2',
bmi: '30',
bloodPressure: '100/100',
latitude: 4,
longitude: 5,
surveyingOrganization: 'Puente',
},
};
return cloudFunctions.postObjectsToClassWithRelation(postParams).then((result) => {
expect(result.get('height')).toEqual('6');
expect(result.get('weight')).toEqual('2');
expect(result.get('bloodPressure')).toEqual('100/100');
});
});

it('should post an obj to class with relation to post with variety of classes', async () => {
const postParams = {
parseParentClass: 'SurveyData',
parseParentClassID: postID1,
localObject: [
{
tag: 'Vitals',
key: 'height',
value: '4',
},
{
tag: 'HistoryMedical',
key: 'majorEvents',
value: null,
},
{
tag: 'Prescriptions',
key: 'name',
value: 'Greetings__',
},
{
tag: 'Allergies',
key: 'substance',
value: 'Tester',
},
{
tag: 'EvaluationSurgical',
key: 'AssessmentandEvaluationSurgical',
value: 'Have',
},
{
tag: 'EvaluationMedical',
key: 'chronic_condition_hypertension',
value: 'swell',
},
{
tag: 'HistoryEnvironmentalHealth',
key: 'yearsLivedinthecommunity',
value: 'day!',
},
],
};

// return cloudFunctions.postObjectsToAnyClassWithRelation(postParams).then((result) => {
// const jsonString = JSON.stringify(result);
// const jsonValues = JSON.parse(jsonString);
return cloudFunctions.postObjectsToAnyClassWithRelation(postParams).then((result) => {
const jsonString = JSON.stringify(result);
const jsonValues = JSON.parse(jsonString);

// Object.keys(jsonValues).forEach((key) => {
// // ensure all are related to original surveyData form
// const { client } = jsonValues[key];
// const type = client.__type; // eslint-disable-line
// const { className } = client;
// const objectID = client.objectId;
// expect(type).toEqual('Pointer');
// expect(className).toEqual('SurveyData');
// expect(objectID).toEqual(`${postID1}`);
Object.keys(jsonValues).forEach((key) => {
// ensure all are related to original surveyData form
const { client } = jsonValues[key];
const type = client.__type; // eslint-disable-line
const { className } = client;
const objectID = client.objectId;
expect(type).toEqual('Pointer');
expect(className).toEqual('SurveyData');
expect(objectID).toEqual(`${postID1}`);

// // testing other attributes are correctly added
// if ('height' in jsonValues[key]) {
// const { height } = jsonValues[key];
// expect(height).toEqual('4');
// }
// if ('majorEvents' in jsonValues[key]) {
// const { majorEvents } = jsonValues[key];
// expect(majorEvents).toEqual(null);
// }
// if ('name' in jsonValues[key]) {
// const { name } = jsonValues[key];
// expect(name).toEqual('Greetings__');
// }
// if ('substance' in jsonValues[key]) {
// const { substance } = jsonValues[key];
// expect(substance).toEqual('Tester');
// }
// if ('AssessmentandEvaluationSurgical' in jsonValues[key]) {
// const { AssessmentandEvaluationSurgical } = jsonValues[key];
// expect(AssessmentandEvaluationSurgical).toEqual('Have');
// }
// if ('chronic_condition_hypertension' in jsonValues[key]) {
// const chronicConditionHypertension = jsonValues[key].chronic_condition_hypertension;
// expect(chronicConditionHypertension).toEqual('swell');
// }
// if ('yearsLivedinthecommunity' in jsonValues[key]) {
// const { yearsLivedinthecommunity } = jsonValues[key];
// expect(yearsLivedinthecommunity).toEqual('day!');
// }
// });
// expect(result).toBeDefined();
// });
// });
// testing other attributes are correctly added
if ('height' in jsonValues[key]) {
const { height } = jsonValues[key];
expect(height).toEqual('4');
}
if ('majorEvents' in jsonValues[key]) {
const { majorEvents } = jsonValues[key];
expect(majorEvents).toEqual(null);
}
if ('name' in jsonValues[key]) {
const { name } = jsonValues[key];
expect(name).toEqual('Greetings__');
}
if ('substance' in jsonValues[key]) {
const { substance } = jsonValues[key];
expect(substance).toEqual('Tester');
}
if ('AssessmentandEvaluationSurgical' in jsonValues[key]) {
const { AssessmentandEvaluationSurgical } = jsonValues[key];
expect(AssessmentandEvaluationSurgical).toEqual('Have');
}
if ('chronic_condition_hypertension' in jsonValues[key]) {
const chronicConditionHypertension = jsonValues[key].chronic_condition_hypertension;
expect(chronicConditionHypertension).toEqual('swell');
}
if ('yearsLivedinthecommunity' in jsonValues[key]) {
const { yearsLivedinthecommunity } = jsonValues[key];
expect(yearsLivedinthecommunity).toEqual('day!');
}
});
expect(result).toBeDefined();
});
});

it('should update the originally posted item', async () => {
const updateParams = {
Expand Down
29 changes: 29 additions & 0 deletions _tests_/integration/error.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { MongoClient } = require('mongodb');
const { cloudFunctions } = require('../run-cloud');

describe('crud testing', () => {
let connection;
let db;

beforeAll(async () => {
connection = await MongoClient.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
db = await connection.db();
});

afterAll(async () => {
await connection.close();
await db.close();
});

it('Test error response in SurveyData post when empy params', async () => {
const postParams = {
};
return cloudFunctions.postObjectsToClass(postParams).then((result) => {
const err = 'Error: no request params';
expect(result).toEqual(err);
});
});
});
7 changes: 7 additions & 0 deletions cloud/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"@slack/web-api": "^6.8.0",
"axios": "^0.27.2",
"lodash": "^4.17.19"
}
}
Loading

0 comments on commit 96f58f5

Please sign in to comment.