Skip to content

Commit

Permalink
test: add test for createEventDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
ngshiheng committed Oct 26, 2023
1 parent effda2f commit a153661
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function createEventDescription(record: BondRecord): string {
{ key: "Issue Date", value: record.issue_date },
{ key: "Maturity Date", value: record.maturity_date },
{ key: "SGS Type", value: record.sgs_type },
{ key: "Tenor", value: `${record.auction_tenor} year` },
{ key: "Tenor", value: record.auction_tenor ? `${record.auction_tenor} year` : null },
];

const description = fields
Expand Down
79 changes: 78 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createMonthlyTrigger, getOrCreateCalendar, updateOrCreateAllDayEvent } from "../src/index";
import { BondRecord } from "../src/api";
import { createEventDescription, createMonthlyTrigger, getOrCreateCalendar, updateOrCreateAllDayEvent } from "../src/index";

// Create a mock for ScriptApp
const mockScriptApp = {
Expand Down Expand Up @@ -142,3 +143,79 @@ describe("updateOrCreateAllDayEvent", () => {
expect(mockLogger.log).toHaveBeenCalledWith(`Creating "${title}"`);
});
});

describe("createEventDescription", () => {
it("should create an event description with all provided fields", () => {
const record = {
issue_code: "ABC123",
isin_code: "XYZ987",
ann_date: "2023-10-20",
auction_date: "2023-11-05",
last_day_to_apply: "2023-10-31",
tender_date: "2023-11-01",
issue_date: "2023-11-15",
maturity_date: "2030-11-15",
sgs_type: "Government Bond",
auction_tenor: "5",
};

const expectedDescription = `<b>Allotment Date</b>: 2023-11-01
<b>Announcement Date</b>: 2023-10-20
<b>Auction Date</b>: 2023-11-05
<b>Closing Date</b>: 2023-10-31
<b>ISIN Code</b>: XYZ987
<b>Issue Code</b>: ABC123
<b>Issue Date</b>: 2023-11-15
<b>Maturity Date</b>: 2030-11-15
<b>SGS Type</b>: Government Bond
<b>Tenor</b>: 5 year`;

const description = createEventDescription(record as BondRecord);

expect(description).toBe(expectedDescription);
});

it("should create an event description with missing fields omitted", () => {
const recordWithMissingFields = {
issue_code: "ABC123",
isin_code: "XYZ987",
ann_date: "2023-10-20",
auction_tenor: "5",
};

const expectedDescription = `<b>Announcement Date</b>: 2023-10-20
<b>ISIN Code</b>: XYZ987
<b>Issue Code</b>: ABC123
<b>Tenor</b>: 5 year`;

const description = createEventDescription(recordWithMissingFields as BondRecord);

expect(description).toBe(expectedDescription);
});

it("should create an event description with missing fields omitted", () => {
const recordWithMissingFields = {
issue_code: "ABC123",
isin_code: "XYZ987",
ann_date: "2023-10-20",
auction_tenor: "5",
};

const expectedDescription = `<b>Announcement Date</b>: 2023-10-20
<b>ISIN Code</b>: XYZ987
<b>Issue Code</b>: ABC123
<b>Tenor</b>: 5 year`;

const description = createEventDescription(recordWithMissingFields as BondRecord);

expect(description).toBe(expectedDescription);
});

it("should create an empty description for an empty record", () => {
const emptyRecord = {} as BondRecord;

const description = createEventDescription(emptyRecord);

expect(description).toBe("");
});
});

0 comments on commit a153661

Please sign in to comment.