rpc-client-clone.test.ts 840 B

1234567891011121314151617181920212223242526272829
  1. import { describe, expect, it, vi } from "vitest";
  2. import { RpcClient } from "../src/modes/rpc/rpc-client.ts";
  3. type RpcClientPrivate = {
  4. send: (command: { type: string }) => Promise<unknown>;
  5. getData: <T>(response: unknown) => T;
  6. };
  7. describe("RpcClient clone", () => {
  8. it("sends the clone RPC command", async () => {
  9. const client = new RpcClient();
  10. const privateClient = client as unknown as RpcClientPrivate;
  11. const send = vi.fn(async () => ({
  12. type: "response",
  13. command: "clone",
  14. success: true,
  15. data: { cancelled: false },
  16. }));
  17. privateClient.send = send;
  18. privateClient.getData = <T>(response: unknown): T => {
  19. return (response as { data: T }).data;
  20. };
  21. const result = await client.clone();
  22. expect(send).toHaveBeenCalledWith({ type: "clone" });
  23. expect(result).toEqual({ cancelled: false });
  24. });
  25. });