35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const authenticatedRequestMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("@/components/session/authenticatedRequest.vue", () => ({
|
|
authenticatedRequest: authenticatedRequestMock,
|
|
}));
|
|
|
|
import { listShellyRelayOptions } from "@/services/shellyRelayOptions.js";
|
|
|
|
describe("shelly relay options service", () => {
|
|
beforeEach(() => {
|
|
authenticatedRequestMock.mockReset();
|
|
});
|
|
|
|
it("loads relay options from the department lane relay options endpoint", async () => {
|
|
authenticatedRequestMock.mockResolvedValue({
|
|
data: {
|
|
data: [
|
|
{ id: "shelly-plus-01", name: "Entry Gate (shelly-plus-01)" },
|
|
{ id: " ", name: "Invalid" },
|
|
{ id: "shelly-plus-02" },
|
|
],
|
|
},
|
|
});
|
|
|
|
await expect(listShellyRelayOptions()).resolves.toEqual([
|
|
{ id: "shelly-plus-01", name: "Entry Gate (shelly-plus-01)" },
|
|
{ id: "shelly-plus-02", name: "shelly-plus-02" },
|
|
]);
|
|
|
|
expect(authenticatedRequestMock).toHaveBeenCalledWith("/department/lanes/relay-options", "GET", {});
|
|
});
|
|
});
|