Skip to content

Commit

Permalink
reorganize fetcher files
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-s-nava committed Dec 18, 2024
1 parent d53557c commit baba470
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/[locale]/opportunity/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Metadata } from "next";
import NotFound from "src/app/[locale]/not-found";
import { fetchOpportunity } from "src/app/api/fetchers";
import { OPPORTUNITY_CRUMBS } from "src/constants/breadcrumbs";
import { ApiRequestError, parseErrorStatus } from "src/errors";
import withFeatureFlag from "src/hoc/withFeatureFlag";
import { fetchOpportunity } from "src/services/fetch/fetchers/fetchers";
import { Opportunity } from "src/types/opportunity/opportunityResponseTypes";
import { WithFeatureFlagProps } from "src/types/uiTypes";

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/api/auth/logout/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { postLogout } from "src/app/api/userFetcher";
import { deleteSession, getSession } from "src/services/auth/session";
import { postLogout } from "src/services/fetch/fetchers/userFetcher";

export async function POST() {
try {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { searchForOpportunities } from "src/app/api/searchFetcher";
import { searchForOpportunities } from "src/services/fetch/fetchers/searchFetcher";
import { QueryParamData } from "src/types/search/searchRequestTypes";

import { Suspense } from "react";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/auth/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// note that importing these individually allows us to mock them, otherwise mocks don't work :shrug:
import debounce from "lodash/debounce";
import noop from "lodash/noop";
import { userFetcher } from "src/app/api/clientUserFetcher";
import { UserSession } from "src/services/auth/types";
import { UserContext } from "src/services/auth/useUser";
import { userFetcher } from "src/services/fetch/fetchers/clientUserFetcher";
import { isSessionExpired } from "src/utils/authUtil";

import React, { useCallback, useEffect, useMemo, useState } from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiMethod } from "src/app/api/fetcherHelpers";
import { environment } from "src/constants/environments";
import { ApiMethod } from "src/services/fetch/fetcherHelpers";

export interface EndpointConfig {
basePath: string;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
fetchOpportunityEndpoint,
opportunitySearchEndpoint,
userLogoutEndpoint,
} from "src/app/api/endpointConfigs";
} from "src/services/fetch/endpointConfigs";
import {
createRequestBody,
createRequestUrl,
getDefaultHeaders,
HeadersDict,
JSONRequestBody,
sendRequest,
} from "src/app/api/fetcherHelpers";
} from "src/services/fetch/fetcherHelpers";
import { APIResponse } from "src/types/apiResponseTypes";
import { OpportunityApiResponse } from "src/types/opportunity/opportunityResponseTypes";
import { QueryParamData } from "src/types/search/searchRequestTypes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "server-only";

import { fetchOpportunitySearch } from "src/app/api/fetchers";
import { fetchOpportunitySearch } from "src/services/fetch/fetchers/fetchers";
import {
PaginationOrderBy,
PaginationRequestBody,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { postUserLogout } from "src/app/api/fetchers";
import { postUserLogout } from "src/services/fetch/fetchers/fetchers";

export const postLogout = async (token: string) => {
const jwtAuthHeader = { "X-SGG-Token": token };
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/api/auth/logout/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.mock("src/services/auth/session", () => ({
deleteSession: (): unknown => deleteSessionMock(),
}));

jest.mock("src/app/api/userFetcher", () => ({
jest.mock("src/services/fetch/fetchers/userFetcher", () => ({
postLogout: (token: string): unknown => postLogoutMock(token),
}));

Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/components/search/SearchResults.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jest.mock("react", () => ({
cache: (fn: unknown) => fn,
}));

jest.mock("src/app/api/searchFetcher", () => ({
jest.mock("src/services/fetch/fetchers/searchFetcher", () => ({
searchForOpportunities: jest.fn(() => Promise.resolve()),
}));

Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/pages/search/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock("src/hooks/useSearchParamUpdater", () => ({
// // currently, with Suspense mocked out below to always show fallback content,
// // the components making the fetch calls are never being rendered so we do not need to mock them out
// // uncomment this if we figure out a way to properly test the underlying async components
// jest.mock("src/app/api/fetchers", () => ({
// jest.mock("src/services/fetch/fetchers", () => ({
// get searchOpportunityFetcher() {
// return new MockSearchOpportunityAPI();
// },
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/services/auth/useUser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useUser } from "src/services/auth/useUser";

const userFetcherMock = jest.fn();

jest.mock("src/app/api/clientUserFetcher", () => ({
jest.mock("src/services/fetch/fetchers/clientUserFetcher", () => ({
userFetcher: () => userFetcherMock() as unknown,
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import "server-only";

import { createRequestUrl, sendRequest } from "src/app/api/fetcherHelpers";
import { ApiRequestError, NetworkError } from "src/errors";
import {
createRequestUrl,
sendRequest,
} from "src/services/fetch/fetcherHelpers";
import { QueryParamData } from "src/types/search/searchRequestTypes";

const searchInputs: QueryParamData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EndpointConfig } from "src/app/api/endpointConfigs";
import { requesterForEndpoint } from "src/app/api/fetchers";
import { EndpointConfig } from "src/services/fetch/endpointConfigs";
import { requesterForEndpoint } from "src/services/fetch/fetchers/fetchers";

const createRequestUrlMock = jest.fn(
(_method, _basePath, _version, _namespace, subPath: string, _body) => {
Expand All @@ -15,7 +15,7 @@ const getDefaultHeadersMock = jest.fn(() => ({
"Content-Type": "application/json",
}));

jest.mock("src/app/api/fetcherHelpers", () => ({
jest.mock("src/services/fetch/fetcherHelpers", () => ({
createRequestUrl: (
_method: unknown,
_basePath: unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
buildFilters,
buildPagination,
searchForOpportunities,
} from "src/app/api/searchFetcher";
} from "src/services/fetch/fetchers/searchFetcher";
import {
QueryParamData,
SearchFetcherActionType,
Expand All @@ -29,7 +29,7 @@ jest.mock("react", () => ({
cache: (fn: unknown) => fn,
}));

jest.mock("src/app/api/fetchers", () => ({
jest.mock("src/services/fetch/fetchers/fetchers", () => ({
fetchOpportunitySearch: (params: QueryParamData) => {
return mockfetchOpportunitySearch(params) as SearchAPIResponse;
},
Expand Down

0 comments on commit baba470

Please sign in to comment.