From 043e629864a17b0f46b10abdf7284c4bb2cfbbe3 Mon Sep 17 00:00:00 2001 From: KasunIs Date: Mon, 21 Nov 2022 14:31:47 +0530 Subject: [PATCH 1/3] Unit tests of contracts.js --- package.json | 7 +-- test.js | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 test.js diff --git a/package.json b/package.json index a64e6a6..2c57789 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Integration Library for IdentityBlock Person Verification Platform", "main": "api.js", "scripts": { - "test": "jest" + "test": "mocha --recursive --exit" }, "repository": { "type": "git", @@ -24,6 +24,7 @@ }, "devDependencies": { "jest": "^29.3.1", - "jsdoc-to-markdown": "^7.1.1" + "jsdoc-to-markdown": "^7.1.1", + "mocha": "^10.1.0" } -} \ No newline at end of file +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..0806e72 --- /dev/null +++ b/test.js @@ -0,0 +1,135 @@ +// Requiring module +const assert = require('assert'); +const { + deployContract, + getVerifiedToken, + getUserName, + getUserEmail, + getUserDOB, + getUserCountry, + getUserMobile, + getUserGender, + } = require("./contract.js"); + +describe("Unit testing of contract.js", () => { + before(() => { + console.log( "Starting" ); + }); + + after(() => { + console.log( "Testing done" ); + }); + + describe( "getUserName function", () => { + beforeEach(() => { + console.log( "Starting getUserName testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); + + describe( "getUserEmail function", () => { + beforeEach(() => { + console.log( "Starting getUserEmail testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserEmail("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "kasunisuranga.19@cse.mrt.ac.lk"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); + + describe( "getUserDOB function", () => { + beforeEach(() => { + console.log( "Starting getUserDOB testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserDOB("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "2000-01-12"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); + + describe( "getUserCountry function", () => { + beforeEach(() => { + console.log( "Starting getUserCountry testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserCountry("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Sri Lanka"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); + + describe( "getUserMobile function", () => { + beforeEach(() => { + console.log( "Starting getUserMobile testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserMobile("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "+94711009825"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); + + describe( "getUserGender function", () => { + beforeEach(() => { + console.log( "Starting getUserGender testing" ); + }); + + it("Test 1", async () => { + assert.equal(await getUserGender("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Male"); + }); + + it("Test 2", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + + it("Test 3", async () => { + assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); + }); + }); +}); + +/*getUserName("0x417fB7b824D97f4554aD61A97d254c24f7C84d20", "0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1").then((data) => { + console.log(data) + } +);*/ \ No newline at end of file From 074eecd1b2d6a987954b2d14450ebec91c04c327 Mon Sep 17 00:00:00 2001 From: KasunIs Date: Mon, 21 Nov 2022 14:40:56 +0530 Subject: [PATCH 2/3] Test server --- integration-test.js | 17 +++++++++++++++++ package.json | 1 + test_server.js | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 integration-test.js create mode 100644 test_server.js diff --git a/integration-test.js b/integration-test.js new file mode 100644 index 0000000..0360478 --- /dev/null +++ b/integration-test.js @@ -0,0 +1,17 @@ +const express = require('express'); +const chai = require(‘chai’); +const request = require(‘supertest’); +const app = express(); + +describe('POST Create User Wallet', () => { + it('should create wallet for the user', () => { + request(app) + .post('123456/wallet') + .send({}) + .expect(201) + .then((res) => { + expect(res.headers.location).to.be.eql('123456/wallet'); + // more validations can be added here as required + }); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json index 2c57789..a6c203c 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "homepage": "https://github.com/IdentityBlock/IntegrationLibrary#readme", "dependencies": { "dotenv": "^16.0.3", + "express": "^4.18.2", "fs": "^0.0.1-security", "qrcode": "^1.5.1", "web3": "^1.8.1" diff --git a/test_server.js b/test_server.js new file mode 100644 index 0000000..04af895 --- /dev/null +++ b/test_server.js @@ -0,0 +1,18 @@ +const express = require("express") +const app = express() + +app.use("/loadContract", (req, res, next) => { + res.send("This is the express server") +}) + +app.get("/getQR", (req, res, next) => { + res.send("This is the hello response"); +}) + +app.get("/getTokenVerified", (req, res, next) => { + res.send("This is the hello response"); +}) + +app.listen(3000, () => { + console.log("Server is Running") +}) \ No newline at end of file From 4b3c52572d114d0efe39a236d9b478621f5e89dd Mon Sep 17 00:00:00 2001 From: KasunIs Date: Mon, 21 Nov 2022 14:57:09 +0530 Subject: [PATCH 3/3] Unit tests --- integration-test.js | 9 ++++---- test.js | 52 ++------------------------------------------- 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/integration-test.js b/integration-test.js index 0360478..0a9a168 100644 --- a/integration-test.js +++ b/integration-test.js @@ -1,6 +1,6 @@ const express = require('express'); -const chai = require(‘chai’); -const request = require(‘supertest’); +const chai = require('chai'); +const request = require('supertest'); const app = express(); describe('POST Create User Wallet', () => { @@ -10,8 +10,7 @@ describe('POST Create User Wallet', () => { .send({}) .expect(201) .then((res) => { - expect(res.headers.location).to.be.eql('123456/wallet'); - // more validations can be added here as required - }); + expect(res.headers.location).to.be.eql('123456/wallet'); + }); }); }); \ No newline at end of file diff --git a/test.js b/test.js index 0806e72..432246f 100644 --- a/test.js +++ b/test.js @@ -28,14 +28,6 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); describe( "getUserEmail function", () => { @@ -46,14 +38,6 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserEmail("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "kasunisuranga.19@cse.mrt.ac.lk"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); describe( "getUserDOB function", () => { @@ -64,14 +48,6 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserDOB("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "2000-01-12"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); describe( "getUserCountry function", () => { @@ -82,14 +58,6 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserCountry("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Sri Lanka"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); describe( "getUserMobile function", () => { @@ -100,14 +68,6 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserMobile("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "+94711009825"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); describe( "getUserGender function", () => { @@ -118,18 +78,10 @@ describe("Unit testing of contract.js", () => { it("Test 1", async () => { assert.equal(await getUserGender("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Male"); }); - - it("Test 2", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); - - it("Test 3", async () => { - assert.equal(await getUserName("0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1", "0xe43FD05d7E2257e2265099cf5Fe87602a6DEfE91"), "Kasun Isuranga"); - }); }); }); -/*getUserName("0x417fB7b824D97f4554aD61A97d254c24f7C84d20", "0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1").then((data) => { +getUserName("0x417fB7b824D97f4554aD61A97d254c24f7C84d20", "0x6102Fb1Caea3Ab5ED5a8Ac844BdB7F28bc8363D1").then((data) => { console.log(data) } -);*/ \ No newline at end of file +); \ No newline at end of file