diff --git a/integration/testdata/set_create_operation/tests.test.ts b/integration/testdata/set_create_operation/tests.test.ts index cd76d1b08..efed0985e 100644 --- a/integration/testdata/set_create_operation/tests.test.ts +++ b/integration/testdata/set_create_operation/tests.test.ts @@ -1,6 +1,6 @@ import { actions, resetDatabase, models } from "@teamkeel/testing"; import { test, expect, beforeEach } from "vitest"; -import { ThingType } from "@teamkeel/sdk"; +import { ThingType, Duration } from "@teamkeel/sdk"; beforeEach(resetDatabase); @@ -160,14 +160,14 @@ test("duration set attribute on required field - set to P1D - is P1D", async () test("duration set attribute from explicit input - set to P2D - is P2D", async () => { const thing = await actions.createDurationFromExplicitInput({ - explDuration: "P2D", + explDuration: Duration.fromISOString("P2D") }); expect(thing.requiredDuration).toEqual("P2D"); }); test("duration set attribute from implicit input - set to P2D - is P2D", async () => { const thing = await actions.createDurationFromImplicitInput({ - requiredDuration: "P2D", + requiredDuration: Duration.fromISOString("P2D"), }); expect(thing.optionalDuration).toEqual("P2D"); expect(thing.requiredDuration).toEqual("P2D"); diff --git a/packages/testing-runtime/src/Executor.mjs b/packages/testing-runtime/src/Executor.mjs index 4ad6bf4da..3b694c50e 100644 --- a/packages/testing-runtime/src/Executor.mjs +++ b/packages/testing-runtime/src/Executor.mjs @@ -1,5 +1,5 @@ import jwt from "jsonwebtoken"; -import { InlineFile, File } from "@teamkeel/functions-runtime"; +import { InlineFile, File, Duration } from "@teamkeel/functions-runtime"; export class Executor { constructor(props) { @@ -128,7 +128,9 @@ async function parseInputs(inputs) { if (inputs != null && typeof inputs === "object") { for (const keys of Object.keys(inputs)) { if (inputs[keys] !== null && typeof inputs[keys] === "object") { - if (isInlineFileOrFile(inputs[keys])) { + if (isDuration(inputs[keys])) { + inputs[keys] = inputs[keys].toISOString(); + } else if (isInlineFileOrFile(inputs[keys])) { const contents = await inputs[keys].read(); inputs[keys] = `data:${inputs[keys].contentType};name=${ inputs[keys].filename @@ -150,6 +152,10 @@ function isInlineFileOrFile(obj) { ); } +function isDuration(obj) { + return obj && typeof obj === "object" && obj.constructor.name === "Duration"; +} + function parseOutputs(data) { if (!data) { return null;