Skip to content

Commit

Permalink
fix(coral): Use correct environments GET endpoints, rename domain fn …
Browse files Browse the repository at this point in the history
…to be more explicit (#1121)

* fix(coral): Use correct endpoints to get envs
* refactor(coral): REname getRequestForSchemas -> getEnvsForSchemaRequests
* reafctor(coral): Rename getEnvironments -> getEnvironmentsForTopicRequest
* feat(coral): Add getAllEnvironments endpoints, use where relevant
* refactor(coral): Rename other envs domain fn (schema, connector)
* fix(coral): use getAllEnvironments in browsing context for all entities
* fix(coral): remove superfluous mocking
* Revert "fix(coral): remove superfluous mocking"
* reafctor(coral): Rename and reorganize envs endpoints with accuracy
* reafctor(coral): Improve naming

Signed-off-by: Mathieu Anderson <mathieu.anderson@aiven.io>
  • Loading branch information
Mathieu Anderson authored May 11, 2023
1 parent b89ea80 commit 5625c7a
Show file tree
Hide file tree
Showing 45 changed files with 237 additions and 162 deletions.
12 changes: 8 additions & 4 deletions coral/src/app/features/approvals/acls/AclApprovals.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import AclApprovals from "src/app/features/approvals/acls/AclApprovals";
import { getAclRequestsForApprover } from "src/domain/acl/acl-api";
import transformAclRequestApiResponse from "src/domain/acl/acl-transformer";
import { AclRequest } from "src/domain/acl/acl-types";
import { Environment, getEnvironments } from "src/domain/environment";
import {
Environment,
getAllEnvironmentsForTopicAndAcl,
} from "src/domain/environment";
import { mockedEnvironmentResponse } from "src/domain/environment/environment-api.msw";
import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer";
import { mockIntersectionObserver } from "src/services/test-utils/mock-intersection-observer";
Expand All @@ -19,9 +22,10 @@ import { customRender } from "src/services/test-utils/render-with-wrappers";
jest.mock("src/domain/acl/acl-api.ts");
jest.mock("src/domain/environment/environment-api.ts");

const mockGetEnvironments = getEnvironments as jest.MockedFunction<
typeof getEnvironments
>;
const mockGetEnvironments =
getAllEnvironmentsForTopicAndAcl as jest.MockedFunction<
typeof getAllEnvironmentsForTopicAndAcl
>;

const mockGetAclRequestsForApprover =
getAclRequestsForApprover as jest.MockedFunction<
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/approvals/acls/AclApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function AclApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getEnvironments"}
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
<StatusFilter key={"status"} defaultStatus={"CREATED"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getConnectorRequestsForApprover,
} from "src/domain/connector";
import { transformConnectorRequestApiResponse } from "src/domain/connector/connector-transformer";
import { getSyncConnectorsEnvironments } from "src/domain/environment";
import { getAllEnvironmentsForConnector } from "src/domain/environment";
import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper";
import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer";
import { mockIntersectionObserver } from "src/services/test-utils/mock-intersection-observer";
Expand All @@ -19,8 +19,8 @@ jest.mock("src/domain/connector/connector-api.ts");
jest.mock("src/domain/environment/environment-api.ts");

const mockGetSyncConnectorsEnvironments =
getSyncConnectorsEnvironments as jest.MockedFunction<
typeof getSyncConnectorsEnvironments
getAllEnvironmentsForConnector as jest.MockedFunction<
typeof getAllEnvironmentsForConnector
>;

const mockGetConnectorRequestsForApprover =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function ConnectorApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getSyncConnectorsEnvironments"}
environmentEndpoint={"getAllEnvironmentsForConnector"}
/>,
<StatusFilter key={"status"} defaultStatus={"CREATED"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cleanup, screen, waitFor, within } from "@testing-library/react";
import { waitForElementToBeRemoved } from "@testing-library/react/pure";
import userEvent from "@testing-library/user-event";
import SchemaApprovals from "src/app/features/approvals/schemas/SchemaApprovals";
import { getSchemaRegistryEnvironments } from "src/domain/environment";
import { getAllEnvironmentsForSchema } from "src/domain/environment";
import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper";
import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer";
import {
Expand All @@ -20,8 +20,8 @@ jest.mock("src/domain/schema-request/schema-request-api.ts");
jest.mock("src/domain/environment/environment-api.ts");

const mockGetSchemaRegistryEnvironments =
getSchemaRegistryEnvironments as jest.MockedFunction<
typeof getSchemaRegistryEnvironments
getAllEnvironmentsForSchema as jest.MockedFunction<
typeof getAllEnvironmentsForSchema
>;

const mockGetSchemaRequestsForApprover =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function SchemaApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getSchemaRegistryEnvironments"}
environmentEndpoint={"getAllEnvironmentsForSchema"}
/>,
<StatusFilter key={"status"} defaultStatus={"CREATED"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cleanup, screen } from "@testing-library/react";
import {
ALL_ENVIRONMENTS_VALUE,
getSchemaRegistryEnvironments,
getEnvironmentsForSchemaRequest,
} from "src/domain/environment";
import { mockedEnvironmentResponse } from "src/domain/environment/environment-api.msw";
import { customRender } from "src/services/test-utils/render-with-wrappers";
Expand All @@ -13,8 +13,8 @@ import { SelectSchemaRegEnvironment } from "src/app/features/approvals/schemas/c
jest.mock("src/domain/environment/environment-api.ts");

const mockGetSchemaRegistryEnvironments =
getSchemaRegistryEnvironments as jest.MockedFunction<
typeof getSchemaRegistryEnvironments
getEnvironmentsForSchemaRequest as jest.MockedFunction<
typeof getEnvironmentsForSchemaRequest
>;

const filterLabel = "Filter by Environment";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NativeSelect, Option } from "@aivenio/aquarium";
import {
ALL_ENVIRONMENTS_VALUE,
Environment,
getSchemaRegistryEnvironments,
getEnvironmentsForSchemaRequest,
} from "src/domain/environment";
import { useQuery } from "@tanstack/react-query";

Expand All @@ -16,7 +16,7 @@ function SelectSchemaRegEnvironment(props: SelectSchemaRegEnvironmentProps) {

const { data: environments, isLoading } = useQuery<Environment[], Error>({
queryKey: ["schemaRegistryEnvironments"],
queryFn: () => getSchemaRegistryEnvironments(),
queryFn: () => getEnvironmentsForSchemaRequest(),
});

if (isLoading || !environments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cleanup, screen, waitFor, within } from "@testing-library/react";
import { waitForElementToBeRemoved } from "@testing-library/react/pure";
import userEvent from "@testing-library/user-event";
import TopicApprovals from "src/app/features/approvals/topics/TopicApprovals";
import { getEnvironments } from "src/domain/environment";
import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment";
import { mockedEnvironmentResponse } from "src/domain/environment/environment-api.msw";
import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer";
import { getTeams } from "src/domain/team/team-api";
Expand All @@ -17,9 +17,10 @@ jest.mock("src/domain/topic/topic-api.ts");
jest.mock("src/domain/environment/environment-api.ts");
jest.mock("src/domain/team/team-api");

const mockGetEnvironments = getEnvironments as jest.MockedFunction<
typeof getEnvironments
>;
const mockGetEnvironments =
getAllEnvironmentsForTopicAndAcl as jest.MockedFunction<
typeof getAllEnvironmentsForTopicAndAcl
>;

const mockGetTopicRequestsForApprover =
getTopicRequestsForApprover as jest.MockedFunction<
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/approvals/topics/TopicApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function TopicApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getEnvironments"}
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
<StatusFilter key={"status"} defaultStatus={"CREATED"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import { waitForElementToBeRemoved } from "@testing-library/react/pure";
import userEvent from "@testing-library/user-event";
import EnvironmentFilter from "src/app/features/components/filters/EnvironmentFilter";
import {
getEnvironments,
getSchemaRegistryEnvironments,
getSyncConnectorsEnvironments,
getAllEnvironmentsForTopicAndAcl,
getAllEnvironmentsForSchema,
getAllEnvironmentsForConnector,
} from "src/domain/environment";
import { createEnvironment } from "src/domain/environment/environment-test-helper";
import { customRender } from "src/services/test-utils/render-with-wrappers";

jest.mock("src/domain/environment/environment-api.ts");

const mockGetEnvironments = getEnvironments as jest.MockedFunction<
typeof getEnvironments
>;
const mockGetEnvironments =
getAllEnvironmentsForTopicAndAcl as jest.MockedFunction<
typeof getAllEnvironmentsForTopicAndAcl
>;

const mockGetSchemaRegistryEnvironments =
getSchemaRegistryEnvironments as jest.MockedFunction<
typeof getSchemaRegistryEnvironments
getAllEnvironmentsForSchema as jest.MockedFunction<
typeof getAllEnvironmentsForSchema
>;

const mockGetSyncConnectorsEnvironments =
getSyncConnectorsEnvironments as jest.MockedFunction<
typeof getSyncConnectorsEnvironments
getAllEnvironmentsForConnector as jest.MockedFunction<
typeof getAllEnvironmentsForConnector
>;

const mockEnvironments = [
Expand Down Expand Up @@ -51,9 +52,11 @@ describe("EnvironmentFilter.tsx", () => {
jest.resetAllMocks();
});

it("fetches from the getEnvironments endpoint", () => {
it("fetches from the getAllEnvironmentsForTopicAndAcl endpoint", () => {
customRender(
<EnvironmentFilter environmentEndpoint={"getEnvironments"} />,
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
{
memoryRouter: true,
queryClient: true,
Expand All @@ -65,10 +68,10 @@ describe("EnvironmentFilter.tsx", () => {
expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled();
});

it("fetches from the getSchemaRegistryEnvironments endpoint", () => {
it("fetches from the getAllEnvironmentsForSchema endpoint", () => {
customRender(
<EnvironmentFilter
environmentEndpoint={"getSchemaRegistryEnvironments"}
environmentEndpoint={"getAllEnvironmentsForSchema"}
/>,
{
memoryRouter: true,
Expand All @@ -81,10 +84,10 @@ describe("EnvironmentFilter.tsx", () => {
expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled();
});

it("fetches from the getSyncConnectorsEnvironments endpoint", () => {
it("fetches from the getAllEnvironmentsForConnector endpoint", () => {
customRender(
<EnvironmentFilter
environmentEndpoint={"getSyncConnectorsEnvironments"}
environmentEndpoint={"getAllEnvironmentsForConnector"}
/>,
{
memoryRouter: true,
Expand All @@ -105,7 +108,9 @@ describe("EnvironmentFilter.tsx", () => {
mockGetSyncConnectorsEnvironments.mockResolvedValue([]);

customRender(
<EnvironmentFilter environmentEndpoint={"getEnvironments"} />,
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
{
memoryRouter: true,
queryClient: true,
Expand Down Expand Up @@ -161,7 +166,9 @@ describe("EnvironmentFilter.tsx", () => {
mockGetSyncConnectorsEnvironments.mockResolvedValue([]);

customRender(
<EnvironmentFilter environmentEndpoint={"getEnvironments"} />,
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
{
memoryRouter: true,
queryClient: true,
Expand Down Expand Up @@ -195,7 +202,9 @@ describe("EnvironmentFilter.tsx", () => {
mockGetSyncConnectorsEnvironments.mockResolvedValue([]);

customRender(
<EnvironmentFilter environmentEndpoint={"getEnvironments"} />,
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
{
queryClient: true,
memoryRouter: true,
Expand Down Expand Up @@ -232,7 +241,9 @@ describe("EnvironmentFilter.tsx", () => {
mockGetSyncConnectorsEnvironments.mockResolvedValue([]);

customRender(
<EnvironmentFilter environmentEndpoint={"getEnvironments"} />,
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>,
{
queryClient: true,
browserRouter: true,
Expand Down
18 changes: 9 additions & 9 deletions coral/src/app/features/components/filters/EnvironmentFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { useQuery } from "@tanstack/react-query";
import { useFiltersValues } from "src/app/features/components/filters/useFiltersValues";
import {
Environment,
getEnvironments,
getSchemaRegistryEnvironments,
getSyncConnectorsEnvironments,
getAllEnvironmentsForTopicAndAcl,
getAllEnvironmentsForSchema,
getAllEnvironmentsForConnector,
} from "src/domain/environment";
import { HTTPError } from "src/services/api";

type EnvironmentEndpoint =
| "getEnvironments"
| "getSchemaRegistryEnvironments"
| "getSyncConnectorsEnvironments";
| "getAllEnvironmentsForTopicAndAcl"
| "getAllEnvironmentsForSchema"
| "getAllEnvironmentsForConnector";
interface EnvironmentFilterProps {
isSchemaRegistryEnvironments?: boolean;
environmentEndpoint: EnvironmentEndpoint;
Expand All @@ -21,9 +21,9 @@ interface EnvironmentFilterProps {
const environmentEndpointMap: {
[key in EnvironmentEndpoint]: () => Promise<Environment[]>;
} = {
getEnvironments: getEnvironments,
getSchemaRegistryEnvironments: getSchemaRegistryEnvironments,
getSyncConnectorsEnvironments: getSyncConnectorsEnvironments,
getAllEnvironmentsForTopicAndAcl: getAllEnvironmentsForTopicAndAcl,
getAllEnvironmentsForSchema: getAllEnvironmentsForSchema,
getAllEnvironmentsForConnector: getAllEnvironmentsForConnector,
};

function EnvironmentFilter({ environmentEndpoint }: EnvironmentFilterProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BrowseConnectors from "src/app/features/connectors/browse/BrowseConnector
import { mockIntersectionObserver } from "src/services/test-utils/mock-intersection-observer";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { Connector, getConnectors } from "src/domain/connector";
import { getSyncConnectorsEnvironments } from "src/domain/environment";
import { getAllEnvironmentsForConnector } from "src/domain/environment";
import { createEnvironment } from "src/domain/environment/environment-test-helper";
import { tabNavigateTo } from "src/services/test-utils/tabbing";
import { getTeams } from "src/domain/team";
Expand All @@ -21,8 +21,8 @@ const mockGetConnectors = getConnectors as jest.MockedFunction<
const mockGetTeams = getTeams as jest.MockedFunction<typeof getTeams>;

const mockGetSyncConnectorsEnvironments =
getSyncConnectorsEnvironments as jest.MockedFunction<
typeof getSyncConnectorsEnvironments
getAllEnvironmentsForConnector as jest.MockedFunction<
typeof getAllEnvironmentsForConnector
>;

const mockConnectors: Connector[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function BrowseConnectors() {
<TeamFilter key={"team"} />,
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getSyncConnectorsEnvironments"}
environmentEndpoint={"getAllEnvironmentsForConnector"}
/>,
<SearchConnectorFilter key="connector-name" />,
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ConnectorRequest from "src/app/features/connectors/request/ConnectorReque
import { createEnvironment } from "src/domain/environment/environment-test-helper";
import { customRender } from "src/services/test-utils/render-with-wrappers";
import { createConnectorRequest } from "src/domain/connector";
import { getSyncConnectorsEnvironments } from "src/domain/environment";
import { getAllEnvironmentsForConnector } from "src/domain/environment";

jest.mock("src/domain/environment/environment-api.ts");
jest.mock("src/domain/connector/connector-api.ts");

const mockGetConnectorEnvironmentRequest =
getSyncConnectorsEnvironments as jest.MockedFunction<
typeof getSyncConnectorsEnvironments
getAllEnvironmentsForConnector as jest.MockedFunction<
typeof getAllEnvironmentsForConnector
>;

const mockCreateConnectorRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { createConnectorRequest } from "src/domain/connector";
import {
Environment,
getSyncConnectorsEnvironments,
getAllEnvironmentsForConnector,
} from "src/domain/environment";
import { parseErrorMsg } from "src/services/mutation-utils";

Expand All @@ -45,8 +45,8 @@ function ConnectorRequest() {
Environment[],
Error
>({
queryKey: ["getSyncConnectorsEnvironments"],
queryFn: () => getSyncConnectorsEnvironments(),
queryKey: ["getAllEnvironmentsForConnector"],
queryFn: () => getAllEnvironmentsForConnector(),
});

const connectorRequestMutation = useMutation(createConnectorRequest, {
Expand Down
Loading

0 comments on commit 5625c7a

Please sign in to comment.