Repository navigation
Novera chat Integration #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rashmika998
merged 9 commits into
wso2-open-operations:customer-portal-milestone-1
from
dileepapeiris:feat/Add-update-Page
Feb 23, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38f6a16
Add conversation send flow & label matchers
dileepapeiris 5c71d7b
Add post conversation hook; update UI navigation
dileepapeiris 88c1038
Add LoadingDotsBubble and improve product matching
dileepapeiris 074b1fa
Replace input with Editor; add copy and error UI
dileepapeiris 2a6de42
Refactor chat tests with Editor & markdown mocks
dileepapeiris 92b060e
Adjust dashboard case-type colors and test typings
dileepapeiris ea03f85
Improve chat copy, deployment matching, and other fixes
dileepapeiris 1c0acb0
Refactor chat avatar color, input handling & tests
dileepapeiris 44ab12e
Add tests for whitespace-only labels
dileepapeiris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
apps/customer-portal/webapp/src/api/__tests__/usePostConversationMessages.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import { renderHook } from "@testing-library/react"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"; | ||
| import type { ReactNode } from "react"; | ||
| import { usePostConversationMessages } from "@api/usePostConversationMessages"; | ||
|
|
||
| const mockLogger = { debug: vi.fn() }; | ||
| vi.mock("@hooks/useLogger", () => ({ useLogger: () => mockLogger })); | ||
|
|
||
| const mockAuthFetch = vi.fn(); | ||
| vi.mock("@context/AuthApiContext", () => ({ | ||
| useAuthApiClient: () => mockAuthFetch, | ||
| })); | ||
|
|
||
| const mockUseAsgardeo = vi.fn(() => ({ | ||
| isSignedIn: true, | ||
| isLoading: false, | ||
| })); | ||
| vi.mock("@asgardeo/react", () => ({ | ||
| useAsgardeo: () => mockUseAsgardeo(), | ||
| })); | ||
|
|
||
| describe("usePostConversationMessages", () => { | ||
| let queryClient: QueryClient; | ||
| const originalConfig = window.config; | ||
|
|
||
| const wrapper = ({ children }: { children: ReactNode }) => ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ); | ||
|
|
||
| const requestParams = { | ||
| projectId: "proj-1", | ||
| conversationId: "conv-1", | ||
| message: "Follow-up question", | ||
| envProducts: { QA: ["WSO2 IS 6.1"], Production: ["WSO2 AM 4.2"] }, | ||
| region: "EU", | ||
| tier: "Tier 1", | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| queryClient = new QueryClient({ | ||
| defaultOptions: { mutations: { retry: false } }, | ||
| }); | ||
| vi.clearAllMocks(); | ||
| window.config = { | ||
| CUSTOMER_PORTAL_BACKEND_BASE_URL: "https://api.example.com", | ||
| } as typeof window.config; | ||
| mockAuthFetch.mockResolvedValue( | ||
| new Response(JSON.stringify({ message: "AI response", conversationId: "conv-1" }), { | ||
| status: 200, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| window.config = originalConfig; | ||
| }); | ||
|
|
||
| it("should POST to messages endpoint and return response", async () => { | ||
| const { result } = renderHook(() => usePostConversationMessages(), { | ||
| wrapper, | ||
| }); | ||
|
|
||
| const response = await result.current.mutateAsync(requestParams); | ||
|
|
||
| expect(mockAuthFetch).toHaveBeenCalledWith( | ||
| "https://api.example.com/projects/proj-1/conversations/conv-1/messages", | ||
| expect.objectContaining({ | ||
| method: "POST", | ||
| body: JSON.stringify({ | ||
| message: requestParams.message, | ||
| envProducts: requestParams.envProducts, | ||
| region: requestParams.region, | ||
| tier: requestParams.tier, | ||
| }), | ||
| }), | ||
| ); | ||
| expect(response).toEqual({ | ||
| message: "AI response", | ||
| conversationId: "conv-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("should throw when base URL is not configured", async () => { | ||
| window.config = {} as typeof window.config; | ||
| const { result } = renderHook(() => usePostConversationMessages(), { | ||
| wrapper, | ||
| }); | ||
|
|
||
| await expect(result.current.mutateAsync(requestParams)).rejects.toThrow( | ||
| "CUSTOMER_PORTAL_BACKEND_BASE_URL is not configured", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw when user is not signed in", async () => { | ||
| mockUseAsgardeo.mockReturnValueOnce({ | ||
| isSignedIn: false, | ||
| isLoading: false, | ||
| }); | ||
| const { result } = renderHook(() => usePostConversationMessages(), { | ||
| wrapper, | ||
| }); | ||
|
|
||
| await expect(result.current.mutateAsync(requestParams)).rejects.toThrow( | ||
| "User must be signed in to send messages", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw when auth is loading", async () => { | ||
| mockUseAsgardeo.mockReturnValueOnce({ | ||
| isSignedIn: false, | ||
| isLoading: true, | ||
| }); | ||
| const { result } = renderHook(() => usePostConversationMessages(), { | ||
| wrapper, | ||
| }); | ||
|
|
||
| await expect(result.current.mutateAsync(requestParams)).rejects.toThrow( | ||
| "User must be signed in to send messages", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw when API returns error response", async () => { | ||
| mockAuthFetch.mockResolvedValueOnce( | ||
| new Response("Internal Server Error", { | ||
| status: 500, | ||
| statusText: "Internal Server Error", | ||
| }), | ||
| ); | ||
| const { result } = renderHook(() => usePostConversationMessages(), { | ||
| wrapper, | ||
| }); | ||
|
|
||
| await expect(result.current.mutateAsync(requestParams)).rejects.toThrow( | ||
| "Conversation messages API error: 500 Internal Server Error", | ||
| ); | ||
| }); | ||
| }); |
83 changes: 83 additions & 0 deletions
83
apps/customer-portal/webapp/src/api/usePostConversationMessages.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import { useMutation, type UseMutationResult } from "@tanstack/react-query"; | ||
| import { useAsgardeo } from "@asgardeo/react"; | ||
| import { useLogger } from "@hooks/useLogger"; | ||
| import { useAuthApiClient } from "@context/AuthApiContext"; | ||
| import type { ConversationRequest } from "@models/requests"; | ||
| import type { ConversationResponse } from "@models/responses"; | ||
|
|
||
| /** | ||
| * Posts a follow-up message to an existing conversation. | ||
| * Called after usePostConversations when user sends additional messages in chat. | ||
| * | ||
| * @returns {UseMutationResult<ConversationResponse, Error, { projectId: string; conversationId: string } & ConversationRequest>} Mutation result. | ||
| */ | ||
| export function usePostConversationMessages(): UseMutationResult< | ||
| ConversationResponse, | ||
| Error, | ||
| { projectId: string; conversationId: string } & ConversationRequest | ||
| > { | ||
| const logger = useLogger(); | ||
| const { isSignedIn, isLoading: isAuthLoading } = useAsgardeo(); | ||
| const fetchFn = useAuthApiClient(); | ||
|
|
||
| return useMutation< | ||
| ConversationResponse, | ||
| Error, | ||
| { projectId: string; conversationId: string } & ConversationRequest | ||
| >({ | ||
| mutationFn: async ( | ||
| params: { projectId: string; conversationId: string } & ConversationRequest, | ||
| ): Promise<ConversationResponse> => { | ||
| const { projectId, conversationId, message, envProducts, region, tier } = | ||
| params; | ||
|
|
||
| if (!isSignedIn || isAuthLoading) { | ||
| throw new Error("User must be signed in to send messages"); | ||
| } | ||
|
|
||
| logger.debug("[usePostConversationMessages] Request:", { | ||
| projectId, | ||
| conversationId, | ||
| messageLength: message.length, | ||
| }); | ||
|
|
||
| const baseUrl = window.config?.CUSTOMER_PORTAL_BACKEND_BASE_URL; | ||
| if (!baseUrl) { | ||
| throw new Error( | ||
| "CUSTOMER_PORTAL_BACKEND_BASE_URL is not configured", | ||
| ); | ||
| } | ||
|
|
||
| const requestUrl = `${baseUrl}/projects/${projectId}/conversations/${conversationId}/messages`; | ||
| const response = await fetchFn(requestUrl, { | ||
| method: "POST", | ||
| body: JSON.stringify({ message, envProducts, region, tier }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Conversation messages API error: ${response.status} ${response.statusText}`, | ||
| ); | ||
| } | ||
|
|
||
| const data: ConversationResponse = await response.json(); | ||
| logger.debug("[usePostConversationMessages] Data received"); | ||
| return data; | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.