Skip to content

Commit cc29ec7

Browse files
committed
[Typescript] Add promotion to basket
1 parent b5c4305 commit cc29ec7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

typescript/src/world-company-remuneration/basket-informations.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,32 @@ export class BasketInformations {
99
// The product of the basket
1010
static map: Map<string, number> = new Map<string, number>()
1111

12-
addProductToBasket(product: string, price: number) {
13-
BasketInformations.map.set(product, price)
12+
// The fact that the basket has promo code
13+
static codeDePromotion: boolean = false
14+
15+
16+
addProductToBasket(product: string, price: number, promoCode: boolean = false) {
17+
if (promoCode) {
18+
BasketInformations.codeDePromotion = true
19+
} else {
20+
BasketInformations.map.set(product, price)
21+
}
1422
}
1523

1624
getBasketPrice(inCents: boolean): Number {
1725
var v = 0;
1826
for (let s of Array.from(BasketInformations.map.values())) {
1927
v += s;
2028
}
29+
if (BasketInformations.codeDePromotion) {
30+
v -= 100;
31+
}
2132
return inCents ? new Number(v * 100) : Number(v)
2233
}
2334

2435
resetBasket() {
2536
this.buyBasket();
37+
BasketInformations.codeDePromotion = false;
2638
}
2739

2840
buyBasket() {

typescript/test/world-company-remuneration/basket-informations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("a basket should cost", () => {
99
test("1000 otherwise", () => {
1010
let basketInformations = new BasketInformations();
1111
basketInformations.resetBasket()
12-
basketInformations.addProductToBasket("Toto", 1000)
12+
basketInformations.addProductToBasket("Toto", 1000) // Promo = false
1313
expect(basketInformations.getBasketPrice(false)).toBe(1000);
1414
});
1515

0 commit comments

Comments
 (0)