session.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { afterEach, describe, expect, it, vi } from "vitest";
  2. import ActionType from "#/types/ActionType";
  3. import { Settings, saveSettings } from "../../src/services/settings";
  4. import Session from "../../src/services/session";
  5. const sendSpy = vi.spyOn(Session, "send");
  6. // @ts-expect-error - spying on private function
  7. const setupSpy = vi.spyOn(Session, "_setupSocket").mockImplementation(() => {
  8. // @ts-expect-error - calling a private function
  9. Session._initializeAgent();
  10. });
  11. describe("startNewSession", () => {
  12. afterEach(() => {
  13. sendSpy.mockClear();
  14. setupSpy.mockClear();
  15. });
  16. it("Should start a new session with the current settings", () => {
  17. const settings: Settings = {
  18. LLM_MODEL: "llm_value",
  19. LLM_BASE_URL: "base_url",
  20. AGENT: "agent_value",
  21. LANGUAGE: "language_value",
  22. LLM_API_KEY: "sk-...",
  23. CONFIRMATION_MODE: true,
  24. SECURITY_ANALYZER: "analyzer",
  25. };
  26. const event = {
  27. action: ActionType.INIT,
  28. args: settings,
  29. };
  30. saveSettings(settings);
  31. Session.startNewSession();
  32. expect(setupSpy).toHaveBeenCalledTimes(1);
  33. expect(sendSpy).toHaveBeenCalledWith(JSON.stringify(event));
  34. });
  35. });