Skip to content

Commit

Permalink
feat: add test for uncovered lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mssoheil committed Sep 18, 2020
1 parent 3768ed1 commit 70f0577
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/modules/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ interface IBillData {
}

interface Params {
billId: number | string;
paymentId: number | string;
billId?: number | string;
paymentId?: number | string;
currency?: Currency;
barcode?: string;
}

class Bill {
Expand All @@ -47,8 +48,8 @@ class Bill {
billId: string;
billPayment: string;

constructor({ billId, paymentId, currency }: Params) {
this.barcode = null;
constructor({ billId, paymentId, currency, barcode }: Params) {
this.barcode = barcode || null;
this.currency = currency || "toman";
this.billId = "";
this.billPayment = "";
Expand Down Expand Up @@ -99,7 +100,7 @@ class Bill {
public findByBarcode(): void {
if (this.barcode) {
this.billId = this.barcode.substr(0, 13);
this.billPayment = this.barcode.split(this.billId)[1];
this.billPayment = this.barcode.substr(16, 10);
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/bill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe("bill", () => {
expect(
new Bill({ billId: 7748317800142, paymentId: 1770160, currency: "rial" }).getData().isValidBillPayment,
).toEqual(true);
expect(new Bill({ billId: 7748317800142, currency: "rial" }).getData().isValidBillPayment).toEqual(false);
expect(
new Bill({ billId: 9174639504124, paymentId: 12908197, currency: "rial" }).getData().isValidBillPayment,
).toEqual(false);
Expand Down Expand Up @@ -86,4 +87,17 @@ describe("bill", () => {
"22343223446130001070189",
);
});

it("getBarcode", () => {
const newBill = new Bill({});
newBill.setBarcode("22343223446130001070189");
expect(newBill.barcode).toEqual("22343223446130001070189");
});

it("findByBarcode", () => {
const newBill = new Bill({ barcode: "22343223446130001070189" });
newBill.findByBarcode();
expect(newBill.billId).toEqual("2234322344613");
expect(newBill.billPayment).toEqual("1070189");
});
});

0 comments on commit 70f0577

Please sign in to comment.