-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
101 changed files
with
838 additions
and
34,214 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.