- Introduced `.prettierrc.json` to enforce consistent code formatting across the project. - Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
authenticatedRequest: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/components/session/authenticatedRequest.vue", () => ({
|
|
authenticatedRequest: mocks.authenticatedRequest,
|
|
}));
|
|
|
|
import {
|
|
getDepartmentSelfServeEnabled,
|
|
setDepartmentSelfServeEnabled,
|
|
} from "@/composables/departmentSelfServeEnabled.js";
|
|
|
|
describe("department self-serve enabled management", () => {
|
|
beforeEach(() => {
|
|
mocks.authenticatedRequest.mockReset();
|
|
});
|
|
|
|
it("gets self-serve enabled status for a department", async () => {
|
|
mocks.authenticatedRequest.mockResolvedValue({
|
|
data: {
|
|
data: {
|
|
enabled: "true",
|
|
},
|
|
},
|
|
});
|
|
|
|
const enabled = await getDepartmentSelfServeEnabled("12");
|
|
|
|
expect(enabled).toBe(true);
|
|
expect(mocks.authenticatedRequest).toHaveBeenCalledWith("/departments/self-serve/enabled?id=12", "GET");
|
|
});
|
|
|
|
it("normalizes false-like enabled responses", async () => {
|
|
mocks.authenticatedRequest.mockResolvedValue({
|
|
data: {
|
|
enabled: 0,
|
|
},
|
|
});
|
|
|
|
const enabled = await getDepartmentSelfServeEnabled(12);
|
|
|
|
expect(enabled).toBe(false);
|
|
});
|
|
|
|
it("updates self-serve enabled status for a department", async () => {
|
|
mocks.authenticatedRequest.mockResolvedValue({
|
|
data: {
|
|
message: "updated",
|
|
},
|
|
});
|
|
|
|
const enabled = await setDepartmentSelfServeEnabled(22, true);
|
|
|
|
expect(enabled).toBe(true);
|
|
expect(mocks.authenticatedRequest).toHaveBeenCalledWith(
|
|
"/departments/self-serve/enabled?id=22&enabled=true",
|
|
"PUT"
|
|
);
|
|
});
|
|
|
|
it("uses response enabled state after update when backend returns it", async () => {
|
|
mocks.authenticatedRequest.mockResolvedValue({
|
|
data: {
|
|
data: {
|
|
enabled: "false",
|
|
},
|
|
},
|
|
});
|
|
|
|
const enabled = await setDepartmentSelfServeEnabled(22, true);
|
|
|
|
expect(enabled).toBe(false);
|
|
expect(mocks.authenticatedRequest).toHaveBeenCalledWith(
|
|
"/departments/self-serve/enabled?id=22&enabled=true",
|
|
"PUT"
|
|
);
|
|
});
|
|
|
|
it("rejects invalid department ids", async () => {
|
|
await expect(getDepartmentSelfServeEnabled(0)).rejects.toThrow("Invalid department id");
|
|
await expect(setDepartmentSelfServeEnabled("abc", true)).rejects.toThrow("Invalid department id");
|
|
expect(mocks.authenticatedRequest).not.toHaveBeenCalled();
|
|
});
|
|
});
|