remoteServiceAccess.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, it, vi } from "vitest";
  2. import type { IChannel, IChannelClient } from "@zcode/rpc";
  3. import { IMediaPreviewService, IClientConfigService } from "@zcode/services";
  4. import { RemoteServiceAccess } from "../src/remoteServiceAccess.js";
  5. describe("RemoteServiceAccess", () => {
  6. it("公开配置经独立频道 RPC 读取", async () => {
  7. const call = vi.fn(async () => ({ pluginStoreOrder: null }));
  8. const requested: string[] = [];
  9. const services = new RemoteServiceAccess({
  10. getChannel: (name) => {
  11. requested.push(name);
  12. return { call, listen: vi.fn() } as IChannel;
  13. },
  14. });
  15. expect(await services.clientConfigService.getSnapshot({ forceRefresh: true })).toEqual({
  16. pluginStoreOrder: null,
  17. });
  18. expect(requested).toContain("client-config");
  19. expect(call.mock.calls[0]?.slice(0, 2)).toEqual(["getSnapshot", [{ forceRefresh: true }]]);
  20. });
  21. it("creates the media preview proxy for every remote service connection", () => {
  22. const channelNames: string[] = [];
  23. const channel: IChannel = {
  24. call: vi.fn(),
  25. listen: vi.fn(),
  26. };
  27. const channelClient: IChannelClient = {
  28. getChannel: (channelName) => {
  29. channelNames.push(channelName);
  30. return channel;
  31. },
  32. };
  33. const services = new RemoteServiceAccess(channelClient);
  34. expect(channelNames).toContain(IMediaPreviewService.channelName);
  35. expect(services.mediaPreviewService).toBeDefined();
  36. expect(channelNames).toContain(IClientConfigService.channelName);
  37. expect(services.clientConfigService).toBeDefined();
  38. });
  39. });