Skip to content

Commit 469286e

Browse files
committed
feat: add test for ReferenceValue suggestion in rest::control::respond payload
1 parent 527b02d commit 469286e

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

test/schema/schema.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,73 @@ describe("Schema", () => {
619619
expect(first.schema.input).toBe("text");
620620
});
621621

622+
it('offers a saved object as a ReferenceValue suggestion in rest::control::respond payload', () => {
623+
// Node 1: std::control::value<T>(value: T): T saves an object literal, so its
624+
// return type is an OBJECT.
625+
// Node 2: rest::control::respond
626+
// <S extends HTTP_SCHEMA>(http_status_code, headers: OBJECT<{}>, http_schema: S,
627+
// payload: HTTP_PAYLOAD<S>): void
628+
// With http_schema = "application/json", HTTP_PAYLOAD<S> resolves to OBJECT<{}>.
629+
//
630+
// Node 1 returns an object, which is assignable to OBJECT<{}>, so node 1 must be
631+
// offered as a ReferenceValue suggestion for the payload parameter.
632+
const flow: Flow = {
633+
id: "gid://sagittarius/Flow/1",
634+
startingNodeId: "gid://sagittarius/NodeFunction/1",
635+
signature: "(): void",
636+
nodes: {
637+
nodes: [
638+
{
639+
id: "gid://sagittarius/NodeFunction/1",
640+
functionDefinition: {identifier: "std::control::value"},
641+
nextNodeId: "gid://sagittarius/NodeFunction/2",
642+
parameters: {
643+
nodes: [
644+
{value: {__typename: "LiteralValue", value: {}}},
645+
],
646+
},
647+
},
648+
{
649+
id: "gid://sagittarius/NodeFunction/2",
650+
functionDefinition: {identifier: "rest::control::respond"},
651+
parameters: {
652+
nodes: [
653+
{value: {__typename: "LiteralValue", value: 200}},
654+
{value: {__typename: "LiteralValue", value: {}}},
655+
{value: {__typename: "LiteralValue", value: "application/json"}},
656+
{value: {__typename: "LiteralValue", value: {}}},
657+
],
658+
},
659+
},
660+
],
661+
},
662+
};
663+
664+
const result = getSignatureSchema(
665+
flow,
666+
DATA_TYPES,
667+
FUNCTION_SIGNATURES,
668+
"gid://sagittarius/NodeFunction/2",
669+
);
670+
671+
// payload is the 4th parameter of rest::control::respond.
672+
const payloadSchema = result[3];
673+
674+
// application/json → HTTP_PAYLOAD<S> = OBJECT<{}> → open object input.
675+
expect(payloadSchema.schema.input).toBe("data");
676+
677+
// Node 1 (std::control::value) returns an object assignable to OBJECT<{}>.
678+
// Its return value is a direct reference (no property path).
679+
const suggestions = (payloadSchema.schema.suggestions ?? []) as any[];
680+
expect(suggestions.length).toBeGreaterThan(0);
681+
expect(
682+
suggestions.some(
683+
(s) =>
684+
s.__typename === "ReferenceValue" &&
685+
s.nodeFunctionId === "gid://sagittarius/NodeFunction/1" &&
686+
!s.referencePath,
687+
),
688+
).toBe(true);
689+
});
690+
622691
})

0 commit comments

Comments
 (0)