testing.test.ts
This file
Path
packages/protocol/test/testing.test.ts
80 lines · 2.3 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–38why, one step back1import { describe, expect, it } from "@effect/vitest";2import { Effect, Exit, Layer } from "effect";3import { RpcTest } from "effect/rpc";45import { Contracts } from "../src/contracts.ts";6import { AskId, Handle, KindName, ProjectName } from "../src/ids.ts";7import { CurrentPrincipal, Principal } from "../src/principal.ts";8import { asPerson, asTester, unanswered } from "../src/testing.ts";910const echoCaller = Layer.mergeAll(11 unanswered,12 Contracts.toLayerHandler("listAsks", () =>13 Effect.gen(function* () {14 const caller = Principal.match(yield* CurrentPrincipal, {15 Anonymous: () => "anyone",16 Person: ({ handle }) => handle,17 });1819 return {20 asks: [21 {22 ask: AskId.make("whoami"),23 blockedBy: [],24 claimed: false,25 kind: KindName.make("fix"),26 territory: ".",27 want: caller,28 },29 ],30 };31 })32 )33);3435const caller = Effect.gen(function* () {36 const client = yield* RpcTest.makeClient(Contracts);3738 const { asks } = yield* client.listAsks({Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 39why, one step back39 project: ProjectName.make("oscabriel/datekit"),Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 40–68why, one step back40 });4142 return asks.map(({ want }) => want);43});4445describe("the test principals", () => {46 it.effect("asPerson runs every call as the person it names", () =>47 Effect.gen(function* () {48 expect(yield* caller).toStrictEqual(["alice"]);49 }).pipe(50 Effect.provide(Layer.mergeAll(echoCaller, asPerson(Handle.make("alice"))))51 )52 );5354 it.effect("asTester runs every call as one person, the tester", () =>55 Effect.gen(function* () {56 expect(yield* caller).toStrictEqual(["tester"]);57 }).pipe(Effect.provide(Layer.mergeAll(echoCaller, asTester)))58 );59});6061describe("the unanswered handlers", () => {62 it.effect(63 "answer only the contracts a test sets up over them; any other call dies",64 () =>65 Effect.gen(function* () {66 const client = yield* RpcTest.makeClient(Contracts);6768 const listed = yield* client.listAsks({Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 69why, one step back69 project: ProjectName.make("oscabriel/datekit"),Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 70–80why, one step back70 });7172 const other = yield* Effect.exit(73 client.credits({ handle: Handle.make("alice") })74 );7576 expect(listed.asks.map(({ want }) => want)).toStrictEqual(["tester"]);77 expect(Exit.hasDies(other)).toBeTruthy();78 }).pipe(Effect.provide(Layer.mergeAll(echoCaller, asTester)))79 );80});