Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

rpc.test.ts

31 lines1.2 KB

1import { describe, expect, it } from "vite-plus/test";
2import * as Exit from "effect/Exit";
3import * as Schema from "effect/Schema";
4​
5import { WsSubscribeServerConfigRpc } from "./rpc.ts";
6​
7/**
8 * The client always sends `environmentThemes`, including to servers built
9 * before the field existed, whose payload schema was an empty struct. What
10 * makes that safe is that such a schema accepts the request rather than
11 * rejecting it -- an error here would take down the config subscription.
12 */
13describe("subscribeServerConfig payload compatibility", () => {
14 it("is accepted by a server whose schema predates the field", () => {
15 const oldServerPayload = Schema.Struct({});
16 const decoded = Schema.decodeExit(oldServerPayload)({ environmentThemes: true });
17 expect(Exit.isSuccess(decoded)).toBe(true);
18 });
19​
20 it("is carried by a server that declares it", () => {
21 const decoded = Schema.decodeSync(WsSubscribeServerConfigRpc.payloadSchema)({
22 environmentThemes: true,
23 });
24 expect(decoded).toEqual({ environmentThemes: true });
25 });
26​
27 it("stays optional, so a client that never sends it still subscribes", () => {
28 const decoded = Schema.decodeSync(WsSubscribeServerConfigRpc.payloadSchema)({});
29 expect(decoded).toEqual({});
30 });
31});