Skip to content

Commit

Permalink
✨(frontend) rename Joanie.Course as CourseLight
Browse files Browse the repository at this point in the history
We need Course to contain lot's more information for our course
endpoint that will be make for teacher dashboard course page.
  • Loading branch information
rlecellier committed Apr 25, 2023
1 parent c126d19 commit beda2ff
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/frontend/js/components/CourseGlimpse/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import { RichieContextFactory, CourseFactory } from 'utils/test/factories/richie';
import { RichieContextFactory, CourseLightFactory } from 'utils/test/factories/richie';
import { CourseGlimpse } from '.';

export default {
Expand All @@ -11,6 +11,6 @@ type Story = StoryObj<typeof CourseGlimpse>;
export const RichieCourse: Story = {
args: {
context: RichieContextFactory().generate(),
course: CourseFactory.generate(),
course: CourseLightFactory.generate(),
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from '@storybook/react';
import { RichieContextFactory, CourseFactory } from 'utils/test/factories/richie';
import { RichieContextFactory, CourseLightFactory } from 'utils/test/factories/richie';
import { CourseGlimpseList } from '.';

export default {
Expand All @@ -11,7 +11,7 @@ type Story = StoryObj<typeof CourseGlimpseList>;
export const RichieCourseList: Story = {
args: {
context: RichieContextFactory().generate(),
courses: CourseFactory.generate(10),
courses: CourseLightFactory.generate(10),
meta: {
count: 10,
offset: 0,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/hooks/useOrders.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineMessages } from 'react-intl';
import { API, Course, Order, OrderState, PaginatedResourceQuery, Product } from 'types/Joanie';
import { API, CourseLight, Order, OrderState, PaginatedResourceQuery, Product } from 'types/Joanie';
import { useJoanieApi } from 'contexts/JoanieApiContext';
import { useSessionMutation } from 'utils/react-query/useSessionMutation';
import { QueryOptions, useResource, useResourcesCustom, UseResourcesProps } from './useResources';

export type OrderResourcesQuery = PaginatedResourceQuery & {
course?: Course['code'];
course?: CourseLight['code'];
product?: Product['id'];
state?: OrderState[];
};
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/js/types/Joanie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface CourseRun {
text: StateText;
};
title: string;
course?: Course;
course?: CourseLight;
}

// - Certificate
Expand Down Expand Up @@ -106,7 +106,7 @@ export interface CourseProduct extends Product {
target_courses: TargetCourse[];
}

export interface Course extends AbstractCourse {
export interface CourseLight extends AbstractCourse {
products: CourseProduct[];
orders?: OrderLite[];
}
Expand Down Expand Up @@ -136,7 +136,7 @@ export enum OrderState {

export interface Order {
id: string;
course?: Course['code'] | Course;
course?: CourseLight['code'] | CourseLight;
created_on: string;
enrollments: Enrollment[];
main_proforma_invoice: string;
Expand Down Expand Up @@ -183,11 +183,11 @@ export interface Address {
// Wishlist
export interface UserWishlistCourse {
id: string;
course: Course['code'];
course: CourseLight['code'];
}

export interface UserWishlistCreationPayload {
course: Course['code'];
course: CourseLight['code'];
}

// Payment
Expand Down Expand Up @@ -217,7 +217,7 @@ export interface AddressCreationPayload extends Omit<Address, 'id' | 'is_main'>

interface OrderCreationPayload {
product: Product['id'];
course: Course['code'];
course: CourseLight['code'];
billing_address?: Omit<Address, 'id' | 'is_main'>;
credit_card_id?: CreditCard['id'];
}
Expand Down
17 changes: 16 additions & 1 deletion src/frontend/js/utils/test/factories/joanie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,27 @@ export const CourseRunFactory = (scopes?: { course: Boolean }) => {
text: 'closing on',
},
...(scopes?.course && {
course: CourseFactory.generate(),
course: CourseLightFactory.generate(),
}),
});
};

export const CourseFactory = createSpec({
code: faker.random.alphaNumeric(5),
organization: OrganizationFactory,
title: faker.unique(faker.random.words(Math.ceil(Math.random() * 3))),
state: {
call_to_action: null,
datetime: derived(() => faker.date.past(0.25)().toISOString()),
priority: Priority.ONGOING_OPEN,
text: 'Ongoing',
},
cover_image: {
src: '/static/course_cover_image.jpg',
},
});

export const CourseLightFactory = createSpec({
code: faker.random.alphaNumeric(5),
organization: OrganizationLightFactory,
title: faker.unique(faker.random.words(Math.ceil(Math.random() * 3))),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/utils/test/factories/richie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const RichieContextFactory = (context: Partial<CommonDataProps['context']
web_analytics_providers: derived(() => context.web_analytics_providers || null),
});

export const CourseFactory = createSpec({
export const CourseLightFactory = createSpec({
absolute_url: '',
categories: [],
code: faker.random.alphaNumeric(5),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/widgets/CourseAddToWishlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum ComponentStates {
}

export interface Props {
courseCode: Joanie.Course['code'];
courseCode: Joanie.CourseLight['code'];
}

const CourseAddToWishlist = ({ courseCode }: Props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { IntlProvider } from 'react-intl';
import { QueryClientProvider } from '@tanstack/react-query';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import {
CourseFactory,
CourseLightFactory,
CourseRunFactory,
EnrollmentFactory,
OrderFactory,
} from 'utils/test/factories/joanie';
import JoanieApiProvider from 'contexts/JoanieApiContext';
import type { Course, CourseRun, Enrollment, OrderLite } from 'types/Joanie';
import type { CourseLight, CourseRun, Enrollment, OrderLite } from 'types/Joanie';
import { Deferred } from 'utils/test/deferred';
import { Priority } from 'types';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('CourseProductCourseRuns', () => {
});

it('renders a list of course runs with a call to action to enroll', async () => {
const course: Course = CourseFactory.generate();
const course: CourseLight = CourseLightFactory.generate();
const courseRuns: CourseRun[] = CourseRunFactory().generate(2);
const order: OrderLite = OrderFactory.generate();

Expand Down Expand Up @@ -233,7 +233,7 @@ describe('CourseProductCourseRuns', () => {
});

it('enroll with errors', async () => {
const course: Course = CourseFactory.generate();
const course: CourseLight = CourseLightFactory.generate();
const courseRuns: CourseRun[] = CourseRunFactory().generate(2);
const order: OrderLite = OrderFactory.generate();
fetchMock.get(`https://joanie.test/api/v1.0/courses/${course.code}/`, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type * as Joanie from 'types/Joanie';

const Context = createContext<
Maybe<{
courseCode: Joanie.Course['code'];
courseCode: Joanie.CourseLight['code'];
productId: Joanie.Product['id'];
}>
>(undefined);

export interface CourseProductProviderProps {
courseCode: Joanie.Course['code'];
courseCode: Joanie.CourseLight['code'];
productId: Joanie.Product['id'];
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/widgets/CourseProductItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const messages = defineMessages({

export interface Props {
productId: Joanie.Product['id'];
courseCode: Joanie.Course['code'];
courseCode: Joanie.CourseLight['code'];
}

const CourseProductItem = ({ productId, courseCode }: Props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IntlProvider } from 'react-intl';
import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
import { Certificate, Course } from 'types/Joanie';
import { Certificate, CourseLight } from 'types/Joanie';
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
import { SessionProvider } from 'contexts/SessionContext';
import { DashboardItemCertificate } from 'widgets/Dashboard/components/DashboardItem/Certificate/index';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('<DashboardCertificate/>', () => {
render(<DashboardItemCertificate certificate={certificate} />, { wrapper: Wrapper });

await waitFor(() => screen.getByText(certificate.certificate_definition.title));
screen.getByText((certificate.order.course as Course).title);
screen.getByText((certificate.order.course as CourseLight).title);
screen.getByText(
'Issued on ' +
new Intl.DateTimeFormat('en', DEFAULT_DATE_FORMAT).format(new Date(certificate.issued_on)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineMessages, FormattedMessage } from 'react-intl';
import { Button } from 'components/Button';
import { Icon } from 'components/Icon';
import { Certificate, CertificateDefinition, Course } from 'types/Joanie';
import { Certificate, CertificateDefinition, CourseLight } from 'types/Joanie';
import { useDownloadCertificate } from 'hooks/useDownloadCertificate';
import { Spinner } from 'components/Spinner';
import useDateFormat from 'hooks/useDateFormat';
Expand Down Expand Up @@ -58,7 +58,7 @@ export const DashboardItemCertificate = ({
throw new Error('certificate or certificateDefinition is required');
}

const course = certificate?.order.course as Maybe<Course>;
const course = certificate?.order.course as Maybe<CourseLight>;
const { download, loading } = useDownloadCertificate();
const formatDate = useDateFormat();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryObj } from '@storybook/react';
import { createMemoryRouter, RouterProvider } from 'react-router-dom';
import faker from 'faker';
import { CourseFactory } from 'utils/test/factories/joanie';
import { CourseLightFactory } from 'utils/test/factories/joanie';
import { StorybookHelper } from 'utils/StorybookHelper';
import { Priority } from 'types';
import { enrollment } from './stories.mock';
Expand Down Expand Up @@ -39,7 +39,7 @@ type Story = StoryObj<typeof DashboardItemCourseEnrolling>;

export const ReadonlyEnrolledOpened: Story = {
args: {
course: CourseFactory.generate(),
course: CourseLightFactory.generate(),
activeEnrollment: {
...enrollment,
course_run: {
Expand All @@ -53,7 +53,7 @@ export const ReadonlyEnrolledOpened: Story = {

export const ReadonlyEnrolledClosed: Story = {
args: {
course: CourseFactory.generate(),
course: CourseLightFactory.generate(),
activeEnrollment: {
...enrollment,
course_run: {
Expand All @@ -67,6 +67,6 @@ export const ReadonlyEnrolledClosed: Story = {

export const ReadonlyNotEnrolled: Story = {
args: {
course: CourseFactory.generate(),
course: CourseLightFactory.generate(),
},
};

0 comments on commit beda2ff

Please sign in to comment.