From 93d734279044110eab2f9ef38bfa4b7ef9e59593 Mon Sep 17 00:00:00 2001 From: "lightwalker.eth" <126201998+lightwalker-eth@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:44:43 +0400 Subject: [PATCH] fix: transfer tests for buildTimePeriod --- src/time.test.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/time.test.ts b/src/time.test.ts index f6e4319..389424d 100644 --- a/src/time.test.ts +++ b/src/time.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; -import { buildTimestamp, buildTimestampMs, fromTimestampToDate, msToSeconds, now } from "./time"; +import { addSeconds, buildTimePeriod, buildTimestamp, buildTimestampMs, fromTimestampToDate, msToSeconds, now } from "./time"; describe("msToSeconds() function", () => { it("Correctly returns 0s for less than 1000ms params", () => { @@ -70,3 +70,28 @@ describe("fromTimestampToDate() function", () => { ); }); }); + +describe("buildTimePeriod function", () => { + it("Correctly creates new TimePeriod", () => { + const nowTime = now(); + const period = buildTimePeriod(nowTime, addSeconds(nowTime, 1000n)); + + expect(period.begin).toStrictEqual(nowTime); + expect(period.end).toStrictEqual(addSeconds(nowTime, 1000n)); + }); + + it("Correctly creates new TimePeriod when both Timestamps are equal", () => { + const nowTime = now(); + const period = buildTimePeriod(nowTime, nowTime); + + expect(period.begin).toStrictEqual(nowTime); + expect(period.end).toStrictEqual(nowTime); + }); + + it("Throws error on smaller end Timestamp provided", () => { + const nowTime = now(); + expect(() => { + buildTimePeriod(addSeconds(nowTime, 1000n), nowTime); + }).toThrow(); + }); +}); \ No newline at end of file