From 578e985f05bd88883478f8b57e73251fe6962b3a Mon Sep 17 00:00:00 2001 From: Radu Gruia Date: Tue, 21 Jan 2025 13:32:53 +0000 Subject: [PATCH] test: add duration instantiation test --- .../functions-runtime/src/Duration.test.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/functions-runtime/src/Duration.test.js diff --git a/packages/functions-runtime/src/Duration.test.js b/packages/functions-runtime/src/Duration.test.js new file mode 100644 index 000000000..080b5b8c9 --- /dev/null +++ b/packages/functions-runtime/src/Duration.test.js @@ -0,0 +1,34 @@ +import { test, expect } from "vitest"; +const { Duration } = require("./Duration"); + +test("fromISOString test", async () => { + const fullDate = Duration.fromISOString("P1Y2M3DT4H5M6S"); + expect(fullDate.toISOString()).toEqual("P1Y2M3DT4H5M6S"); + expect(fullDate.toPostgres()).toEqual( + "1 years 2 months 3 days 4 hours 5 minutes 6 seconds" + ); + const dateOnly = Duration.fromISOString("P2Y3M4D"); + expect(dateOnly.toISOString()).toEqual("P2Y3M4D"); + expect(dateOnly.toPostgres()).toEqual("2 years 3 months 4 days"); + const timeOnly = Duration.fromISOString("PT4H5M6S"); + expect(timeOnly.toISOString()).toEqual("PT4H5M6S"); + expect(timeOnly.toPostgres()).toEqual("4 hours 5 minutes 6 seconds"); + const years = Duration.fromISOString("P10Y"); + expect(years.toISOString()).toEqual("P10Y"); + expect(years.toPostgres()).toEqual("10 years"); + const months = Duration.fromISOString("P20M"); + expect(months.toISOString()).toEqual("P20M"); + expect(months.toPostgres()).toEqual("20 months"); + const days = Duration.fromISOString("P31D"); + expect(days.toISOString()).toEqual("P31D"); + expect(days.toPostgres()).toEqual("31 days"); + const hours = Duration.fromISOString("PT4H"); + expect(hours.toISOString()).toEqual("PT4H"); + expect(hours.toPostgres()).toEqual("4 hours"); + const minutes = Duration.fromISOString("PT61M"); + expect(minutes.toISOString()).toEqual("PT61M"); + expect(minutes.toPostgres()).toEqual("61 minutes"); + const seconds = Duration.fromISOString("PT76S"); + expect(seconds.toISOString()).toEqual("PT76S"); + expect(seconds.toPostgres()).toEqual("76 seconds"); +});