add cart calculation tests
This commit is contained in:
parent
c08b1a95be
commit
40a61e888e
37
src/pages/dashboard/Content/Tariffs/cartCalcs.test.ts
Normal file
37
src/pages/dashboard/Content/Tariffs/cartCalcs.test.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { Cart } from "../../../../model/cart";
|
||||||
|
import { Tariffs } from "../../../../model/tariff";
|
||||||
|
import { User } from "../../../../model/user";
|
||||||
|
import { exampleCartValues } from "../../../../stores/mocks/exampleCartValues";
|
||||||
|
import { calcCartData } from "./cartCalcs";
|
||||||
|
|
||||||
|
|
||||||
|
function findPrivilegeById(id: string) {
|
||||||
|
const privilege = exampleCartValues.privileges.find(privilege => privilege.privilegeId === id);
|
||||||
|
if (!privilege) throw new Error(`Privilege not found with id ${id}`);
|
||||||
|
|
||||||
|
return privilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("cart tests", () => {
|
||||||
|
it("test case 1", () => {
|
||||||
|
const user: User = exampleCartValues.testCases[0].input.UserInformation;
|
||||||
|
const tariffs: Tariffs.Tariff[] = exampleCartValues.testCases[0].input.Products.map((testProduct) => ({
|
||||||
|
amount: testProduct.Amount,
|
||||||
|
customPrice: testProduct.Price,
|
||||||
|
privilege: findPrivilegeById(testProduct.ID)
|
||||||
|
}));
|
||||||
|
const cartItems: Cart.CartItem[] = tariffs.map(tariff => {
|
||||||
|
const pricePerUnit = tariff.customPrice ?? tariff.privilege.price;
|
||||||
|
const price = pricePerUnit * tariff.amount;
|
||||||
|
|
||||||
|
const cartItem: Cart.CartItem = {
|
||||||
|
item: tariff,
|
||||||
|
price,
|
||||||
|
};
|
||||||
|
|
||||||
|
return cartItem;
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user