1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { TEST_API } from "https://esm.town/v/stevekrouse/TEST_API";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export async function testMutateSemantics2({
stateName,
mutateExpected,
expected,
mutator,
authenticated,
}: {
stateName: string;
mutateExpected?: boolean;
expected?: (old, next) => boolean;
mutator: (x: number) => string;
authenticated: boolean;
}) {
const { data: last } = await fetchJSON(
`${TEST_API}/eval/${stateName}`
);
const now = Date.now();
await fetchJSON(
`${TEST_API}/eval/${mutator(now)}`
);
const { data: next } = await fetchJSON(
`${TEST_API}/eval/${stateName}`
);
const mutated = next === now;
const passed = expected
? expected(last, next)
: (mutateExpected && mutated) || (!mutateExpected && !mutated);
return `${passed ? "✅" : "❌"} ${stateName} ${
mutated ? "set to" : "remains"
} ${JSON.stringify(next)}`;
}