Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
60f68eb
Refactor tests to mock API responses
dileepapeiris Feb 17, 2026
373a1d6
Remove mock mode and simplify MockConfigProvider
dileepapeiris Feb 17, 2026
1ed003f
Remove MockConfig usage and update chat
dileepapeiris Feb 17, 2026
a64bd7d
Add case metadata types and update tests
dileepapeiris Feb 17, 2026
7678f2d
Inline test mocks; remove mockFunctions & delay
dileepapeiris Feb 17, 2026
60b1509
Remove mock gating and inline case mocks in tests
dileepapeiris Feb 17, 2026
3c4b09e
Update imports and inline mocks in tests
dileepapeiris Feb 17, 2026
44ca389
Refactor API tests to use AuthApiClient mock
dileepapeiris Feb 17, 2026
dbfeb61
Remove mock helpers; use defaults & inline mocks
dileepapeiris Feb 17, 2026
62dc2e4
Remove mock config and streamline auth flow
dileepapeiris Feb 17, 2026
e5d1d2e
Inline mocks in header tests, remove MockConfig
dileepapeiris Feb 17, 2026
043d2c7
Refactor API tests to use AuthApiClient mock
dileepapeiris Feb 17, 2026
65393d0
Remove mock config and mock API handling
dileepapeiris Feb 17, 2026
af2e725
Remove mock handling from post API hooks
dileepapeiris Feb 17, 2026
9f87c43
Remove mock handling from customer API hooks
dileepapeiris Feb 17, 2026
cd92fe5
Refactor API tests to use AuthApiContext mock
dileepapeiris Feb 17, 2026
9255108
Remove mock logic; use real API and auth
dileepapeiris Feb 17, 2026
10fd85f
Remove mock handling from project API hooks
dileepapeiris Feb 17, 2026
80bfbe2
Remove mock mode from project API hooks
dileepapeiris Feb 17, 2026
cd2b8e5
Remove mock support from API queries
dileepapeiris Feb 17, 2026
e724a7b
Use AuthApiContext mock in project API tests
dileepapeiris Feb 17, 2026
2e50ba8
Refactor API tests to use AuthApiContext mocks
dileepapeiris Feb 17, 2026
6e88495
Remove mock mode from customer-portal API hooks
dileepapeiris Feb 17, 2026
8887d87
Refactor API tests to use AuthApiContext mock
dileepapeiris Feb 17, 2026
1359ef2
Use AuthApiContext mock in API tests
dileepapeiris Feb 17, 2026
879e9c9
Remove mock support from case API hooks
dileepapeiris Feb 17, 2026
302facc
Use AuthApiClient; remove mock config from APIs
dileepapeiris Feb 17, 2026
53c396f
Refactor auth mock in useGetCaseComments test
dileepapeiris Feb 17, 2026
1f45f75
Use hyphen placeholder for case/chat counts
dileepapeiris Feb 17, 2026
ca03ae0
Standardize mock attachment creator email
dileepapeiris Feb 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions apps/customer-portal/webapp/src/AppWithConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { AsgardeoProvider } from "@asgardeo/react";
import { themeConfig } from "@config/themeConfig";
import { loggerConfig } from "@config/loggerConfig";
import LoggerProvider from "@context/logger/LoggerProvider";
import { MockConfigProvider } from "@providers/MockConfigProvider";
import { authConfig } from "@config/authConfig";

const queryClient: QueryClient = new QueryClient();
Expand All @@ -38,16 +37,14 @@ export default function AppWithConfig(): JSX.Element {
scopes={["openid", "email", "groups"]}
storage="localStorage"
>
<MockConfigProvider>
<LoggerProvider config={loggerConfig}>
<OxygenUIThemeProvider theme={themeConfig}>
<QueryClientProvider client={queryClient}>
<App />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</OxygenUIThemeProvider>
</LoggerProvider>
</MockConfigProvider>
<LoggerProvider config={loggerConfig}>
<OxygenUIThemeProvider theme={themeConfig}>
<QueryClientProvider client={queryClient}>
<App />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</OxygenUIThemeProvider>
</LoggerProvider>
</AsgardeoProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import type { ReactNode } from "react";
import { useGetCallRequests } from "@api/useGetCallRequests";
import { mockCallRequests } from "@models/mockData";

const mockCallRequestsResponse = { callRequests: [] };

const mockLogger = {
debug: vi.fn(),
Expand All @@ -43,13 +44,6 @@ vi.mock("@context/AuthApiContext", () => ({
vi.fn().mockImplementation((url, init) => fetch(url, init)),
}));

let mockIsMockEnabled = false;
vi.mock("@/providers/MockConfigProvider", () => ({
useMockConfig: () => ({
isMockEnabled: mockIsMockEnabled,
}),
}));

describe("useGetCallRequests", () => {
let queryClient: QueryClient;
const originalConfig = window.config;
Expand All @@ -68,7 +62,6 @@ describe("useGetCallRequests", () => {
},
},
});
mockIsMockEnabled = false;
mockIsSignedIn = true;
mockIsAuthLoading = false;
vi.clearAllMocks();
Expand All @@ -83,7 +76,7 @@ describe("useGetCallRequests", () => {
});

it("should fetch call requests from API successfully", async () => {
const mockResponse = mockCallRequests;
const mockResponse = mockCallRequestsResponse;
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
Expand All @@ -103,24 +96,11 @@ describe("useGetCallRequests", () => {
);
});

it("should return mock data when isMockEnabled is true", async () => {
mockIsMockEnabled = true;

const { result } = renderHook(() => useGetCallRequests(projectId, caseId), {
wrapper,
});

await waitFor(() => expect(result.current.isSuccess).toBe(true), {
timeout: 2000,
});
expect(result.current.data).toEqual(mockCallRequests);
});

it("should have correct query options", () => {
renderHook(() => useGetCallRequests(projectId, caseId), { wrapper });

const query = queryClient.getQueryCache().findAll({
queryKey: ["case-call-requests", projectId, caseId, false],
queryKey: ["case-call-requests", projectId, caseId],
})[0];

expect((query?.options as { staleTime?: number }).staleTime).toBe(
Expand Down Expand Up @@ -163,7 +143,7 @@ describe("useGetCallRequests", () => {
expect(mockFetch).not.toHaveBeenCalled();
});

it("should not fetch when user is not signed in and mock is disabled", async () => {
it("should not fetch when user is not signed in", async () => {
mockIsSignedIn = false;

const { result } = renderHook(() => useGetCallRequests(projectId, caseId), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ import { renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { describe, it, expect, vi, beforeEach } from "vitest";
import useGetCaseAttachments from "@api/useGetCaseAttachments";
import { mockCaseAttachments } from "@models/mockData";

vi.mock("@constants/apiConstants", async (importOriginal) => {
const actual =
await importOriginal<typeof import("@constants/apiConstants")>();
return {
...actual,
API_MOCK_DELAY: 0,
};
});

const mockAttachmentsResponse = {
attachments: [
{ id: "a1", name: "file.txt", size: 100, createdOn: "", createdBy: "" },
],
totalRecords: 1,
offset: 0,
limit: 50,
};

vi.mock("@asgardeo/react", () => ({
useAsgardeo: () => ({
Expand All @@ -37,10 +36,12 @@ vi.mock("@asgardeo/react", () => ({
}),
}));

const mockUseMockConfig = vi.fn().mockReturnValue({ isMockEnabled: true });

vi.mock("@providers/MockConfigProvider", () => ({
useMockConfig: () => mockUseMockConfig(),
const mockAuthFetch = vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve(mockAttachmentsResponse),
});
vi.mock("@context/AuthApiContext", () => ({
useAuthApiClient: () => mockAuthFetch,
}));

vi.mock("@hooks/useLogger", () => ({
Expand All @@ -59,10 +60,16 @@ describe("useGetCaseAttachments", () => {
beforeEach(() => {
queryClient.clear();
vi.clearAllMocks();
mockUseMockConfig.mockReturnValue({ isMockEnabled: true });
mockAuthFetch.mockResolvedValue({
ok: true,
json: () => Promise.resolve(mockAttachmentsResponse),
});
(window as unknown as { config?: { CUSTOMER_PORTAL_BACKEND_BASE_URL?: string } }).config = {
CUSTOMER_PORTAL_BACKEND_BASE_URL: "https://api.test",
};
});

it("should return mock attachments when isMockEnabled is true", async () => {
it("should return attachments from API", async () => {
const { result } = renderHook(() => useGetCaseAttachments("case-001"), {
wrapper,
});
Expand All @@ -72,9 +79,9 @@ describe("useGetCaseAttachments", () => {
expect(result.current.data).toBeDefined();
expect(result.current.data?.attachments).toBeDefined();
expect(result.current.data?.attachments.length).toBe(
mockCaseAttachments.length,
mockAttachmentsResponse.attachments.length,
);
expect(result.current.data?.totalRecords).toBe(mockCaseAttachments.length);
expect(result.current.data?.totalRecords).toBe(mockAttachmentsResponse.totalRecords);
expect(result.current.data?.offset).toBe(0);
expect(result.current.data?.limit).toBe(50);
});
Expand All @@ -87,12 +94,22 @@ describe("useGetCaseAttachments", () => {
it("should use correct query key", () => {
renderHook(() => useGetCaseAttachments("case-001"), { wrapper });
const query = queryClient.getQueryCache().findAll({
queryKey: ["case-attachments", "case-001", 50, 0, true],
queryKey: ["case-attachments", "case-001", 50, 0],
})[0];
expect(query).toBeDefined();
});

it("should respect limit and offset options when mock is enabled", async () => {
it("should respect limit and offset options", async () => {
const limitedResponse = {
...mockAttachmentsResponse,
limit: 2,
offset: 1,
attachments: mockAttachmentsResponse.attachments.slice(0, 2),
};
mockAuthFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(limitedResponse),
});
const { result } = renderHook(
() => useGetCaseAttachments("case-001", { limit: 2, offset: 1 }),
{ wrapper },
Expand All @@ -103,6 +120,6 @@ describe("useGetCaseAttachments", () => {
expect(result.current.data?.limit).toBe(2);
expect(result.current.data?.offset).toBe(1);
expect(result.current.data?.attachments.length).toBeLessThanOrEqual(2);
expect(result.current.data?.totalRecords).toBe(mockCaseAttachments.length);
expect(result.current.data?.totalRecords).toBe(mockAttachmentsResponse.totalRecords);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

import { renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import useGetCaseComments from "@api/useGetCaseComments";
import { mockCaseComments } from "@models/mockData";

vi.mock("@constants/apiConstants", async (importOriginal) => {
const actual =
await importOriginal<typeof import("@constants/apiConstants")>();
return {
...actual,
API_MOCK_DELAY: 0,
};
});

const mockCommentsResponse = {
comments: [
{ id: "c1", content: "Comment one", type: "comments", createdOn: "", createdBy: "", isEscalated: false },
],
totalRecords: 1,
offset: 0,
limit: 20,
};

vi.mock("@asgardeo/react", () => ({
useAsgardeo: () => ({
Expand All @@ -37,10 +36,10 @@ vi.mock("@asgardeo/react", () => ({
}),
}));

const mockUseMockConfig = vi.fn().mockReturnValue({ isMockEnabled: true });
const mockAuthFetch = vi.fn();

vi.mock("@providers/MockConfigProvider", () => ({
useMockConfig: () => mockUseMockConfig(),
vi.mock("@context/AuthApiContext", () => ({
useAuthApiClient: () => mockAuthFetch,
}));
Comment thread
coderabbitai[bot] marked this conversation as resolved.

vi.mock("@hooks/useLogger", () => ({
Expand All @@ -59,10 +58,20 @@ describe("useGetCaseComments", () => {
beforeEach(() => {
queryClient.clear();
vi.clearAllMocks();
mockUseMockConfig.mockReturnValue({ isMockEnabled: true });
mockAuthFetch.mockResolvedValue({
ok: true,
json: () => Promise.resolve(mockCommentsResponse),
});
(window as unknown as { config?: { CUSTOMER_PORTAL_BACKEND_BASE_URL?: string } }).config = {
CUSTOMER_PORTAL_BACKEND_BASE_URL: "https://api.test",
};
});

afterEach(() => {
mockAuthFetch.mockReset();
});

it("should return mock comments when isMockEnabled is true", async () => {
it("should return comments from API", async () => {
const { result } = renderHook(
() => useGetCaseComments("project-1", "case-001"),
{ wrapper },
Expand All @@ -72,8 +81,8 @@ describe("useGetCaseComments", () => {

expect(result.current.data).toBeDefined();
expect(result.current.data?.comments).toBeDefined();
expect(result.current.data?.comments.length).toBe(mockCaseComments.length);
expect(result.current.data?.totalRecords).toBe(mockCaseComments.length);
expect(result.current.data?.comments.length).toBe(mockCommentsResponse.comments.length);
expect(result.current.data?.totalRecords).toBe(mockCommentsResponse.totalRecords);
expect(result.current.data?.offset).toBe(0);
expect(result.current.data?.limit).toBe(20);
});
Expand All @@ -95,7 +104,7 @@ describe("useGetCaseComments", () => {
it("should use correct query key", () => {
renderHook(() => useGetCaseComments("project-1", "case-001"), { wrapper });
const query = queryClient.getQueryCache().findAll({
queryKey: ["case-comments", "project-1", "case-001", 0, 20, true],
queryKey: ["case-comments", "project-1", "case-001", 0, 20],
})[0];
expect(query).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ import { renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { describe, it, expect, vi, beforeEach } from "vitest";
import useGetCaseDetails from "@api/useGetCaseDetails";
import { mockCaseDetails } from "@models/mockData";

vi.mock("@constants/apiConstants", async (importOriginal) => {
const actual =
await importOriginal<typeof import("@constants/apiConstants")>();
return {
...actual,
API_MOCK_DELAY: 0,
};
});
const mockCaseDetails = {
id: "case-001",
number: "CS0001001",
title: "Application crashes on startup",
};

vi.mock("@asgardeo/react", () => ({
useAsgardeo: () => ({
Expand All @@ -37,10 +33,12 @@ vi.mock("@asgardeo/react", () => ({
}),
}));

const mockUseMockConfig = vi.fn().mockReturnValue({ isMockEnabled: true });

vi.mock("@providers/MockConfigProvider", () => ({
useMockConfig: () => mockUseMockConfig(),
vi.mock("@context/AuthApiContext", () => ({
useAuthApiClient: () =>
vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve(mockCaseDetails),
}),
}));

vi.mock("@hooks/useLogger", () => ({
Expand All @@ -59,10 +57,12 @@ describe("useGetCaseDetails", () => {
beforeEach(() => {
queryClient.clear();
vi.clearAllMocks();
mockUseMockConfig.mockReturnValue({ isMockEnabled: true });
(window as unknown as { config?: { CUSTOMER_PORTAL_BACKEND_BASE_URL?: string } }).config = {
CUSTOMER_PORTAL_BACKEND_BASE_URL: "https://api.test",
};
});

it("should return mock case details when isMockEnabled is true", async () => {
it("should return case details from API", async () => {
const { result } = renderHook(
() => useGetCaseDetails("project-1", "case-001"),
{ wrapper },
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("useGetCaseDetails", () => {
it("should use correct query key", () => {
renderHook(() => useGetCaseDetails("project-1", "case-001"), { wrapper });
const query = queryClient.getQueryCache().findAll({
queryKey: ["case-details", "project-1", "case-001", true],
queryKey: ["case-details", "project-1", "case-001"],
})[0];
expect(query).toBeDefined();
});
Expand Down
Loading