diff --git a/typescript/src/world-company-remuneration/basket-informations.ts b/typescript/src/world-company-remuneration/basket-informations.ts index cbe333d..e66cdf2 100644 --- a/typescript/src/world-company-remuneration/basket-informations.ts +++ b/typescript/src/world-company-remuneration/basket-informations.ts @@ -9,8 +9,16 @@ export class BasketInformations { // The product of the basket static map: Map = new Map() - addProductToBasket(product: string, price: number) { - BasketInformations.map.set(product, price) + // The fact that the basket has promo code + static codeDePromotion: boolean = false + + + addProductToBasket(product: string, price: number, promoCode: boolean = false) { + if (promoCode) { + BasketInformations.codeDePromotion = true + } else { + BasketInformations.map.set(product, price) + } } getBasketPrice(inCents: boolean): Number { @@ -18,11 +26,15 @@ export class BasketInformations { for (let s of Array.from(BasketInformations.map.values())) { v += s; } + if (BasketInformations.codeDePromotion) { + v -= 100; + } return inCents ? new Number(v * 100) : Number(v) } resetBasket() { this.buyBasket(); + BasketInformations.codeDePromotion = false; } buyBasket() { diff --git a/typescript/test/world-company-remuneration/basket-informations.test.ts b/typescript/test/world-company-remuneration/basket-informations.test.ts index 0a18345..3e5cfe0 100644 --- a/typescript/test/world-company-remuneration/basket-informations.test.ts +++ b/typescript/test/world-company-remuneration/basket-informations.test.ts @@ -9,7 +9,7 @@ describe("a basket should cost", () => { test("1000 otherwise", () => { let basketInformations = new BasketInformations(); basketInformations.resetBasket() - basketInformations.addProductToBasket("Toto", 1000) + basketInformations.addProductToBasket("Toto", 1000) // Promo = false expect(basketInformations.getBasketPrice(false)).toBe(1000); });