Skip to content

Commit

Permalink
test: update test action executor
Browse files Browse the repository at this point in the history
  • Loading branch information
RutZap committed Jan 17, 2025
1 parent d8ee975 commit 1db993a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions integration/testdata/set_create_operation/tests.test.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -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");
Expand Down
10 changes: 8 additions & 2 deletions packages/testing-runtime/src/Executor.mjs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 1db993a

Please sign in to comment.