Skip to content

Commit f17c622

Browse files
committed
Use OpenAPI fixture for scripted failure tests
1 parent 60d0a2d commit f17c622

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

packages/plugins/openapi/src/sdk/upstream-failures.test.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212

1313
import { describe, expect, it } from "@effect/vitest";
1414
import { Effect, Exit, Schema } from "effect";
15-
import { FetchHttpClient, HttpServerResponse } from "effect/unstable/http";
16-
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi";
15+
import { FetchHttpClient, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
16+
import {
17+
HttpApi,
18+
HttpApiBuilder,
19+
HttpApiEndpoint,
20+
HttpApiGroup,
21+
OpenApi,
22+
} from "effect/unstable/httpapi";
1723
// The socket-drop and slow-response cases exercise Node transport behavior
1824
// that Effect's in-memory HTTP test server intentionally abstracts away.
1925
import { createServer } from "node:http";
@@ -25,7 +31,8 @@ import {
2531
type InvokeOptions,
2632
type SecretProvider,
2733
} from "@executor-js/sdk";
28-
import { makeTestConfig, serveTestHttpApp } from "@executor-js/sdk/testing";
34+
import { makeTestConfig } from "@executor-js/sdk/testing";
35+
import { serveOpenApiHttpApiTestServer } from "../testing";
2936

3037
import { openApiPlugin } from "./plugin";
3138

@@ -64,18 +71,28 @@ type ResponseScript = (req: {
6471
};
6572

6673
const startScriptedServer = (script: ResponseScript) =>
67-
serveTestHttpApp((request) =>
68-
Effect.sync(() => {
69-
const result = script({
70-
url: request.url,
71-
method: request.method,
72-
headers: request.headers,
73-
});
74-
return HttpServerResponse.text(result.body ?? '{"ok":true}', {
75-
status: result.status ?? 200,
76-
headers: result.headers ?? { "content-type": "application/json" },
77-
});
78-
}),
74+
serveOpenApiHttpApiTestServer({
75+
api: FailureApi,
76+
handlersLayer: HttpApiBuilder.group(FailureApi, "things", (handlers) =>
77+
handlers.handle("listThings", () =>
78+
Effect.gen(function* () {
79+
const request = yield* HttpServerRequest.HttpServerRequest;
80+
const result = script({
81+
url: request.url,
82+
method: request.method,
83+
headers: request.headers,
84+
});
85+
return HttpServerResponse.text(result.body ?? '{"ok":true}', {
86+
status: result.status ?? 200,
87+
headers: result.headers ?? { "content-type": "application/json" },
88+
});
89+
}),
90+
),
91+
),
92+
}).pipe(
93+
Effect.map((server) => ({
94+
baseUrl: server.baseUrl,
95+
})),
7996
);
8097

8198
const startDroppingServer = () =>

0 commit comments

Comments
 (0)