Skip to content

Commit

Permalink
feat: add getBarcode test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mssoheil committed Sep 17, 2020
1 parent 709b83c commit 9a5a830
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/modules/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Bill {
billId: string;
billPayment: string;

constructor(billId: number, paymentId: number, currency?: Currency) {
constructor(billId: number | string, paymentId: number | string, currency?: Currency) {
this.barcode = null;
this.currency = currency || "toman";
this.billId = "";
Expand Down Expand Up @@ -89,15 +89,7 @@ class Bill {
}

public getBarcode(): string {
const width = 13;
const padding = "0";

const billPayment = String(this.billId);
let lpadBillPayment = billPayment.slice();

if (billPayment.length < width) lpadBillPayment = padding.repeat(width - billPayment.length) + billPayment;

return this.billId + "" + lpadBillPayment;
return this.billId + "000" + this.billPayment;
}
public findByBarcode(): void {
if (this.barcode) {
Expand Down
7 changes: 7 additions & 0 deletions test/bill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ describe("bill", () => {
expect(new Bill(2050327604613, 1070189, "rial").getData().isValid).toEqual(true);
expect(new Bill(2234322344613, 1070189, "rial").getData().isValid).toEqual(false);
});

it("getBarcode", () => {
expect(new Bill(7748317800142, 1770160, "rial").getData().barcode).toEqual("77483178001420001770160");
expect(new Bill(9174639504124, 12908197, "rial").getData().barcode).toEqual("917463950412400012908197");
expect(new Bill(2050327604613, 1070189, "rial").getData().barcode).toEqual("20503276046130001070189");
expect(new Bill(2234322344613, 1070189, "rial").getData().barcode).toEqual("22343223446130001070189");
});
});

0 comments on commit 9a5a830

Please sign in to comment.