Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const EmbeddedObject = {
anEnumArray: ["option1", "option2", "option3"],
anIntArray: [1, 2, 3],
aDate: "2024-07-23T16:03:34.000Z",
aDateArray: [
"2024-07-23T16:03:34.000Z",
"2024-08-23T16:03:35.000Z",
"2024-09-23T16:03:36.000Z",
]
};

const inputBufferString = "Hello 🌍 World!🌍";
Expand Down Expand Up @@ -81,6 +86,30 @@ export function test() {
}
});

Test.group("schema v1-draft mutating object", () => {
let input = JSON.stringify(EmbeddedObject);
let output: typeof EmbeddedObject = Test.call("mutateObject", input).json();
Test.assertEqual('has bools', output.aBoolArray.length, 3)
output.aBoolArray.forEach((b, i) => {
Test.assertEqual(`inverted ${b}`, b, !EmbeddedObject.aBoolArray[i])
})

Test.assertEqual('has strings', output.aStringArray.length, 3)
output.aStringArray.forEach((b, i) => {
Test.assertEqual(`mutated ${b}`, b, `hello ${EmbeddedObject.aStringArray[i]}`)
})

Test.assertEqual('has ints', output.anIntArray.length, 3)
output.anIntArray.forEach((b, i) => {
Test.assertEqual(`mutated ${b}`, b, EmbeddedObject.anIntArray[i] + 1)
})

Test.assertEqual('has dates', output.aDateArray.length, 3)
output.aDateArray.forEach((b, i) => {
Test.assertEqual(`one second added ${b}`, b, new Date((new Date(EmbeddedObject.aDateArray[i]).getTime() + 1000)).toISOString())
})
});

Test.group("check signature and type variations", () => {
// should call a the `noInputWithOutputHost` host function passing it
// a string "noInputWithOutputHost" which it should return
Expand Down
24 changes: 24 additions & 0 deletions schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ exports:
source: |
input.aBuffer = input.aBuffer.replace(b"Hello", b"Goodbye"); return input

mutateObject:
description: |
This function takes an EmbeddedObject and mutates it. It tests that
types are properly cast to their language equivalents
codeSamples:
- lang: typescript
source: |
input.aBoolArray = input.aBoolArray.map(v => !v)
input.aStringArray = input.aStringArray.map(v => `hello ${v}`)
input.anIntArray = input.anIntArray.map(v => v + 1)
input.aDateArray = input.aDateArray.map(v => new Date(v.getTime() + 1000)) // add one second
return input
input:
contentType: application/json
$ref: "#/components/schemas/EmbeddedObject"
output:
contentType: application/json
$ref: "#/components/schemas/EmbeddedObject"
imports:
reflectJsonObjectHost:
description: |
Expand Down Expand Up @@ -352,6 +370,12 @@ components:
type: array
items:
type: integer
aDateArray:
description: a date array
type: array
items:
type: string
format: date-time
aDate:
description: a date
type: string
Expand Down