Skip to content

Commit

Permalink
Passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Apr 12, 2024
1 parent 578e776 commit 7052900
Show file tree
Hide file tree
Showing 101 changed files with 838 additions and 34,214 deletions.
Binary file removed POC/static/510logo.jpg
Binary file not shown.
Binary file removed POC/static/ReliefBox-horizontal-nobackground.png
Binary file not shown.
Binary file removed POC/static/ReliefBox-horizontal.png
Binary file not shown.
Binary file removed POC/static/ReliefBox.PNG
Binary file not shown.
25 changes: 0 additions & 25 deletions POC/static/navbar-burger.js

This file was deleted.

6 changes: 0 additions & 6 deletions PWA/jest.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions PWA/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"@types/jest": "^29.5.11",
"http-server": "^0.10.0",
"jest": "^29.7.0"
},
"jest": {
"verbose": false,
"roots": ["public"]
}
}
6 changes: 0 additions & 6 deletions PWA/public/Models/BenificiarySpreadSheetRow.js

This file was deleted.

6 changes: 6 additions & 0 deletions PWA/public/Models/DistributionBeneficiary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class DistributionBeneficiary {
constructor(beneficiaryCode, distributionName) {
this.beneficiaryCode = beneficiaryCode;
this.distributionName = distributionName;
}
}
1 change: 0 additions & 1 deletion PWA/public/Models/FetchEvent.js

This file was deleted.

1 change: 1 addition & 0 deletions PWA/public/RouteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RouteEvents.nameDistribution = "/name_distrib.html";
RouteEvents.listDistributions = "/list_distrib.html";
RouteEvents.deleteDistribution = "/list_distrib_delete.html";
RouteEvents.uploadData = "/upload_data.html";
RouteEvents.viewData = "/view_data.html";
RouteEvents.uploadDataError = "/upload_error.html";
RouteEvents.template = "/template.html";
RouteEvents.chooseBenificiaryCodeInputMethodPage = "/choose_input_method.html";
Expand Down
21 changes: 18 additions & 3 deletions PWA/public/Services/ActiveSession.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
class ActiveSession {
export class ActiveSession {
constructor(database) {
console.info("ℹ️ Constructing active session, should only happen once ");
this.database = database;
}
get nameOfLastViewedDistribution() {
return this._nameOfLastViewedDistribution;
}
set nameOfLastViewedDistribution(value) {
console.log("ℹ️ name of last known distribution is now:");
console.log(value);
this._nameOfLastViewedDistribution = value;
}
}
export class ActiveSessionContainer {
constructor(activeSession) {
this.activeSession = activeSession;
}
}
ActiveSession.singleton = new ActiveSession();
export { ActiveSession };
34 changes: 34 additions & 0 deletions PWA/public/Services/BeneficiariesService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ActiveSessionContainer } from "./ActiveSession.js";
export class BeneficiariesService extends ActiveSessionContainer {
async beneficiariesForActiveDistribution() {
const database = this.activeSession.database;
const activeDistributionName = this.activeSession.nameOfLastViewedDistribution;
if (activeDistributionName) {
const distribution = await database.distributionWithName(activeDistributionName);
if (distribution) {
const activeDistributionBeneficiaries = (await database.benificiariesForDistribution(distribution)).filter((distributionBeneficiary) => {
return distributionBeneficiary.distributionName === activeDistributionName;
});
const activeDistributionBeneficiaryCodes = activeDistributionBeneficiaries
.map((distributionBeneficiary) => {
return distributionBeneficiary.beneficiaryCode;
});
const allBeneficiaries = await database.readBeneficiaries();
const beneficiaries = allBeneficiaries
.filter((beneficiary) => {
return activeDistributionBeneficiaryCodes.indexOf(beneficiary.code) != -1;
});
console.log("ℹ️");
console.log(allBeneficiaries);
console.log(beneficiaries);
return beneficiaries;
}
else {
throw "Expected distribution";
}
}
else {
throw "Expected active distribution name";
}
}
}
62 changes: 62 additions & 0 deletions PWA/public/Services/BeneficiariesService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, test, expect, beforeEach } from '@jest/globals';
import { fail } from 'assert';
import { BeneficiariesService } from './BeneficiariesService.js';
import { IDBFactory } from "fake-indexeddb";
import { ActiveSession } from './ActiveSession.js';
import { Database } from './Database.js';
import { Distribution } from '../Models/Distribution.js';
import { Beneficiary } from '../Models/Beneficiary';
describe('BeneficiariesService', () => {
const existingDistributionName = "ExistingDistributionName";
const beneficiaryCode1 = "code1";
const beneficiaryCode2 = "code2";
const existingDistribution = new Distribution("", "", "", existingDistributionName);
const beneficiary1 = new Beneficiary(beneficiaryCode1, [], []);
const beneficiary2 = new Beneficiary(beneficiaryCode2, [], []);
var database = new Database(new IDBFactory());
var activeSesion = new ActiveSession(database);
var sut = new BeneficiariesService(activeSesion);
beforeEach(() => {
database = new Database(new IDBFactory());
activeSesion = new ActiveSession(database);
sut = new BeneficiariesService(activeSesion);
});
test("When there's no active distribution Then error is thrown", async () => {
activeSesion.nameOfLastViewedDistribution = undefined;
try {
const beneficiaries = await sut.beneficiariesForActiveDistribution();
fail("expected other error to be thrown at this point");
}
catch (error) {
expect(error).toEqual("Expected active distribution name");
}
});
test("When active distribution doesn't exist Then error is thrown", async () => {
activeSesion.nameOfLastViewedDistribution = "Nonexisting distribution name";
try {
const beneficiaries = await sut.beneficiariesForActiveDistribution();
fail("expected other error to be thrown at this point");
}
catch (error) {
expect(error).toEqual("Expected distribution");
}
});
test("When active distribution exist without beneficiaries Then no beneficiaries are provided", async () => {
activeSesion.nameOfLastViewedDistribution = existingDistributionName;
await database.addDistribution(existingDistribution);
const beneficiaries = await sut.beneficiariesForActiveDistribution();
expect(beneficiaries.length).toEqual(0);
});
test("When active distribution exist with beneficiaries Then they beneficiaries are provided", async () => {
activeSesion.nameOfLastViewedDistribution = existingDistributionName;
const distributions = await database.readDistributions();
console.log(distributions);
await database.addDistribution(existingDistribution);
await database.addBeneficiaryToDistribution(beneficiary1, existingDistribution);
await database.addBeneficiaryToDistribution(beneficiary2, existingDistribution);
const beneficiaries = await sut.beneficiariesForActiveDistribution();
expect(beneficiaries.length).toEqual(2);
expect(beneficiaries[0].code).toEqual(beneficiaryCode1);
expect(beneficiaries[1].code).toEqual(beneficiaryCode2);
});
});
6 changes: 3 additions & 3 deletions PWA/public/Services/BeneficiaryDeserializationService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Beneficiary } from "../Models/Beneficiary";
import { FormParser } from "./FormParser";
import { SpreadSheetFileParser } from "./SpreadSheetFileParser";
import { Beneficiary } from "../Models/Beneficiary.js";
import { FormParser } from "./FormParser.js";
import { SpreadSheetFileParser } from "./SpreadSheetFileParser.js";
export class BeneficiaryDeserializationService {
async deserializeFormDataFromRequest(request) {
return new Promise(async (resolve, reject) => {
Expand Down
9 changes: 5 additions & 4 deletions PWA/public/Services/BeneficiaryEligilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ export class BeneficiaryEligilityService {
if (nameOfActiveDistribution) {
const distribution = await this.activeSession.database.distributionWithName(nameOfActiveDistribution);
if (distribution) {
const beneficiaries = await this.activeSession.database.benificiariesForDistribution(distribution);
console.log(beneficiaries);
const matchedBeneficiaries = beneficiaries.filter((beneficiary) => {
beneficiary.code == beneficiaryCode;
const distributionBeneficiaries = await this.activeSession.database.benificiariesForDistribution(distribution);
console.log("🦆 there is a distribution");
console.log(distributionBeneficiaries);
const matchedBeneficiaries = distributionBeneficiaries.filter((beneficiary) => {
return beneficiary.beneficiaryCode === beneficiaryCode;
});
if (matchedBeneficiaries.length == 1) {
return true;
Expand Down
58 changes: 28 additions & 30 deletions PWA/public/Services/BeneficiaryEligilityService.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
import { describe, test, expect } from '@jest/globals';
import { describe, test, expect } from "@jest/globals";
import { BeneficiaryEligilityService } from "./BeneficiaryEligilityService";
import { Database } from "./Database";
import { indexedDB } from "fake-indexeddb";
import { ActiveSession } from '../SessionState/ActiveSession';
import { Distribution } from '../Models/Distribution';
import { Beneficiary } from '../Models/Beneficiary';
import { fail } from 'assert';
const activeEligibleBeneficiaryCode = "1234";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
import { ActiveSession } from "./ActiveSession";
import { Distribution } from "../Models/Distribution";
import { Beneficiary } from "../Models/Beneficiary";
import { fail } from "assert";
const activeEligibleBeneficiaryCode = "1234AA";
const inActiveEligibleBeneficiaryCode = "5432";
const eligibleActiveDistributionBeneficiary = new Beneficiary(activeEligibleBeneficiaryCode, ["code", "name"], [activeEligibleBeneficiaryCode, "henry"]);
const eligibleInactiveDistributionBeneficiary = new Beneficiary(activeEligibleBeneficiaryCode, ["code", "name"], [inActiveEligibleBeneficiaryCode, "tedd"]);
const activeDistribution = new Distribution("items", "date", "place", "activeDistribution");
const inactiveDistribution = new Distribution("items", "date", "place", "inactiveDistribution");
const database = new Database(indexedDB);
database.addDistribution(activeDistribution);
database.addDistribution(inactiveDistribution);
database.addBeneficiaryToDistribution(eligibleActiveDistributionBeneficiary, activeDistribution);
database.addBeneficiaryToDistribution(eligibleInactiveDistributionBeneficiary, inactiveDistribution);
describe('BeneficiaryEligilityService during active distribution', () => {
const activeSession = new ActiveSession(database);
activeSession.nameOfLastViewedDistribution = activeDistribution.distrib_name;
const sut = new BeneficiaryEligilityService(activeSession);
test("When checking elible code from inactive distribution", async () => {
async function setupDatabase() {
const database = new Database(new IDBFactory());
await database.addDistribution(activeDistribution);
await database.addDistribution(inactiveDistribution);
await database.addBeneficiaryToDistribution(eligibleActiveDistributionBeneficiary, activeDistribution);
await database.addBeneficiaryToDistribution(eligibleInactiveDistributionBeneficiary, inactiveDistribution);
return database;
}
describe("BeneficiaryEligilityService", () => {
test("When checking elible code from inactive distribution during active distrubution Then not eligible", async () => {
const activeSession = await new ActiveSession(await setupDatabase());
activeSession.nameOfLastViewedDistribution = activeDistribution.distrib_name;
const sut = new BeneficiaryEligilityService(activeSession);
expect(await sut.isBenificiaryEligibleForCurrentDistribution(inActiveEligibleBeneficiaryCode)).toEqual(false);
});
});
describe('BeneficiaryEligilityService during active distribution', () => {
const activeSession = new ActiveSession(database);
activeSession.nameOfLastViewedDistribution = activeDistribution.distrib_name;
const sut = new BeneficiaryEligilityService(activeSession);
test("When checking elible code from active distribution", async () => {
//fails expectedly since implementation isn't complete yet
test("When checking elible code from active distribution during active distrubtion Then eligible", async () => {
const activeSession = await new ActiveSession(await setupDatabase());
activeSession.nameOfLastViewedDistribution = activeDistribution.distrib_name;
const sut = new BeneficiaryEligilityService(activeSession);
expect(await sut.isBenificiaryEligibleForCurrentDistribution(activeEligibleBeneficiaryCode)).toEqual(true);
});
});
describe('BeneficiaryEligilityService during inActive distribution', () => {
const activeSession = new ActiveSession(database);
activeSession.nameOfLastViewedDistribution = undefined;
const sut = new BeneficiaryEligilityService(activeSession);
test("When checking code", async () => {
test("When checking code from any distribution during inactive distrubtion Then error is thrown", async () => {
const activeSession = await new ActiveSession(await setupDatabase());
activeSession.nameOfLastViewedDistribution = undefined;
const sut = new BeneficiaryEligilityService(activeSession);
try {
const result = await sut.isBenificiaryEligibleForCurrentDistribution("could have been any code");
fail("Expected error");
Expand Down
23 changes: 0 additions & 23 deletions PWA/public/Services/BenificiaryDataParser.js

This file was deleted.

24 changes: 0 additions & 24 deletions PWA/public/Services/BenificiaryJsonValidator.js

This file was deleted.

17 changes: 0 additions & 17 deletions PWA/public/Services/BenificiaryJsonValidator.test.js

This file was deleted.

Loading

0 comments on commit 7052900

Please sign in to comment.