From 9ba17809a98a7c20868347a6954925003241b977 Mon Sep 17 00:00:00 2001 From: Chris Wilhite Date: Mon, 13 Dec 2021 14:53:56 -0500 Subject: [PATCH] updates for local development --- .gitignore | 3 ++ README.md | 18 ++++--- __test__/BackendSDKTest.spec.js | 85 +++++++++++++-------------------- package.json | 3 +- src/index.ts | 1 + 5 files changed, 46 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 07509ad..527da53 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ package-lock.json database.sqlite src/migration/* *.pem +*.der *.crt *.ppk .idea/* @@ -16,3 +17,5 @@ certs/* src/carekit-root* src/carekit-sdk.csr bootstrapping.md +venv +.DS_Store diff --git a/README.md b/README.md index bea49f5..6f26b33 100644 --- a/README.md +++ b/README.md @@ -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 - -> ibm-hyperprotect-mbaas@0.0.1 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. ``` diff --git a/__test__/BackendSDKTest.spec.js b/__test__/BackendSDKTest.spec.js index e41aaf8..af32628 100644 --- a/__test__/BackendSDKTest.spec.js +++ b/__test__/BackendSDKTest.spec.js @@ -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); }); }); diff --git a/package.json b/package.json index caf2668..baec0df 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/index.ts b/src/index.ts index ec08da9..16daa90 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,7 @@ if (process.env.MONGO_DB === "localhost"){ database: "carekit", entities: [`${__dirname}/entity/**/*`], useNewUrlParser: true, + useUnifiedTopology: true, url : "mongodb://localhost:27017/", }; } else {