Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for local development #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package-lock.json
database.sqlite
src/migration/*
*.pem
*.der
*.crt
*.ppk
.idea/*
Expand All @@ -16,3 +17,5 @@ certs/*
src/carekit-root*
src/carekit-sdk.csr
bootstrapping.md
venv
.DS_Store
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,21 @@ CareKit Backend SDK is running!

We can validate that the app is running and configured correctly by simply running the predefined validation test, which uses the 'jest' npm package. If the test was run successfully the `npm start` window will have populated a new entry containing a `201` response.

To run the test, please use the `npm run test` command in a different terminal window (or tab) as depicted below. Please ensure that the directory in the recently opened terminal window/tab is pointed towards the locally cloned **IBM-HyperProtectMBaaS** repo.
To run the test, please use the `npm test` command in a different terminal window (or tab) as depicted below. Please ensure that the directory in the recently opened terminal window/tab is pointed towards the locally cloned **IBM-HyperProtectMBaaS** repo.

```bash
$ npm run test

> [email protected] test /Users/ryley.wharton1ibm.com/Documents/Github/IBM-HyperProtectMBaaS
$ npm test
> jest

(node:13022) ExperimentalWarning: The fs.promises API is experimental
PASS __test__/BackendSDKValidationTest.spec.js
BackendSDK CareKit Function
✓ Testing POST calls to Backend SDK (7 ms)
PASS __test__/BackendSDKTest.spec.js
Testing MBaaS functionality
✓ Testing POST call to Backend SDK (62 ms)
✓ Testing GET call to Backend SDK (63 ms)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.575 s
Time: 0.369 s, estimated 1 s
Ran all test suites.
```

Expand Down
85 changes: 32 additions & 53 deletions __test__/BackendSDKTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,42 @@
- using 'jest' npm package
- POST is issued using 'verification.json' file as data

Use command 'npm run test' to initiate validation test
Use command 'npm test' to initiate validation test
*/
const https = require("https");
const fs = require("fs");
const path = require("path");
const axios = require("axios");

const fs = require('fs');
const path = require('path');
const request = require('request');
const diff = require('json-diff');
// setup the cert
const cacert = fs.readFileSync(
path.resolve(__dirname + "../../src/carekit-root.crt")
);
const httpsAgent = new https.Agent({ ca: cacert });
axios.defaults.httpsAgent = httpsAgent;

describe("Testing MBaaS functionality", () => {
test("Testing POST call to Backend SDK", () => {
// code to test goes here
const input = require(path.resolve(__dirname + '../../verification.json'));
const cacert = fs.readFileSync(path.resolve(__dirname + '../../src/carekit-root.crt'));
const options = {
url: 'http://localhost:3000/revisionRecord',
method: 'POST',
headers: 'Content-Type: application/json',
body: input,
json: true,
ca: cacert
};
const input = require(path.resolve(__dirname + "../../verification.json"));

const output = async (options) => {
const response = await request.post(options, function(err, res, body) {
if(err) {
console.log(`Error: ${err}`);
};
});
return response;
}
output(options);
}),
test("Testing GET call to Backend SDK", () => {
// code to test goes here
const input = require(path.resolve(__dirname + '../../verification.json'));
const cacert = fs.readFileSync(path.resolve(__dirname + '../../src/carekit-root.crt'));
const options = {
url: 'http://localhost:3000/revisionRecord',
method: 'GET',
headers: 'Content-Type: application/json',
body: input,
json: true,
ca: cacert
};
describe("Testing MBaaS functionality", () => {
test("Testing POST call to Backend SDK", async () => {
const res = await axios({
url: "https://localhost:3000/revisionRecord",
method: "POST",
data: input,
});
expect(res.data).toEqual("RevisionRecord stored");
});

const output = async (options) => {
const response = await request.get(options, function(err, res, body) {
if(err) {
console.log(`Error: ${err}`);
};
// if returned json (i.e values stored in the DB) aren't the same as input JSON
if (!diff.diff(res, input)){
return false;
}
});
return response;
}
output(options);
test("Testing GET call to Backend SDK", async () => {
const res = await axios({
url: "https://localhost:3000/revisionRecord",
method: "GET",
params: {
knowledgeVector: {
processes: [{ id: "1C43F648-D41A-4A5A-8708-15737425FA7C", clock: 2 }],
},
},
});
expect(res.data.entities.length).toEqual(2);
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/uuid": "^8.3.3",
"@types/uuidv4": "^5.0.0",
"ajv": "^8.8.2",
"axios": "^0.24.0",
"bcryptjs": "^2.4.3",
"class-validator": "^0.13.2",
"config": "^3.3.6",
Expand All @@ -31,7 +32,7 @@
"jest": "^27.4.3",
"json-diff": "^0.5.4",
"jsonwebtoken": "^8.5.1",
"mongodb": "^4.2.1",
"mongodb": "^3.7.3",
"morgan": "^1.10.0",
"reflect-metadata": "^0.1.13",
"typedjson": "^1.8.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if (process.env.MONGO_DB === "localhost"){
database: "carekit",
entities: [`${__dirname}/entity/**/*`],
useNewUrlParser: true,
useUnifiedTopology: true,
url : "mongodb://localhost:27017/",
};
} else {
Expand Down