diff --git a/apps/server/src/services/script.spec.ts b/apps/server/src/services/script.spec.ts index f94c93f26..da6978666 100644 --- a/apps/server/src/services/script.spec.ts +++ b/apps/server/src/services/script.spec.ts @@ -59,7 +59,7 @@ describe("Script", () => { }); }); - describe("dayjs", () => { + describe("dayjs in backend scripts", () => { const scriptNote = note("dayjs", { type: "code", mime: "application/javascript;env=backend", @@ -74,7 +74,7 @@ describe("Script", () => { }); }); - it("dayjs is-same-or-before", () => { + it("dayjs is-same-or-before plugin exists", () => { cls.init(() => { const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").isSameOrBefore(api.dayjs("2023-10-02"));`); expect(bundle).toBeDefined(); @@ -82,33 +82,5 @@ describe("Script", () => { expect(result).toBe(true); }); }); - - it("dayjs is-same-or-after", () => { - cls.init(() => { - const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-02").isSameOrAfter(api.dayjs("2023-10-01"));`); - expect(bundle).toBeDefined(); - const result = executeBundle(bundle!); - expect(result).toBe(true); - }); - }); - - it("dayjs is-between", () => { - cls.init(() => { - const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-02").isBetween(api.dayjs("2023-10-01"), api.dayjs("2023-10-03"));`); - expect(bundle).toBeDefined(); - const result = executeBundle(bundle!); - expect(result).toBe(true); - }); - }); - - // advanced format - it("dayjs advanced format", () => { - cls.init(() => { - const bundle = getScriptBundle(scriptNote.note, true, "backend", [], `return api.dayjs("2023-10-01").format("Q");`); - expect(bundle).toBeDefined(); - const result = executeBundle(bundle!); - expect(result).not.toBe("Q"); - }); - }); }); }); diff --git a/packages/commons/src/lib/dayjs.spec.ts b/packages/commons/src/lib/dayjs.spec.ts index 43e3581a1..7e8f41a55 100644 --- a/packages/commons/src/lib/dayjs.spec.ts +++ b/packages/commons/src/lib/dayjs.spec.ts @@ -1,5 +1,5 @@ import { LOCALES } from "./i18n.js"; -import { DAYJS_LOADER } from "./dayjs.js"; +import { DAYJS_LOADER, dayjs } from "./dayjs.js"; describe("dayjs", () => { it("all dayjs locales are valid", async () => { @@ -10,4 +10,22 @@ describe("dayjs", () => { await dayjsLoader(); } }); + + describe("Plugins", () => { + it("is-same-or-before is available", () => { + expect(dayjs("2023-10-01").isSameOrBefore(dayjs("2023-10-02"))).toBe(true); + }); + + it("is-same-or-after is available", () => { + expect(dayjs("2023-10-02").isSameOrAfter(dayjs("2023-10-01"))).toBe(true); + }); + + it("is-between is available", () => { + expect(dayjs("2023-10-02").isBetween(dayjs("2023-10-01"), dayjs("2023-10-03"))).toBe(true); + }); + + it("advanced format is available", () => { + expect(dayjs("2023-10-01").format("Q")).not.toBe("Q"); + }); + }); });