Skip to content

Commit b2a67bc

Browse files
authored
Merge pull request #71 from code0-tech/feat/#67
If no startingNodeId is provided it should result in a validation error
2 parents e54fb78 + b32a2a2 commit b2a67bc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/validation/getFlowValidation.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ export const getFlowValidation = (
1212
): ValidationResult => {
1313

1414

15+
if (!flow?.startingNodeId) {
16+
return {
17+
isValid: false,
18+
returnType: "void",
19+
diagnostics: [{
20+
nodeId: null,
21+
parameterIndex: null,
22+
code: 0,
23+
message: "You need to provide a starting node to be able to execute this flow.",
24+
severity: "error",
25+
}]
26+
}
27+
}
28+
29+
if (!flow.nodes?.nodes?.find(n => n?.id == flow.startingNodeId)) {
30+
return {
31+
isValid: false,
32+
returnType: "void",
33+
diagnostics: [{
34+
nodeId: null,
35+
parameterIndex: null,
36+
code: 0,
37+
message: "The starting node is not linked within the flow. Please make sure the starting node is connected to the rest of the flow.",
38+
severity: "error",
39+
}]
40+
}
41+
}
42+
1543
const sourceCode = generateFlowSourceCode(flow, functions, dataTypes);
1644

1745
// 3. Virtual TypeScript Compilation

test/flowValidation.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('getFlowValidation - Integrationstest', () => {
88
it('1', () => {
99

1010
const flow: Flow = {
11+
startingNodeId: "gid://sagittarius/NodeFunction/1",
1112
nodes: {
1213
nodes: [
1314
{
@@ -51,7 +52,7 @@ describe('getFlowValidation - Integrationstest', () => {
5152
__typename: "ReferenceValue",
5253
nodeFunctionId: "gid://sagittarius/NodeFunction/2",
5354
parameterIndex: 1,
54-
inputIndex: 0, //TODO: Das wird gerade einfach nicht berücksichtigt
55+
inputIndex: 0,
5556
referencePath: [{path: "test"}]
5657
}
5758
},
@@ -149,6 +150,7 @@ describe('getFlowValidation - Integrationstest', () => {
149150
it('4', () => {
150151

151152
const flow: Flow = {
153+
startingNodeId: "gid://sagittarius/NodeFunction/1",
152154
nodes: {
153155
nodes: [
154156
{
@@ -198,6 +200,7 @@ describe('getFlowValidation - Integrationstest', () => {
198200
it('5', () => {
199201

200202
const flow: Flow = {
203+
startingNodeId: "gid://sagittarius/NodeFunction/2",
201204
nodes: {
202205
nodes: [
203206
{

0 commit comments

Comments
 (0)