| @@ -4,7 +4,7 @@ · 3 unmodified lines |
| 4 | 4 | // single org. |
| 5 | 5 | |
| 6 | 6 | import { describe, expect, it } from "@effect/vitest"; |
| 7 | | −import { Effect } from "effect"; |
| 7 | +import { Effect, Result, Schema } from "effect"; |
| 8 | 8 | import http from "node:http"; |
| 9 | 9 | import { readFileSync } from "node:fs"; |
| 10 | 10 | import type { AddressInfo } from "node:net"; |
| @@ -173,6 +173,11 @@ const GRAPHQL_INTROSPECTION_RESPONSE = { · 162 unmodified lines |
| 173 | 173 | }, |
| 174 | 174 | }; |
| 175 | 175 | |
| 176 | +const GraphqlRequestSchema = Schema.Struct({ |
| 177 | + query: Schema.optional(Schema.String), |
| 178 | + variables: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), |
| 179 | +}); |
| 180 | + |
| 176 | 181 | const startGraphqlServer = () => { |
| 177 | 182 | const requests: Array<{ readonly query: string; readonly variables: unknown }> = []; |
| 178 | 183 | const server = http.createServer(async (req, res) => { |
| @@ -182,10 +187,9 @@ const startGraphqlServer = () => { · 3 unmodified lines |
| 182 | 187 | return; |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | | − const parsed = JSON.parse(await readBody(req)) as { |
| 186 | | − readonly query?: string; |
| 187 | | − readonly variables?: Record<string, unknown>; |
| 188 | | − }; |
| 190 | + const parsed = await Schema.decodeUnknownPromise(Schema.fromJsonString(GraphqlRequestSchema))( |
| 191 | + await readBody(req), |
| 192 | + ); |
| 189 | 193 | const query = parsed.query ?? ""; |
| 190 | 194 | requests.push({ query, variables: parsed.variables ?? null }); |
| 191 | 195 | |
| @@ -411,9 +415,8 @@ describe("sources api (HTTP)", () => { · 219 unmodified lines |
| 411 | 415 | }), |
| 412 | 416 | ); |
| 413 | 417 | |
| 414 | | − if (execution.status !== "completed") { |
| 415 | | − throw new Error(`Expected completed execution, got ${execution.status}`); |
| 416 | | − } |
| 418 | + expect(execution.status).toBe("completed"); |
| 419 | + if (execution.status !== "completed") return; |
| 417 | 420 | expect(execution.isError).toBe(false); |
| 418 | 421 | expect(execution.structured).toMatchObject({ |
| 419 | 422 | status: "completed", |
| @@ -448,7 +451,7 @@ describe("sources api (HTTP)", () => { · 28 unmodified lines |
| 448 | 451 | }) |
| 449 | 452 | .pipe(Effect.result), |
| 450 | 453 | ); |
| 451 | | − expect(addResult._tag).toBe("Failure"); |
| 454 | + expect(Result.isFailure(addResult)).toBe(true); |
| 452 | 455 | |
| 453 | 456 | const fetched = yield* asOrg(org, (client) => |
| 454 | 457 | client.mcp.getSource({ params: { scopeId, namespace } }), |
| @@ -518,9 +521,8 @@ describe("sources api (HTTP)", () => { · 63 unmodified lines |
| 518 | 521 | }), |
| 519 | 522 | ); |
| 520 | 523 | |
| 521 | | − if (execution.status !== "completed") { |
| 522 | | − throw new Error(`Expected completed execution, got ${execution.status}`); |
| 523 | | − } |
| 524 | + expect(execution.status).toBe("completed"); |
| 525 | + if (execution.status !== "completed") return; |
| 524 | 526 | expect(execution.isError).toBe(false); |
| 525 | 527 | expect(execution.structured).toMatchObject({ |
| 526 | 528 | status: "completed", |
| @@ -587,9 +589,8 @@ describe("sources api (HTTP)", () => { · 60 unmodified lines |
| 587 | 589 | }), |
| 588 | 590 | ); |
| 589 | 591 | |
| 590 | | − if (execution.status !== "completed") { |
| 591 | | − throw new Error(`Expected completed execution, got ${execution.status}`); |
| 592 | | − } |
| 592 | + expect(execution.status).toBe("completed"); |
| 593 | + if (execution.status !== "completed") return; |
| 593 | 594 | expect(execution.isError).toBe(false); |
| 594 | 595 | expect(execution.structured).toMatchObject({ |
| 595 | 596 | status: "completed", |
| @@ -635,7 +636,7 @@ describe("sources api (HTTP)", () => { · 39 unmodified lines |
| 635 | 636 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: ghost } }) |
| 636 | 637 | .pipe(Effect.result), |
| 637 | 638 | ); |
| 638 | | − expect(result._tag).toBe("Success"); |
| 639 | + expect(Result.isSuccess(result)).toBe(true); |
| 639 | 640 | }), |
| 640 | 641 | ); |
| 641 | 642 | |
| @@ -651,7 +652,7 @@ describe("sources api (HTTP)", () => { · 9 unmodified lines |
| 651 | 652 | .remove({ params: { scopeId: ScopeId.make(org), sourceId: "openapi" } }) |
| 652 | 653 | .pipe(Effect.result), |
| 653 | 654 | ); |
| 654 | | − expect(result._tag).toBe("Failure"); |
| 655 | + expect(Result.isFailure(result)).toBe(true); |
| 655 | 656 | }), |
| 656 | 657 | ); |
| 657 | 658 | |