Skip to content

Commit a8ab4ed

Browse files
committed
test(openapi): add explicit fast-check property
1 parent a603c4e commit a8ab4ed

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

packages/app/tests/docker-git/openapi-effect-client.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as Schema from "@effect/schema/Schema"
2+
import * as ParseResult from "@effect/schema/ParseResult"
23
import { describe, expect, it } from "@effect/vitest"
34
import { createClient } from "@prover-coder-ai/docker-git-openapi"
45
import type { ApiTransportValue } from "@prover-coder-ai/docker-git-openapi"
5-
import { Effect } from "effect"
6+
import { Effect, Either } from "effect"
67
import * as fc from "fast-check"
78

89
type CapturedRequest = {
@@ -39,6 +40,25 @@ const createMockFetch = (
3940
return Effect.runPromise(Effect.succeed(response))
4041
}
4142

43+
/**
44+
* Runs a fast-check synchronous property inside the Effect test runtime.
45+
*
46+
* @param property - Finite pure property over OpenAPI boundary values.
47+
* @returns Effect that fails when fast-check finds a counterexample.
48+
*
49+
* @pure false - executes property samples.
50+
* @effect Effect.sync, fc.assert.
51+
* @invariant success proves every sampled case preserved the asserted pure invariant.
52+
* @precondition property predicate is synchronous and total.
53+
* @postcondition counterexamples are surfaced through the Effect error channel.
54+
* @complexity O(r * c) where r is numRuns and c is one predicate cost.
55+
* @throws Never.
56+
*/
57+
const assertOpenApiClientSyncProperty = <PropertyArgs>(property: fc.IProperty<PropertyArgs>) =>
58+
Effect.sync(() => {
59+
fc.assert(property, { numRuns: 25 })
60+
})
61+
4262
/**
4363
* Runs a fast-check async property inside the Effect test runtime.
4464
*
@@ -91,6 +111,16 @@ describe("docker-git OpenAPI Effect client", () => {
91111
expect(new URL(requests[0]?.url ?? "").searchParams.has("_")).toBe(true)
92112
}))
93113

114+
it.effect("property: schema decoding preserves JSON null transport values", () =>
115+
assertOpenApiClientSyncProperty(
116+
fc.property(fc.constant(null), (value) =>
117+
Either.match(ParseResult.decodeUnknownEither(Schema.Null)(value), {
118+
onLeft: () => false,
119+
onRight: (decoded) => decoded === null
120+
})
121+
)
122+
))
123+
94124
it.effect("property: GET requests always include no-cache transport invariants", () =>
95125
assertOpenApiClientProperty(
96126
fc.asyncProperty(

0 commit comments

Comments
 (0)