Skip to content

Commit

Permalink
Merge pull request #45 from Llandy3d/fix-check-block-not-generating-s…
Browse files Browse the repository at this point in the history
…cript

fix checks breaking codegen
  • Loading branch information
allansson authored Mar 7, 2024
2 parents 7919a37 + 76a984a commit ef15570
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/stores/blocks/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function emitStep(step: Step, substitutions: Substitution[]): string {
return `body: (r) => r.body.includes(${JSON.stringify(substitute(check.value, substitutions))})`;
}
})
.join(",")},
.join(",\n")},
})
`;

Expand Down
20 changes: 18 additions & 2 deletions src/lib/stores/blocks/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Environment } from "$lib/backend-client";
import type { HttpRequestStep, Scenario, Step, Test } from "$lib/types";
import type { Check, HttpRequestStep, Scenario, Step, Test } from "$lib/types";
import { exhaustive } from "$lib/utils/typescript";
import { emitScript } from "./codegen";
import type * as loose from "./model/loose";
Expand All @@ -26,6 +26,22 @@ function toHttpRequestStep(model: model.LibraryBlock | model.HttpRequestBlock):
};
}

function toCheck(model: model.Check): Check {
switch (model.type) {
case "status":
return {
type: "has-status",
status: model.value,
};

case "contains":
return {
type: "body-contains",
value: model.value,
};
}
}

function toStep(model: model.StepBlock): Step {
switch (model.type) {
case "group":
Expand All @@ -39,7 +55,7 @@ function toStep(model: model.StepBlock): Step {
return {
type: "check",
target: toHttpRequestStep(model.target),
checks: [],
checks: model.checks.map(toCheck),
};

case "http-request":
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stores/blocks/model/strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Check = Output<typeof check>;

interface CheckBlock extends ChainableBlock {
type: "check";
target: LibraryBlock;
target: LibraryBlock | HttpRequestBlock;
checks: Check[];
next: StepBlock | null;
}
Expand All @@ -141,7 +141,7 @@ const checkBlock: BaseSchema<CheckBlock> = merge([
blockBase,
object({
type: literal("check"),
target: libraryBlock,
target: union([libraryBlock, httpRequestBlock]),
checks: array(check),
next: nullable(lazy(() => stepBlock)),
}),
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ interface Test {

export type {
BodyContainsCheck,
Check,
CheckStep,
Executor,
GroupStep,
Expand Down

0 comments on commit ef15570

Please sign in to comment.