Skip to content

Commit

Permalink
[UPD] add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatnm0612 committed Nov 7, 2023
1 parent 44ceb1a commit f449738
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 14 deletions.
Binary file modified packages/openspp/assets/rectangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/openspp/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export function getGroupMembers(registrant_id, offset=0, callback=false) {
if (callback) {
return callback(nextState);
}
return nextState;
} catch (err) {
console.log(`✗ Error: ${err}`);
return state;
Expand Down Expand Up @@ -296,6 +297,7 @@ export function getServicePoint(name, offset=0, callback=false) {
if (callback) {
return callback(nextState);
}
return nextState;
} catch (err) {
console.log(`✗ Error: ${err}`);
return state;
Expand Down
87 changes: 73 additions & 14 deletions packages/openspp/test/Adaptor.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { expect } from "chai";
import { execute } from "../src/Adaptor.js";
import {
execute,
getServicePoint,
searchGroup,
searchIndividual,
getGroup,
getIndividual,
getProgram
} from "../src/Adaptor.js";

const state = {
configuration: {
username: "admin",
password: "c_fqD_u*Bob9axkqdAN-FrKq",
baseUrl: "https://acf-dev.newlogic-demo.com/",
database: "devel",
},
references: [],
};

describe("execute", () => {
it("executes each operation in sequence", done => {
const state = {
configuration: {
username: "admin",
password: "935j-jv38-yeu9",
baseUrl: "https://dev.newlogic-demo.com/",
database: "devel",
},
};;
const operations = [
state => {
return { counter: 1 };
Expand All @@ -30,12 +40,61 @@ describe("execute", () => {
.then(done)
.catch(done);
});
});

describe("getServicePoint", () => {
it("get existing service point from demo server", async () => {
let finalState = await getServicePoint("Agent 1")(state);
expect(finalState.data[0].id).to.eq(16);
});

it("get non-existing service point from demo server", async () => {
let finalState = await getServicePoint("n0n-3x15t1n6-53rv1c3-p01nt")(state);
expect(finalState.data).to.be.undefined;
});
});

describe("searchGroup", () => {
it("search existing group from demo server", async () => {
let finalState = await searchGroup([["name", "ilike", "test group"]])(state);
expect(finalState.data).to.not.be.undefined;
});

it("assigns references, data to the initialState", () => {
const state = {};
it("search non-existing group from demo server", async () => {
let finalState = await searchGroup([["id", "=", 10000000]])(state);
expect(finalState.data).to.be.undefined;
});
});

describe("searchIndividual", () => {
it("search existing individual from demo server", async () => {
let finalState = await searchIndividual([["name", "ilike", "butt"]])(state);
expect(finalState.data).to.not.be.undefined;
});

it("search non-existing individual from demo server", async () => {
let finalState = await searchIndividual([["id", "=", 10000000]])(state);
expect(finalState.data).to.be.undefined;
});
});

describe("getGroup", () => {
it("get group by registrant_id", async () => {
let finalState = await getGroup("GRP_7NAAH42X")(state);
expect(finalState.data).to.not.be.undefined;
});
});

describe("getIndividual", () => {
it("get individual by registrant_id", async () => {
let finalState = await getIndividual("IND_EJFW8GUQ")(state);
expect(finalState.data).to.not.be.undefined;
});
});

execute()(state).then(finalState => {
expect(finalState).to.eql({ references: [], data: null });
});
describe("getProgram", () => {
it("get program by program_id", async () => {
let finalState = await getProgram("PROG_2023_00000128")(state);
expect(finalState.data).to.not.be.undefined;
});
});

0 comments on commit f449738

Please sign in to comment.