Skip to content
Myr

client-today.test.ts

This file

Path

apps/web/test/client-today.test.ts

131 lines · 4.2 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take it

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 1–28why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { DecisionSubject } from "@repo/protocol/domain/decision";3import { Unauthenticated } from "@repo/protocol/principal";4import { Array, DateTime, Effect, Exit, Option, Schema } from "effect";56import { keys } from "../src/client/keys.ts";7import { ContractsClient } from "../src/surfaces.ts";8import { DECIDER, registryAs, seededWorld, settled } from "./dev-browser.ts";910const todayAtom = ContractsClient.query(11 "today",12 {},13 { reactivityKeys: keys.today() }14);1516describe("Today, through the web's atoms", seededWorld, () => {17 it.live("keeps Today from an anonymous browser", () =>18 Effect.gen(function* () {19 const anonymous = yield* settled(registryAs(), todayAtom);2021 const refused = Exit.isFailure(anonymous)22 ? Option.getOrUndefined(Exit.findErrorOption(anonymous))23 : undefined;2425 expect(Schema.is(Unauthenticated)(refused)).toBeTruthy();26 })27 );28

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 29why, one step back
29 it.live("shows the maintainer their Today, with the seed's decisions", () =>

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 30–51why, one step back
30 Effect.gen(function* () {
31 const today = yield* settled(registryAs(DECIDER), todayAtom);3233 expect(34 Exit.isSuccess(today)35 ? {36 budget: today.value.budget,37 decider: today.value.decider,38 newcomers: today.value.newcomers,39 projects: Array.dedupe(40 today.value.decisions.map(({ project }) => project)41 ),42 subjects: today.value.decisions43 .map(({ subject }) => subject._tag)44 .toSorted(),45 unattended: today.value.unattended.map(({ ask }) => ask),46 }47 : undefined48 ).toStrictEqual({49 budget: { finishes: 0, total: 5, used: 2 },50 decider: "ines-v",51 newcomers: ["bram"],

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 52why, one step back
52 projects: ["oscabriel/datekit"],

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 53–58why, one step back
53 subjects: ["OpenProposal", "OpenProposal", "StrayPush"],
54 unattended: ["diff-in-days-dst"],55 });56 })57 );58

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

lines 59–60why, one step back
59 // The page's atoms live in a registry of the page's own (`SeededAtoms`),
60 // the rail's in the root's: a decision taken on the page refetches both.

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 61why, one step back
61 it.live(

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 62why, one step back
62 "closes a decision the maintainer declines, and Today refetches without it, on the page and in the rail",

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 63–65why, one step back
63 () =>
64 Effect.gen(function* () {65 const registry = registryAs(DECIDER);

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

line 66why, one step back
66 const rail = registryAs(DECIDER);

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 67why, one step back
67 const unmount = registry.mount(todayAtom);

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

line 68why, one step back
68 const unmountRail = rail.mount(todayAtom);

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 69why, one step back
69 const before = yield* settled(registry, todayAtom);

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

lines 70–71why, one step back
70 // Read in the rail before the decision, so a refetch is what changes it.
71 yield* settled(rail, todayAtom);

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 72–106why, one step back
72
73 const proposal = Exit.isSuccess(before)74 ? before.value.decisions.find(({ subject }) =>75 DecisionSubject.guards.OpenProposal(subject)76 )77 : undefined;7879 expect(proposal).toBeDefined();8081 if (proposal === undefined) {82 return;83 }8485 const decide = ContractsClient.mutation("decide");8687 registry.set(decide, {88 payload: {89 choice: "decline",90 decision: proposal.id,91 project: proposal.project,92 },93 reactivityKeys: [...keys.today(), ...keys.project(proposal.project)],94 });9596 const decided = yield* settled(registry, decide);9798 const taken = Exit.isSuccess(decided)99 ? decided.value.decision.decided100 : undefined;101102 expect(taken?.choice).toBe("decline");103 expect(104 taken === undefined ? undefined : DateTime.formatIso(taken.at)105 ).toBe("2026-10-07T09:21:00.000Z");106

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

lines 107–117why, one step back
107 const todayIn = (where: typeof registry) =>
108 Effect.map(settled(where, todayAtom), (today) =>109 Exit.isSuccess(today)110 ? {111 holds: today.value.decisions.some(112 ({ id }) => id === proposal.id113 ),114 used: today.value.budget.used,115 }116 : undefined117 );

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 118why, one step back
118

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

lines 119–125why, one step back
119 expect({
120 page: yield* todayIn(registry),121 rail: yield* todayIn(rail),122 }).toStrictEqual({123 page: { holds: false, used: 3 },124 rail: { holds: false, used: 3 },125 });

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 126–127why, one step back
126
127 unmount();

Merge fix/w12-reviewoscabrielbefore adoption7b8b393

line 128why, one step back
128 unmountRail();

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

lines 129–131why, one step back
129 })
130 );131});