Skip to content
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

🚚(frontend) move: api/joanie to api/joanie/joanieLegacyClient, factories/joanie to factories/joanieLegacy #2323

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/frontend/js/api/joanie/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import context from 'utils/context';

/**
* Flag which determines if joanie is enabled.
*/
export const isJoanieEnabled = !!context.joanie_backend;

export {
default as JoanieLegacyClient,
getResponseBody as getResponseBodyLegacy,
checkStatus as checkStatusLegacy,
getAPIEndpoint as getAPIEndpointLegacy,
getRoutes as getRoutesLegacy,
buildApiUrl as buildApiUrlLegacy,
} from './joanieLegacyClient';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetchMock from 'fetch-mock';
import { ResourcesQuery } from 'hooks/useResources';
import { HttpStatusCode } from 'utils/errors/HttpError';
import { buildApiUrl, getResponseBody } from './joanie';
import { buildApiUrl, getResponseBody } from './joanieLegacyClient';

describe('api/joanie', () => {
it('getResponse should handle empty response body', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ export const getRoutes = () => {
};
};

/**
* Flag which determines if joanie is enabled.
*/
export const isJoanieEnabled = !!context.joanie_backend;

const filterEmptyEntry = ([, value]: [PropertyKey, any]) => {
if (value == null) return false; // Value is null/undefined
if (value?.length !== undefined && value.length === 0) return false; // Value is an empty array/string
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/api/lms/joanie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { matchPath, PathMatch } from 'react-router-dom';
import JoanieApi from 'api/joanie';
import { JoanieLegacyClient as JoanieApi } from 'api/joanie';
import { LMSBackend } from 'types/commonDataProps';
import { APIBackend, APILms } from 'types/api';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import countries from 'i18n-iso-countries';
import { CunninghamProvider } from '@openfun/cunningham-react';
import userEvent, { UserEvent } from '@testing-library/user-event';
import { Address } from 'types/Joanie';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { changeSelect, clearSelect } from 'components/Form/test-utils';
import AddressForm from './index';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { StorybookHelper } from 'utils/StorybookHelper';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import AddressForm from '.';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PropsWithChildren } from 'react';
import { CunninghamProvider } from '@openfun/cunningham-react';
import userEvent, { UserEvent } from '@testing-library/user-event';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import type * as Joanie from 'types/Joanie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IntlProvider } from 'react-intl';
import fetchMock from 'fetch-mock';
import { QueryStateFactory } from 'utils/test/factories/reactQuery';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { CredentialOrderFactory } from 'utils/test/factories/joanie';
import { CredentialOrderFactory } from 'utils/test/factories/joanieLegacy';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
import { Props } from './AbstractContractFrame';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ContractFactory,
CourseProductRelationFactory,
OrganizationFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
import { isCourseProductRelation } from 'types/Joanie';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/components/ContractStatus/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import { PropsWithChildren } from 'react';
import { IntlProvider, createIntl } from 'react-intl';
import { faker } from '@faker-js/faker';
import { ContractFactory } from 'utils/test/factories/joanie';
import { ContractFactory } from 'utils/test/factories/joanieLegacy';
import { DEFAULT_DATE_FORMAT } from 'hooks/useDateFormat';
import ContractStatus from '.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event';
import { QueryClientProvider } from '@tanstack/react-query';
import fetchMock from 'fetch-mock';
import { faker } from '@faker-js/faker';
import { ContractFactory, CredentialOrderFactory } from 'utils/test/factories/joanie';
import { ContractFactory, CredentialOrderFactory } from 'utils/test/factories/joanieLegacy';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import JoanieApiProvider from 'contexts/JoanieApiContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type * as Joanie from 'types/Joanie';
import { PaymentProviders } from 'types/Joanie';
import { handle as mockHandle } from 'utils/errors/handle';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { PaymentFactory } from 'utils/test/factories/joanie';
import { PaymentFactory } from 'utils/test/factories/joanieLegacy';
import PaymentInterface from '.';

jest.mock('./PayplugLightbox', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/components/PaymentButton/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
OrderGroupFactory,
CourseLightFactory,
EnrollmentFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { PAYMENT_SETTINGS } from 'settings';
import type * as Joanie from 'types/Joanie';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/components/PurchaseButton/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CourseLightFactory,
EnrollmentFactory,
ProductFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { ProductType } from 'types/Joanie';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import { ProductFactory } from 'utils/test/factories/joanie';
import { ProductFactory } from 'utils/test/factories/joanieLegacy';
import PurchaseButton from '.';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IntlProvider } from 'react-intl';
import RegisteredAddress from 'components/RegisteredAddress/index';
import type { Address } from 'types/Joanie';
import { noop } from 'utils';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';

describe('RegisteredAddress', () => {
const Wrapper = ({ children }: PropsWithChildren<{}>) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { StorybookHelper } from 'utils/StorybookHelper';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import RegisteredAddress from '.';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent, getByRole, getByText, render } from '@testing-library/react'
import { PropsWithChildren } from 'react';
import { IntlProvider } from 'react-intl';
import { CreditCard } from 'types/Joanie';
import { CreditCardFactory } from 'utils/test/factories/joanie';
import { CreditCardFactory } from 'utils/test/factories/joanieLegacy';
import { RegisteredCreditCard } from '.';

describe('RegisteredCreditCard', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AddressFactory,
CreditCardFactory,
CourseLightFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { Address, CreditCard, Order, Product } from 'types/Joanie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CourseLightFactory,
CredentialOrderFactory,
ProductFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { SaleTunnelContext } from 'components/SaleTunnel/context';
import { SaleTunnelStepResume } from '.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
CourseLightFactory,
CredentialProductFactory,
EnrollmentFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { User } from 'types/User';
import { Maybe } from 'types/utils';
import { SaleTunnelContext, SaleTunnelContextType } from 'components/SaleTunnel/context';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/components/SaleTunnel/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Fragment } from 'react';
import { IntlProvider } from 'react-intl';
import { QueryClientProvider } from '@tanstack/react-query';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { CourseLightFactory, ProductFactory } from 'utils/test/factories/joanie';
import { CourseLightFactory, ProductFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import SaleTunnel from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MemoryRouter } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import { QueryClientProvider } from '@tanstack/react-query';
import fetchMock from 'fetch-mock';
import { ContractFactory, CredentialOrderFactory } from 'utils/test/factories/joanie';
import { ContractFactory, CredentialOrderFactory } from 'utils/test/factories/joanieLegacy';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { useOmniscientOrders } from 'hooks/useOrders';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ContractFactory,
CredentialOrderFactory,
NestedCredentialOrderFactory,
} from 'utils/test/factories/joanie';
} from 'utils/test/factories/joanieLegacy';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import JoanieApiProvider from 'contexts/JoanieApiContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UserFactory,
} from 'utils/test/factories/richie';
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
import { CourseListItemFactory } from 'utils/test/factories/joanie';
import { CourseListItemFactory } from 'utils/test/factories/joanieLegacy';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { mockPaginatedResponse } from 'utils/test/mockPaginatedResponse';
import { expectNoSpinner } from 'utils/test/expectSpinner';
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/contexts/JoanieApiContext/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PropsWithChildren } from 'react';
import { createContext, useContext } from 'react';
import type * as Joanie from 'types/Joanie';
import API from 'api/joanie';
import { JoanieLegacyClient as JoanieApi } from 'api/joanie';
import type { Maybe } from 'types/utils';

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

return <JoanieApiContext.Provider value={api}>{children}</JoanieApiContext.Provider>;
};
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/contexts/SessionContext/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('SessionProvider', () => {
});

it('uses BaseSessionProvider if joanie is disabled', async () => {
jest.doMock('api/joanie.ts', () => ({
jest.doMock('api/joanie/index.ts', () => ({
isJoanieEnabled: false,
}));
jest.doMock('./BaseSessionProvider', () => ({
Expand All @@ -75,7 +75,7 @@ describe('SessionProvider', () => {
});

it('uses JoanieSessionProvider if joanie is enabled', async () => {
jest.doMock('api/joanie.ts', () => ({
jest.doMock('api/joanie/index.ts', () => ({
isJoanieEnabled: true,
}));
jest.doMock('./BaseSessionProvider', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/hooks/useContractAbilities/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from '@testing-library/react';
import useContractAbilities from 'hooks/useContractAbilities/index';
import { ContractFactory } from 'utils/test/factories/joanie';
import { ContractFactory } from 'utils/test/factories/joanieLegacy';
import { ContractActions } from 'utils/AbilitiesHelper/types';

describe('useContractAbilities', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/frontend/js/hooks/useCourseProductUnion/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { History, HistoryContext } from 'hooks/useHistory';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { SessionProvider } from 'contexts/SessionContext';
import { getRoutes } from 'api/joanie';
import { getRoutesLegacy } from 'api/joanie';
import { mockPaginatedResponse } from 'utils/test/mockPaginatedResponse';
import { CourseListItemFactory, CourseProductRelationFactory } from 'utils/test/factories/joanie';
import {
CourseListItemFactory,
CourseProductRelationFactory,
} from 'utils/test/factories/joanieLegacy';
import { useCourseProductUnion } from '.';

jest.mock('utils/context', () => ({
Expand Down Expand Up @@ -74,7 +77,7 @@ describe('useCourseProductUnion', () => {
});

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

it('should call organization courses and organization coursesProductRelation endpoints', async () => {
const organizationId = 'DUMMY_ORGANIZATION_ID';
const ROUTES = getRoutes();
const ROUTES = getRoutesLegacy();
const organizationCoursesUrl = ROUTES.organizations.courses.get
.replace(':organization_id', organizationId)
.replace(':id/', '');
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/hooks/useCourses/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RichieContextFactory as mockRichieContextFactory,
UserFactory,
} from 'utils/test/factories/richie';
import { CourseListItemFactory } from 'utils/test/factories/joanie';
import { CourseListItemFactory } from 'utils/test/factories/joanieLegacy';
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { User } from 'types/User';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/hooks/useCreditCards/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fetchMock from 'fetch-mock';
import { PropsWithChildren } from 'react';
import { act, renderHook, waitFor } from '@testing-library/react';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { CreditCardFactory } from 'utils/test/factories/joanie';
import { CreditCardFactory } from 'utils/test/factories/joanieLegacy';
import { useCreditCard, useCreditCards } from 'hooks/useCreditCards/index';
import { SessionProvider } from 'contexts/SessionContext';
import { Deferred } from 'utils/test/deferred';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { renderHook, waitFor } from '@testing-library/react';
import fetchMock from 'fetch-mock';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { OrganizationFactory } from 'utils/test/factories/joanie';
import { OrganizationFactory } from 'utils/test/factories/joanieLegacy';
import { Organization } from 'types/Joanie';
import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
import useDefaultOrganizationId from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { handle } from 'utils/errors/handle';
import { Certificate } from 'types/Joanie';
import { SessionProvider } from 'contexts/SessionContext';
import { Deferred } from 'utils/test/deferred';
import { CertificateFactory } from 'utils/test/factories/joanie';
import { CertificateFactory } from 'utils/test/factories/joanieLegacy';
import { HttpStatusCode } from 'utils/errors/HttpError';

jest.mock('utils/errors/handle');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QueryClientProvider } from '@tanstack/react-query';
import { PropsWithChildren } from 'react';
import { IntlProvider } from 'react-intl';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { JoanieUserProfileFactory } from 'utils/test/factories/joanie';
import { JoanieUserProfileFactory } from 'utils/test/factories/joanieLegacy';
import { JoanieUserApiAbilityActions } from 'types/User';
import { JoanieUserProfileActions } from 'utils/AbilitiesHelper/types';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/hooks/useProductOrder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PropsWithChildren } from 'react';
import { act, renderHook, waitFor } from '@testing-library/react';
import { faker } from '@faker-js/faker';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { CourseLightFactory, CredentialOrderFactory } from 'utils/test/factories/joanie';
import { CourseLightFactory, CredentialOrderFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { Deferred } from 'utils/test/deferred';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IntlProvider } from 'react-intl';
import userEvent, { UserEvent } from '@testing-library/user-event';
import { PropsWithChildren } from 'react';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRouteMessages';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRouteMessages';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { StorybookHelper } from 'utils/StorybookHelper';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { DashboardEditAddress } from './DashboardEditAddress';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { QueryClientProvider } from '@tanstack/react-query';
import fetchMock from 'fetch-mock';
import { findByText } from '@storybook/testing-library';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { AddressFactory } from 'utils/test/factories/joanie';
import { AddressFactory } from 'utils/test/factories/joanieLegacy';
import { SessionProvider } from 'contexts/SessionContext';
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRouteMessages';
Expand Down
Loading