"use strict";
var import_vitest = require("vitest");
var import_job = require("./job.cjs");
const { deleteRoomMock, roomServiceClientMock } = import_vitest.vi.hoisted(() => ({
  deleteRoomMock: import_vitest.vi.fn(async () => {
  }),
  roomServiceClientMock: import_vitest.vi.fn(function RoomServiceClient() {
    return { deleteRoom: deleteRoomMock };
  })
}));
import_vitest.vi.mock("livekit-server-sdk", () => ({
  RoomServiceClient: roomServiceClientMock
}));
(0, import_vitest.beforeEach)(() => {
  import_vitest.vi.clearAllMocks();
});
function createJobContext(infoOverrides = {}) {
  const room = {
    name: "connected-room",
    on: import_vitest.vi.fn(),
    off: import_vitest.vi.fn(),
    isConnected: false,
    remoteParticipants: /* @__PURE__ */ new Map()
  };
  return new import_job.JobContext(
    {},
    {
      acceptArguments: {
        name: "agent",
        identity: "agent",
        metadata: ""
      },
      job: {
        id: "job-id",
        room: { name: "assigned-room" }
      },
      url: "wss://example.livekit.cloud",
      token: "token",
      workerId: "worker-id",
      ...infoOverrides
    },
    room,
    import_vitest.vi.fn(),
    import_vitest.vi.fn(),
    {}
  );
}
(0, import_vitest.describe)("JobContext.deleteRoom", () => {
  (0, import_vitest.it)("deletes the connected room by default using the job URL and credentials", async () => {
    const ctx = createJobContext({
      apiKey: "api-key",
      apiSecret: "api-secret"
    });
    await ctx.deleteRoom();
    (0, import_vitest.expect)(roomServiceClientMock).toHaveBeenCalledWith(
      "wss://example.livekit.cloud",
      "api-key",
      "api-secret"
    );
    (0, import_vitest.expect)(deleteRoomMock).toHaveBeenCalledWith("connected-room");
  });
  (0, import_vitest.it)("falls back to environment credentials when job credentials are absent", async () => {
    const ctx = createJobContext();
    await ctx.deleteRoom();
    (0, import_vitest.expect)(roomServiceClientMock).toHaveBeenCalledWith(
      "wss://example.livekit.cloud",
      void 0,
      void 0
    );
    (0, import_vitest.expect)(deleteRoomMock).toHaveBeenCalledWith("connected-room");
  });
  (0, import_vitest.it)("deletes the provided room name when specified", async () => {
    const ctx = createJobContext();
    await ctx.deleteRoom("other-room");
    (0, import_vitest.expect)(deleteRoomMock).toHaveBeenCalledWith("other-room");
  });
});
(0, import_vitest.describe)("JobContext fake job (console mode)", () => {
  function createFakeJobContext() {
    const onConnect = import_vitest.vi.fn();
    const room = {
      name: "console-room",
      on: import_vitest.vi.fn(),
      off: import_vitest.vi.fn(),
      isConnected: false,
      remoteParticipants: /* @__PURE__ */ new Map(),
      connect: import_vitest.vi.fn(async () => {
      })
    };
    const ctx = new import_job.JobContext(
      {},
      {
        acceptArguments: { name: "", identity: "console", metadata: "" },
        job: { id: "console-job", room: { name: "console-room" } },
        url: "",
        token: "",
        workerId: "console",
        fakeJob: true
      },
      room,
      onConnect,
      import_vitest.vi.fn(),
      {}
    );
    return { ctx, onConnect, room };
  }
  (0, import_vitest.it)("reports isFakeJob", () => {
    (0, import_vitest.expect)(createFakeJobContext().ctx.isFakeJob).toBe(true);
    (0, import_vitest.expect)(createJobContext().isFakeJob).toBe(false);
  });
  (0, import_vitest.it)("connect() is an idempotent no-op that does not touch the room", async () => {
    const { ctx, onConnect, room } = createFakeJobContext();
    await ctx.connect();
    (0, import_vitest.expect)(onConnect).toHaveBeenCalledTimes(1);
    (0, import_vitest.expect)(room.connect).not.toHaveBeenCalled();
    await ctx.connect();
    (0, import_vitest.expect)(onConnect).toHaveBeenCalledTimes(1);
  });
  (0, import_vitest.it)("deleteRoom() is a no-op", async () => {
    const { ctx } = createFakeJobContext();
    await ctx.deleteRoom();
    (0, import_vitest.expect)(roomServiceClientMock).not.toHaveBeenCalled();
    (0, import_vitest.expect)(deleteRoomMock).not.toHaveBeenCalled();
  });
  (0, import_vitest.it)("initRecording() is a no-op and does not parse the empty URL", async () => {
    const { ctx } = createFakeJobContext();
    await (0, import_vitest.expect)(ctx.initRecording()).resolves.toBeUndefined();
  });
});
//# sourceMappingURL=job.test.cjs.map