PliWould/lib/__tests__/product-test.ts
2024-06-30 19:49:41 -07:00

30 lines
1.0 KiB
TypeScript

import { length } from "enheter";
import { Product } from "../product";
describe("Product tests", () => {
it(`Length product gives correct price for a shorter length`, () => {
const standard = new Product(20, { l: 4, u: "feet" });
const comparison = standard.priceFor({ l: 2, u: "feet" });
expect(comparison).toEqual(10);
});
it(`Length product gives correct price for a longer length`, () => {
const standard = new Product(20, {l: 4, u : "feet"});
const comparison = standard.priceFor({l : 8, u : "feet"});
expect(comparison).toEqual(40);
});
it(`Length product gives correct price if different units`, () => {
const standard = new Product(10, {l: 1, u : "feet"});
const comparison = standard.priceFor({l : 24, u: "inch"});
expect(comparison).toBeCloseTo(20, 4);
});
it("Can convert to/from object", () => {
const standard = new Product(10, {l: 1, u : "feet"});
const obj = standard.asObject;
const back = Product.fromObject(obj);
expect(back).toEqual(standard);
})
});