diff --git a/coral/src/app/features/topics/acl-request/TopicAclRequest.tsx b/coral/src/app/features/topics/acl-request/TopicAclRequest.tsx index 8c47e3f29a..f8ad9064d7 100644 --- a/coral/src/app/features/topics/acl-request/TopicAclRequest.tsx +++ b/coral/src/app/features/topics/acl-request/TopicAclRequest.tsx @@ -89,6 +89,7 @@ const TopicAclRequest = () => { aclType === "PRODUCER" ? topicProducerForm.watch("topicname") : topicConsumerForm.watch("topicname"); + useQuery( ["topicTeam", selectedTopicName, selectedPatternType, aclType], { diff --git a/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.test.tsx b/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.test.tsx index c6a631ef2a..fca754587d 100644 --- a/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.test.tsx +++ b/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.test.tsx @@ -10,12 +10,8 @@ import { } from "src/domain/acl/acl-api"; import { AclOverviewInfo } from "src/domain/topic/topic-types"; import { customRender } from "src/services/test-utils/render-with-wrappers"; -import { testAuthUser } from "src/domain/auth-user/auth-user-test-helper"; jest.mock("src/domain/acl/acl-api"); -jest.mock("src/app/context-provider/AuthProvider", () => ({ - useAuthContext: () => mockAuthUser(), -})); const mockGetConsumerOffsets = getConsumerOffsets as jest.MockedFunction< typeof getConsumerOffsets @@ -24,7 +20,7 @@ const mockGetAivenServiceAccountDetails = getAivenServiceAccountDetails as jest.MockedFunction< typeof getAivenServiceAccountDetails >; -const mockAuthUser = jest.fn(); + const mockCloseDetailsModal = jest.fn(); const testServiceAccountData = { @@ -123,176 +119,239 @@ const findTerm = (term: string) => { }; describe("TopicSubscriptionsDetailsModal.tsx", () => { - beforeAll(() => { - mockAuthUser.mockReturnValue(testAuthUser); - }); + describe("renders correct data in details modal (Aiven)", () => { + beforeEach(() => { + mockGetAivenServiceAccountDetails.mockResolvedValue( + testServiceAccountData + ); + customRender(, { + queryClient: true, + }); + }); + afterEach(() => { + jest.resetAllMocks(); + cleanup(); + }); + + it("does not fetch data for consumer offset", async () => { + expect(mockGetConsumerOffsets).not.toHaveBeenCalled(); + }); + + it("fetches the data for service account details", async () => { + expect(mockGetAivenServiceAccountDetails).toHaveBeenCalledWith({ + aclReqNo: defaultPropsAiven.selectedSubscription.req_no, + env: defaultPropsAiven.selectedSubscription.environment, + serviceName: defaultPropsAiven.selectedSubscription.acl_ssl, + topicName: defaultPropsAiven.selectedSubscription.topicname, + }); + }); - afterEach(() => { - cleanup(); - jest.clearAllMocks(); + it("renders correct data in details modal (Aiven)", async () => { + await waitForElementToBeRemoved(screen.getByTestId("pw-skeleton")); + + expect(findTerm("Environment")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.selectedSubscription.environmentName) + ).toBeVisible(); + + expect(findTerm("Subscription type")).toBeVisible(); + expect( + findDefinition( + defaultPropsAiven.selectedSubscription.topictype.toUpperCase() + ) + ).toBeVisible(); + + expect(findTerm("Pattern type")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.selectedSubscription.aclPatternType) + ).toBeVisible(); + + expect(findTerm("Topic name")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.selectedSubscription.topicname) + ).toBeVisible(); + + expect(findTerm("Consumer group")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.selectedSubscription.consumergroup) + ).toBeVisible(); + + expect(findTerm("IP or Service account based")).toBeVisible(); + expect(findDefinition("Service account")).toBeVisible(); + + expect(findTerm("Service account")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.selectedSubscription.acl_ssl) + ).toBeVisible(); + + expect(findTerm("Service account password")).toBeVisible(); + expect( + findDefinition(defaultPropsAiven.serviceAccountData.password) + ).toBeVisible(); + + expect(screen.queryByText("Consumer offset")).not.toBeInTheDocument(); + }); }); - it("should render correct data in details modal (Aiven)", async () => { - mockGetAivenServiceAccountDetails.mockResolvedValue(testServiceAccountData); + describe("renders correct data in details modal (non Aiven consumer)", () => { + beforeEach(() => { + mockGetConsumerOffsets.mockResolvedValue([testOffsetsData]); + + customRender( + , + { + queryClient: true, + } + ); + }); + afterEach(() => { + jest.resetAllMocks(); + cleanup(); + }); + + it("fetches data for consumer offset", async () => { + expect(mockGetConsumerOffsets).toHaveBeenCalledWith({ + consumerGroupId: + defaultPropsNonAiven.selectedSubscription.consumergroup, + env: defaultPropsNonAiven.selectedSubscription.environment, + topicName: defaultPropsNonAiven.selectedSubscription.topicname, + }); + }); - customRender(, { - queryClient: true, + it("does not fetch service account details from aiven", async () => { + expect(mockGetAivenServiceAccountDetails).not.toHaveBeenCalled(); }); - await waitForElementToBeRemoved(screen.getByTestId("pw-skeleton")); - - expect(findTerm("Environment")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.selectedSubscription.environmentName) - ).toBeVisible(); - - expect(findTerm("Subscription type")).toBeVisible(); - expect( - findDefinition( - defaultPropsAiven.selectedSubscription.topictype.toUpperCase() - ) - ).toBeVisible(); - - expect(findTerm("Pattern type")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.selectedSubscription.aclPatternType) - ).toBeVisible(); - - expect(findTerm("Topic name")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.selectedSubscription.topicname) - ).toBeVisible(); - - expect(findTerm("Consumer group")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.selectedSubscription.consumergroup) - ).toBeVisible(); - - expect(findTerm("IP or Service account based")).toBeVisible(); - expect(findDefinition("Service account")).toBeVisible(); - - expect(findTerm("Service account")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.selectedSubscription.acl_ssl) - ).toBeVisible(); - - expect(findTerm("Service account password")).toBeVisible(); - expect( - findDefinition(defaultPropsAiven.serviceAccountData.password) - ).toBeVisible(); - - expect(screen.queryByText("Consumer offset")).not.toBeInTheDocument(); + it("renders correct data in details modal (non Aiven consumer)", async () => { + await waitForElementToBeRemoved(screen.getByTestId("offsets-skeleton")); + + expect(findTerm("Environment")).toBeVisible(); + expect( + findDefinition( + defaultPropsNonAiven.selectedSubscription.environmentName + ) + ).toBeVisible(); + + expect(findTerm("Subscription type")).toBeVisible(); + expect( + findDefinition( + defaultPropsNonAiven.selectedSubscription.topictype.toUpperCase() + ) + ).toBeVisible(); + + expect(findTerm("Pattern type")).toBeVisible(); + expect( + findDefinition(defaultPropsNonAiven.selectedSubscription.aclPatternType) + ).toBeVisible(); + + expect(findTerm("Topic name")).toBeVisible(); + expect( + findDefinition(defaultPropsNonAiven.selectedSubscription.topicname) + ).toBeVisible(); + + expect(findTerm("Consumer group")).toBeVisible(); + expect( + findDefinition(defaultPropsNonAiven.selectedSubscription.consumergroup) + ).toBeVisible(); + + expect(findTerm("IP or Principal based")).toBeVisible(); + expect(findDefinition("IP")).toBeVisible(); + + expect(findTerm("IP")).toBeVisible(); + expect( + findDefinition(defaultPropsNonAiven.selectedSubscription.acl_ip) + ).toBeVisible(); + + expect( + screen.getByText( + "Partition 0 | Current offset 0 | End offset 0 | Lag 0" + ) + ).toBeVisible(); + + expect( + screen.queryByText("Service account password") + ).not.toBeInTheDocument(); + }); }); - it("should render correct data in details modal (non Aiven consumer)", async () => { - mockGetConsumerOffsets.mockResolvedValue([testOffsetsData]); + describe("should render correct data in details modal (Aiven consumer, non owner user)", () => { + beforeAll(async () => { + mockGetAivenServiceAccountDetails.mockResolvedValue( + notOwnerTestServiceAccountData + ); + + customRender( + , + { + queryClient: true, + } + ); - customRender(, { - queryClient: true, + await waitForElementToBeRemoved(screen.getByTestId("pw-skeleton")); }); - await waitForElementToBeRemoved(screen.getByTestId("offsets-skeleton")); - - expect(findTerm("Environment")).toBeVisible(); - expect( - findDefinition(defaultPropsNonAiven.selectedSubscription.environmentName) - ).toBeVisible(); - - expect(findTerm("Subscription type")).toBeVisible(); - expect( - findDefinition( - defaultPropsNonAiven.selectedSubscription.topictype.toUpperCase() - ) - ).toBeVisible(); - - expect(findTerm("Pattern type")).toBeVisible(); - expect( - findDefinition(defaultPropsNonAiven.selectedSubscription.aclPatternType) - ).toBeVisible(); - - expect(findTerm("Topic name")).toBeVisible(); - expect( - findDefinition(defaultPropsNonAiven.selectedSubscription.topicname) - ).toBeVisible(); - - expect(findTerm("Consumer group")).toBeVisible(); - expect( - findDefinition(defaultPropsNonAiven.selectedSubscription.consumergroup) - ).toBeVisible(); - - expect(findTerm("IP or Principal based")).toBeVisible(); - expect(findDefinition("IP")).toBeVisible(); - - expect(findTerm("IP")).toBeVisible(); - expect( - findDefinition(defaultPropsNonAiven.selectedSubscription.acl_ip) - ).toBeVisible(); - - expect( - screen.getByText("Partition 0 | Current offset 0 | End offset 0 | Lag 0") - ).toBeVisible(); - - expect( - screen.queryByText("Service account password") - ).not.toBeInTheDocument(); - }); + afterAll(() => { + cleanup(); + jest.resetAllMocks(); + }); - it("should render correct data in details modal (Aiven consumer, non owner user)", async () => { - mockGetAivenServiceAccountDetails.mockResolvedValue( - notOwnerTestServiceAccountData - ); + it("does not fetch data for consumer offset", async () => { + expect(mockGetConsumerOffsets).not.toHaveBeenCalled(); + }); - customRender( - , - { - queryClient: true, - } - ); - - await waitForElementToBeRemoved(screen.getByTestId("pw-skeleton")); - - expect(findTerm("Environment")).toBeVisible(); - expect( - findDefinition( - defaultPropsNotOwnerAiven.selectedSubscription.environmentName - ) - ).toBeVisible(); - - expect(findTerm("Subscription type")).toBeVisible(); - expect( - findDefinition( - defaultPropsNotOwnerAiven.selectedSubscription.topictype.toUpperCase() - ) - ).toBeVisible(); - - expect(findTerm("Pattern type")).toBeVisible(); - expect( - findDefinition( - defaultPropsNotOwnerAiven.selectedSubscription.aclPatternType - ) - ).toBeVisible(); - - expect(findTerm("Topic name")).toBeVisible(); - expect( - findDefinition(defaultPropsNotOwnerAiven.selectedSubscription.topicname) - ).toBeVisible(); - - expect(findTerm("Consumer group")).toBeVisible(); - expect( - findDefinition( - defaultPropsNotOwnerAiven.selectedSubscription.consumergroup - ) - ).toBeVisible(); - - expect(findTerm("IP or Service account based")).toBeVisible(); - expect(findDefinition("Service account")).toBeVisible(); - - expect(findTerm("Service account")).toBeVisible(); - expect( - findDefinition(defaultPropsNotOwnerAiven.selectedSubscription.acl_ssl) - ).toBeVisible(); - - expect(findTerm("Service account password")).toBeVisible(); - expect(findDefinition("Not authorized to see this.")).toBeVisible(); + it("fetches service account details from aiven", async () => { + expect(mockGetAivenServiceAccountDetails).toHaveBeenCalledWith({ + aclReqNo: defaultPropsNotOwnerAiven.selectedSubscription.req_no, + env: defaultPropsNotOwnerAiven.selectedSubscription.environment, + serviceName: defaultPropsNotOwnerAiven.selectedSubscription.acl_ssl, + topicName: defaultPropsNotOwnerAiven.selectedSubscription.topicname, + }); + }); + + it("renders correct data in details modal (Aiven consumer, non owner user)", async () => { + expect(findTerm("Environment")).toBeVisible(); + expect( + findDefinition( + defaultPropsNotOwnerAiven.selectedSubscription.environmentName + ) + ).toBeVisible(); + + expect(findTerm("Subscription type")).toBeVisible(); + expect( + findDefinition( + defaultPropsNotOwnerAiven.selectedSubscription.topictype.toUpperCase() + ) + ).toBeVisible(); + + expect(findTerm("Pattern type")).toBeVisible(); + expect( + findDefinition( + defaultPropsNotOwnerAiven.selectedSubscription.aclPatternType + ) + ).toBeVisible(); + + expect(findTerm("Topic name")).toBeVisible(); + expect( + findDefinition(defaultPropsNotOwnerAiven.selectedSubscription.topicname) + ).toBeVisible(); + + expect(findTerm("Consumer group")).toBeVisible(); + expect( + findDefinition( + defaultPropsNotOwnerAiven.selectedSubscription.consumergroup + ) + ).toBeVisible(); + + expect(findTerm("IP or Service account based")).toBeVisible(); + expect(findDefinition("Service account")).toBeVisible(); + + expect(findTerm("Service account")).toBeVisible(); + expect( + findDefinition(defaultPropsNotOwnerAiven.selectedSubscription.acl_ssl) + ).toBeVisible(); + + expect(findTerm("Service account password")).toBeVisible(); + expect(findDefinition("Not authorized to see this.")).toBeVisible(); + }); }); }); diff --git a/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.tsx b/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.tsx index 8158fca306..ad3ade966d 100644 --- a/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.tsx +++ b/coral/src/app/features/topics/details/subscriptions/components/TopicSubscriptionsDetailsModal.tsx @@ -11,7 +11,6 @@ import { import { useQuery } from "@tanstack/react-query"; import { useEffect, useState } from "react"; import { Modal } from "src/app/components/Modal"; -import { useAuthContext } from "src/app/context-provider/AuthProvider"; import { getAivenServiceAccountDetails, getConsumerOffsets, @@ -37,7 +36,6 @@ const TopicSubscriptionsDetailsModal = ({ isAivenCluster, selectedSubscription, }: TopicSubscriptionsDetailsModalProps) => { - const user = useAuthContext(); const { environment, consumergroup, @@ -76,19 +74,13 @@ const TopicSubscriptionsDetailsModal = ({ error: serviceAccountError, isFetched: serviceAccountDataFetched, } = useQuery( - [ - "getAivenServiceAccountDetails", - environment, - topicname, - user?.username, - req_no, - ], + ["getAivenServiceAccountDetails", environment, topicname, acl_ssl, req_no], { queryFn: () => { return getAivenServiceAccountDetails({ env: environment, topicName: topicname, - userName: user?.username || "", + serviceName: acl_ssl || "", aclReqNo: req_no, }); }, diff --git a/coral/src/domain/acl/acl-api.ts b/coral/src/domain/acl/acl-api.ts index 9aec2004ac..2fea0b1c07 100644 --- a/coral/src/domain/acl/acl-api.ts +++ b/coral/src/domain/acl/acl-api.ts @@ -16,6 +16,7 @@ import { KlawApiRequest, KlawApiRequestQueryParameters, KlawApiResponse, + ResolveIntersectionTypes, } from "types/utils"; const createAclRequest = ( @@ -137,16 +138,37 @@ function getAivenServiceAccounts( ); } -type GetAivenServiceAccountDetailsParams = - KlawApiRequestQueryParameters<"getAivenServiceAccountDetails">; +/*** The parameter "userName" that the endpoint expects is actually + * the name of the service (acl_ssl). Since this is very confusing + * and error-prone, we name it different for the params of our + * api call function + * Will be renamed in Backend after release 2.5. + */ +type GetAivenServiceAccountDetailsParams = ResolveIntersectionTypes< + Omit< + KlawApiRequestQueryParameters<"getAivenServiceAccountDetails">, + "userName" + > & { + serviceName: KlawApiRequestQueryParameters<"getAivenServiceAccountDetails">["userName"]; + } +>; + type getAivenServiceAccountDetailsResponse = KlawApiResponse<"getAivenServiceAccountDetails">; function getAivenServiceAccountDetails( params: GetAivenServiceAccountDetailsParams ): Promise { + const apiParams: KlawApiRequestQueryParameters<"getAivenServiceAccountDetails"> = + { + aclReqNo: params.aclReqNo, + env: params.env, + topicName: params.topicName, + userName: params.serviceName, + }; + return api.get( API_PATHS.getAivenServiceAccountDetails, - new URLSearchParams(params) + new URLSearchParams(apiParams) ); }