Skip to content

Commit

Permalink
Passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Feb 16, 2024
1 parent 578e776 commit 4915517
Show file tree
Hide file tree
Showing 77 changed files with 243 additions and 34,063 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": true,
"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.

4 changes: 0 additions & 4 deletions PWA/public/Services/ActiveSession.js

This file was deleted.

7 changes: 3 additions & 4 deletions PWA/public/Services/BeneficiaryEligilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ 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);
const matchedBeneficiaries = distributionBeneficiaries.filter((beneficiary) => {
return beneficiary.beneficiaryCode === beneficiaryCode;
});
if (matchedBeneficiaries.length == 1) {
return true;
Expand Down
3 changes: 1 addition & 2 deletions PWA/public/Services/BeneficiaryEligilityService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActiveSession } from '../SessionState/ActiveSession';
import { Distribution } from '../Models/Distribution';
import { Beneficiary } from '../Models/Beneficiary';
import { fail } from 'assert';
const activeEligibleBeneficiaryCode = "1234";
const activeEligibleBeneficiaryCode = "1234AA";
const inActiveEligibleBeneficiaryCode = "5432";
const eligibleActiveDistributionBeneficiary = new Beneficiary(activeEligibleBeneficiaryCode, ["code", "name"], [activeEligibleBeneficiaryCode, "henry"]);
const eligibleInactiveDistributionBeneficiary = new Beneficiary(activeEligibleBeneficiaryCode, ["code", "name"], [inActiveEligibleBeneficiaryCode, "tedd"]);
Expand All @@ -30,7 +30,6 @@ describe('BeneficiaryEligilityService during active distribution', () => {
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
expect(await sut.isBenificiaryEligibleForCurrentDistribution(activeEligibleBeneficiaryCode)).toEqual(true);
});
});
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.

This file was deleted.

28 changes: 19 additions & 9 deletions PWA/public/Services/CacheFilePathService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import { BeneficiaryEligilityService } from "./BeneficiaryEligilityService.js";
export class CacheFilePathService {
pathsOfFilesToCache() {
return [
this.imagesPaths(),
this.pagePaths(),
this.modelPaths(),
this.toplevelScriptsPaths(),
this.fetchEventHanderPaths(),
this.interfacesPaths(),
this.externalLibrariesPaths(),
this.servicePaths(),
this.sessionStatePaths()
this.sessionStatePaths(),
].reduce((previousArray, currentValue) => {
return previousArray.concat(currentValue);
}, []);
Expand All @@ -58,13 +59,24 @@ export class CacheFilePathService {
"app",
"sw",
"navbar-burger",
RouteEvents.name
RouteEvents.name,
]);
}
externalLibrariesPaths() {
return this.pathsForTypesInFolder("ExternalLibraries", [
"mustache",
"xlsx.full.min"
"xlsx.full.min",
]).concat([
"https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css",
"https://unpkg.com/@zxing/library@latest/umd/index.min.js",
]);
}
imagesPaths() {
return this.pathsForTypesInFolder("images", [
"/images/ReliefBox-horizontal-nobackground.png",
"/images/510logo.jpg",
"/images/ReliefBox-horizontal.png",
"/images/ReliefBox.PNG",
]);
}
modelPaths() {
Expand All @@ -73,7 +85,7 @@ export class CacheFilePathService {
Distribution.name,
DeleteDistributionPost.name,
SelectDistributionPost.name,
BeneficiaryCodeInputMethodPost.name
BeneficiaryCodeInputMethodPost.name,
]);
}
servicePaths() {
Expand All @@ -83,13 +95,11 @@ export class CacheFilePathService {
Database.name,
DeserialisationService.name,
FormParser.name,
BeneficiaryEligilityService.name
BeneficiaryEligilityService.name,
]);
}
sessionStatePaths() {
return this.pathsForTypesInFolder("Services", [
ActiveSession.name
]);
return this.pathsForTypesInFolder("Services", [ActiveSession.name]);
}
fetchEventHanderPaths() {
return this.pathsForTypesInFolder("Services/FetchEventHandlers", [
Expand All @@ -109,7 +119,7 @@ export class CacheFilePathService {
interfacesPaths() {
return this.pathsForTypesInFolder("Interfaces", [
"FetchEvent",
"FetchEventHandler"
"FetchEventHandler",
]);
}
pathsForTypesInFolder(folder, typeNames, extension = ".js") {
Expand Down
33 changes: 28 additions & 5 deletions PWA/public/Services/Database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Beneficiary } from "../Models/Beneficiary";
import { Distribution } from "../Models/Distribution";
import { Beneficiary } from "../Models/Beneficiary.js";
import { Distribution } from "../Models/Distribution.js";
import { DistributionBeneficiary } from "../Models/DistributionBeneficiary.js";
let db;
export var ObjectStoreName;
(function (ObjectStoreName) {
Expand Down Expand Up @@ -60,7 +61,12 @@ export class Database {
async readDistributions() {
return this.getElement(ObjectStoreName.distribution);
}
//Todo: we should be able to make this non plural because of uniquenesss
async readBeneficiaries() {
return this.getElement(ObjectStoreName.beneficiary);
}
async readDistributionBeneficiaries() {
return this.getElement(ObjectStoreName.distributionBeneficiaries);
}
async distributionWithName(name) {
const distributions = await this.readDistributions();
const foundDistributions = distributions.filter((distribution) => distribution.distrib_name == name);
Expand All @@ -71,20 +77,37 @@ export class Database {
return undefined;
}
}
async beneficiaryWithCode(code) {
const beneficiaries = await this.readBeneficiaries();
const foundBeneficiaries = beneficiaries.filter((beneficiary) => beneficiary.code == code);
if (foundBeneficiaries.length > 0) {
return foundBeneficiaries[0];
}
else {
return undefined;
}
}
async addDistribution(distribution) {
return this.addElement(ObjectStoreName.distribution, distribution);
}
async deleteDistributionWithName(name) {
return this.removeElement(ObjectStoreName.distribution, await this.keyForDistributionWithName(name));
}
async benificiariesForDistribution(distribution) {
// no link to distribution yet
return [new Beneficiary("code", [], [])];
const distributionBeneficiaries = await this.readDistributionBeneficiaries();
return distributionBeneficiaries.filter((distributionBeneficiary) => distributionBeneficiary.distributionName == distribution.distrib_name);
}
async addBenificiary(beneficiary) {
return this.addElement(ObjectStoreName.beneficiary, beneficiary);
}
async addBeneficiaryToDistribution(beneficiary, distribution) {
const existing = await this.readDistributionBeneficiaries();
existing.forEach((curent) => {
if (curent.beneficiaryCode === beneficiary.code && curent.distributionName === distribution.distrib_name) {
throw Error("Beneficiary was already added to distribution");
}
});
return this.addElement(ObjectStoreName.distributionBeneficiaries, new DistributionBeneficiary(beneficiary.code, distribution.distrib_name));
}
async keyForDistributionWithName(name) {
const distributions = await this.readDistributions();
Expand Down
33 changes: 29 additions & 4 deletions PWA/public/Services/Database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,41 @@ describe('Database', () => {
const sut = new Database(indexedDB);
const distributionName = "UniqueDistributionName";
const distribution = new Distribution("items", "date", "location", distributionName);
const beneficiary = new Beneficiary("123", ["code"], ["123"]);
const beneficiaryCode = "123";
const beneficiary = new Beneficiary(beneficiaryCode, ["code"], [beneficiaryCode]);
test("When adding distribution, it can be retrieved", async () => {
await sut.addDistribution(distribution);
const receivedDistribution = await sut.distributionWithName(distributionName);
expect(receivedDistribution.distrib_name).toEqual(distributionName);
});
test("When same distribution is added again, constaint error is thown", async () => {
try {
await sut.addDistribution(distribution);
throw new Error("Expected other error to be thown");
}
catch (error) {
expect(error.name).toEqual("ConstraintError");
}
});
test("When adding a beneficiary, it can be retrieved", async () => {
await sut.addBenificiary(beneficiary);
const receivedBeneficiary = await sut.beneficiaryWithCode(beneficiaryCode);
expect(receivedBeneficiary.code).toEqual(beneficiaryCode);
});
test("When adding beneficiary to distribution, it can be retrieved", async () => {
await sut.addDistribution(distribution);
await sut.addBeneficiaryToDistribution(beneficiary, distribution);
const receivedDistribution = await sut.distributionWithName(distributionName);
expect(sut.benificiariesForDistribution(distribution)).toStrictEqual([beneficiary]);
const receivedBeneficiaries = await sut.benificiariesForDistribution(distribution);
expect(receivedBeneficiaries.length).toEqual(1);
expect(receivedBeneficiaries[0].beneficiaryCode).toEqual(beneficiary.code);
expect(receivedBeneficiaries[0].distributionName).toEqual(distribution.distrib_name);
});
test("When adding beneficiary to distribution twice, an error is thown", async () => {
try {
await sut.addBeneficiaryToDistribution(beneficiary, distribution);
throw Error("expected error to be thown at this point");
}
catch (error) {
expect(error.message).toBe("Beneficiary was already added to distribution");
}
});
});
Loading

0 comments on commit 4915517

Please sign in to comment.