Skip to content

Commit e8893f7

Browse files
committed
🚚(frontend) api/joanie as joanieLegacyClient
1 parent dbe06db commit e8893f7

File tree

11 files changed

+32
-18
lines changed

11 files changed

+32
-18
lines changed

src/frontend/js/api/joanie/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ export const joanieApi = new ApiClientJoanie(config);
3131
export const isApiError = (error: unknown): error is ApiError => {
3232
return (error as ApiError).name === 'ApiError';
3333
};
34+
35+
export {
36+
default as JoanieLegacyClient,
37+
getResponseBody as getResponseBodyLegacy,
38+
checkStatus as checkStatusLegacy,
39+
getAPIEndpoint as getAPIEndpointLegacy,
40+
getRoutes as getRoutesLegacy,
41+
isJoanieEnabled as isJoanieEnabledLegacy,
42+
buildApiUrl as buildApiUrlLegacy,
43+
} from './joanieLegacyClient';

src/frontend/js/api/joanie.spec.ts renamed to src/frontend/js/api/joanie/joanieLegacyClient.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetchMock from 'fetch-mock';
22
import { ResourcesQuery } from 'hooks/useResources';
33
import { HttpStatusCode } from 'utils/errors/HttpError';
4-
import { buildApiUrl, getResponseBody } from './joanie';
4+
import { buildApiUrl, getResponseBody } from './joanieLegacyClient';
55

66
describe('api/joanie', () => {
77
it('getResponse should handle empty response body', async () => {
File renamed without changes.

src/frontend/js/api/lms/joanie.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { matchPath, PathMatch } from 'react-router-dom';
2-
import JoanieApi from 'api/joanie';
2+
import { JoanieLegacyClient as JoanieApi } from 'api/joanie';
33
import { LMSBackend } from 'types/commonDataProps';
44
import { APIBackend, APILms } from 'types/api';
55

src/frontend/js/contexts/JoanieApiContext/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PropsWithChildren } from 'react';
22
import { createContext, useContext } from 'react';
33
import type * as Joanie from 'types/Joanie';
4-
import API from 'api/joanie';
4+
import { JoanieLegacyClient as JoanieApi } from 'api/joanie';
55
import type { Maybe } from 'types/utils';
66

77
const JoanieApiContext = createContext<Maybe<Joanie.API>>(undefined);
@@ -10,7 +10,7 @@ const JoanieApiContext = createContext<Maybe<Joanie.API>>(undefined);
1010
* Provider to access to the Joanie API interface.
1111
*/
1212
const JoanieApiProvider = ({ children }: PropsWithChildren<{}>) => {
13-
const api = API();
13+
const api = JoanieApi();
1414

1515
return <JoanieApiContext.Provider value={api}>{children}</JoanieApiContext.Provider>;
1616
};

src/frontend/js/contexts/SessionContext/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { lazy, PropsWithChildren, Suspense, useContext } from 'react';
2-
import { isJoanieEnabled } from 'api/joanie';
2+
import { isJoanieEnabledLegacy } from 'api/joanie';
33
import { AuthenticationApi } from 'api/authentication';
44
import { handle } from 'utils/errors/handle';
55
import { Session } from './SessionContext';
@@ -19,7 +19,7 @@ export const SessionProvider = ({ children, ...props }: PropsWithChildren<any>)
1919

2020
return (
2121
<Suspense fallback="loading...">
22-
{isJoanieEnabled ? (
22+
{isJoanieEnabledLegacy ? (
2323
<LazyJoanieSessionProvider {...props}>{children}</LazyJoanieSessionProvider>
2424
) : (
2525
<LazyBaseSessionProvider {...props}>{children}</LazyBaseSessionProvider>

src/frontend/js/hooks/useCourseProductUnion/index.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { History, HistoryContext } from 'hooks/useHistory';
88
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
99
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
1010
import { SessionProvider } from 'contexts/SessionContext';
11-
import { getRoutes } from 'api/joanie';
11+
import { getRoutesLegacy } from 'api/joanie';
1212
import { mockPaginatedResponse } from 'utils/test/mockPaginatedResponse';
1313
import { CourseListItemFactory, CourseProductRelationFactory } from 'utils/test/factories/joanie';
1414
import { useCourseProductUnion } from '.';
@@ -74,7 +74,7 @@ describe('useCourseProductUnion', () => {
7474
});
7575

7676
it('should call courses and coursesProductRelation endpoints', async () => {
77-
const ROUTES = getRoutes();
77+
const ROUTES = getRoutesLegacy();
7878
const coursesUrl = ROUTES.courses.get.replace(':id/', '');
7979
const courseProductRelationsUrl = ROUTES.courseProductRelations.get.replace(':id/', '');
8080
fetchMock.get(
@@ -100,7 +100,7 @@ describe('useCourseProductUnion', () => {
100100

101101
it('should call organization courses and organization coursesProductRelation endpoints', async () => {
102102
const organizationId = 'DUMMY_ORGANIZATION_ID';
103-
const ROUTES = getRoutes();
103+
const ROUTES = getRoutesLegacy();
104104
const organizationCoursesUrl = ROUTES.user.organizations.courses.get.replace(
105105
':id',
106106
organizationId,

src/frontend/js/utils/react-query/useSessionMutation/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { renderHook, waitFor } from '@testing-library/react';
55
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
66
import BaseSessionProvider from 'contexts/SessionContext/BaseSessionProvider';
77
import { useSession } from 'contexts/SessionContext';
8-
import { checkStatus } from 'api/joanie';
8+
import { checkStatusLegacy } from 'api/joanie';
99
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
1010
import { HttpStatusCode } from 'utils/errors/HttpError';
1111
import { useSessionMutation } from '.';
@@ -41,7 +41,7 @@ describe('useSessionMutation', () => {
4141
const session = useSession();
4242
const mutation = useSessionMutation<unknown, void, unknown>({
4343
mutationFn: () =>
44-
fetch('http://api.endpoint/orders/create', { method: 'POST' }).then(checkStatus),
44+
fetch('http://api.endpoint/orders/create', { method: 'POST' }).then(checkStatusLegacy),
4545
onError: handleError,
4646
});
4747

src/frontend/js/utils/react-query/useSessionQuery/index.spec.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PropsWithChildren } from 'react';
44
import { renderHook, waitFor } from '@testing-library/react';
55
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
66
import BaseSessionProvider from 'contexts/SessionContext/BaseSessionProvider';
7-
import { checkStatus } from 'api/joanie';
7+
import { checkStatusLegacy } from 'api/joanie';
88
import { useSession } from 'contexts/SessionContext';
99
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
1010
import { HttpError, HttpStatusCode } from 'utils/errors/HttpError';
@@ -43,7 +43,9 @@ describe('useSessionQuery', () => {
4343

4444
const useHooks = () => {
4545
const session = useSession();
46-
useSessionQuery(['orders'], () => fetch('http://api.endpoint/orders/').then(checkStatus));
46+
useSessionQuery(['orders'], () =>
47+
fetch('http://api.endpoint/orders/').then(checkStatusLegacy),
48+
);
4749

4850
return session;
4951
};
@@ -73,7 +75,9 @@ describe('useSessionQuery', () => {
7375

7476
const useHooks = () => {
7577
const session = useSession();
76-
useSessionQuery(['orders'], () => fetch('http://api.endpoint/orders/').then(checkStatus));
78+
useSessionQuery(['orders'], () =>
79+
fetch('http://api.endpoint/orders/').then(checkStatusLegacy),
80+
);
7781

7882
return session;
7983
};

src/frontend/js/widgets/SyllabusCourseRunsList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { computeStates } from 'utils/CourseRuns';
77
import { SyllabusAsideList } from 'widgets/SyllabusCourseRunsList/components/SyllabusAsideList';
88
import { SyllabusCourseRun } from 'widgets/SyllabusCourseRunsList/components/SyllabusCourseRun';
99
import { DjangoCMSPluginsInit } from 'components/DjangoCMSTemplate';
10-
import { isJoanieEnabled } from 'api/joanie';
10+
import { isJoanieEnabledLegacy } from 'api/joanie';
1111
import context from 'utils/context';
1212
import CourseWishButton from './components/CourseWishButton';
1313

@@ -74,7 +74,7 @@ const SyllabusCourseRunsList = ({
7474
<div className="course-detail__row course-detail__runs course-detail__runs--open">
7575
<div className="course-detail__empty">
7676
<FormattedMessage {...messages.noOpenedCourseRuns} />
77-
{isJoanieEnabled && Boolean(context?.features.WISHLIST) && (
77+
{isJoanieEnabledLegacy && Boolean(context?.features.WISHLIST) && (
7878
<CourseWishButton course={course} />
7979
)}
8080
</div>

0 commit comments

Comments
 (0)