From 3ce496a13cc3c8b3da66330672dfdff892be610b Mon Sep 17 00:00:00 2001 From: Sergio Valero Date: Wed, 19 Jun 2024 14:27:07 -0400 Subject: [PATCH] fix: filter classes by courseId --- src/features/Classes/ClassesTable/columns.jsx | 2 +- src/features/Classes/data/_test_/redux.test.js | 6 ++++-- src/features/Classes/data/thunks.js | 8 ++++---- src/features/Common/data/_test_/api.test.js | 6 +++--- src/features/Common/data/api.js | 6 +++--- src/features/Courses/CoursesDetailPage/index.jsx | 8 ++++---- src/features/Dashboard/data/_test_/redux.test.jsx | 6 ++++-- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/features/Classes/ClassesTable/columns.jsx b/src/features/Classes/ClassesTable/columns.jsx index dd9d5350..d4e0ee8d 100644 --- a/src/features/Classes/ClassesTable/columns.jsx +++ b/src/features/Classes/ClassesTable/columns.jsx @@ -21,7 +21,7 @@ const columns = [ accessor: 'className', Cell: ({ row }) => ( {row.values.className} diff --git a/src/features/Classes/data/_test_/redux.test.js b/src/features/Classes/data/_test_/redux.test.js index 1d89c86d..acfbda7f 100644 --- a/src/features/Classes/data/_test_/redux.test.js +++ b/src/features/Classes/data/_test_/redux.test.js @@ -29,10 +29,11 @@ describe('Classes redux tests', () => { }); test('successful fetch classes data', async () => { - const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`; + const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`; const mockResponse = { results: [ { + masterCourseId: 'course-v1:USB+CCD+2023', masterCourseName: 'Demo MasterCourse 1', className: 'Demo Class 1', startDate: '09/21/24', @@ -91,9 +92,10 @@ describe('Classes redux tests', () => { }); test('successful fetch all classes data', async () => { - const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`; + const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`; const mockResponse = [ { + masterCourseId: 'course-v1:USB+CCD+2023', masterCourseName: 'Demo MasterCourse 1', className: 'Demo Class 1', startDate: '09/21/24', diff --git a/src/features/Classes/data/thunks.js b/src/features/Classes/data/thunks.js index b53f7213..a39e2f33 100644 --- a/src/features/Classes/data/thunks.js +++ b/src/features/Classes/data/thunks.js @@ -13,13 +13,13 @@ import { import { getClassesByInstitution } from 'features/Common/data/api'; import { initialPage } from 'features/constants'; -function fetchClassesData(id, currentPage, courseName = '', urlParamsFilters = '', limit = true) { +function fetchClassesData(id, currentPage, courseId = '', urlParamsFilters = '', limit = true) { return async (dispatch) => { dispatch(fetchClassesDataRequest()); try { const response = camelCaseObject( - await getClassesByInstitution(id, courseName, limit, currentPage, urlParamsFilters), + await getClassesByInstitution(id, courseId, limit, currentPage, urlParamsFilters), ); dispatch(fetchClassesDataSuccess(response.data)); } catch (error) { @@ -43,13 +43,13 @@ function fetchClassesOptionsData(id, courseName) { }; } -function fetchAllClassesData(id, courseName = '', urlParamsFilters = '', limit = false) { +function fetchAllClassesData(id, courseId = '', urlParamsFilters = '', limit = false) { return async (dispatch) => { dispatch(fetchAllClassesDataRequest()); try { const response = camelCaseObject( - await getClassesByInstitution(id, courseName, limit, initialPage, urlParamsFilters), + await getClassesByInstitution(id, courseId, limit, initialPage, urlParamsFilters), ); dispatch(fetchAllClassesDataSuccess(response.data)); } catch (error) { diff --git a/src/features/Common/data/_test_/api.test.js b/src/features/Common/data/_test_/api.test.js index ccb1013a..03473732 100644 --- a/src/features/Common/data/_test_/api.test.js +++ b/src/features/Common/data/_test_/api.test.js @@ -72,18 +72,18 @@ describe('Common api services', () => { }; const institutionId = 1; - const courseName = 'ccx1'; + const courseId = 'course-v1'; getAuthenticatedHttpClient.mockReturnValue(httpClientMock); - getClassesByInstitution(institutionId, courseName); + getClassesByInstitution(institutionId, courseId); expect(getAuthenticatedHttpClient).toHaveBeenCalledTimes(1); expect(getAuthenticatedHttpClient).toHaveBeenCalledWith(); expect(httpClientMock.get).toHaveBeenCalledTimes(1); expect(httpClientMock.get).toHaveBeenCalledWith( - `${COURSE_OPERATIONS_API_V2}/classes/?course_name=ccx1`, + `${COURSE_OPERATIONS_API_V2}/classes/?course_id=course-v1`, { params: { institution_id: 1, limit: false, page: '', diff --git a/src/features/Common/data/api.js b/src/features/Common/data/api.js index 816180c1..dcfabd09 100644 --- a/src/features/Common/data/api.js +++ b/src/features/Common/data/api.js @@ -19,8 +19,8 @@ function getLicensesByInstitution(institutionId, limit, page = 1, urlParamsFilte ); } -function getClassesByInstitution(institutionId, courseName, limit = false, page = '', urlParamsFilters = '') { - const encodedCourseName = encodeURIComponent(courseName); +function getClassesByInstitution(institutionId, courseId, limit = false, page = '', urlParamsFilters = '') { + const encodedCourseId = encodeURIComponent(courseId); const params = { limit, institution_id: institutionId, @@ -28,7 +28,7 @@ function getClassesByInstitution(institutionId, courseName, limit = false, page ...urlParamsFilters, }; return getAuthenticatedHttpClient().get( - `${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=${encodedCourseName}`, + `${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=${encodedCourseId}`, { params }, ); } diff --git a/src/features/Courses/CoursesDetailPage/index.jsx b/src/features/Courses/CoursesDetailPage/index.jsx index a8270066..cb42d14e 100644 --- a/src/features/Courses/CoursesDetailPage/index.jsx +++ b/src/features/Courses/CoursesDetailPage/index.jsx @@ -29,7 +29,7 @@ const CoursesDetailPage = () => { numberOfStudents: '-', numberOfPendingStudents: '-', masterCourseId: '-', - masterCourseName: '-', + masterCourseName: '', }; const courseInfo = useSelector((state) => state.courses.table.data) @@ -51,7 +51,7 @@ const CoursesDetailPage = () => { }; if (institution.id) { - dispatch(fetchClassesData(institution.id, initialPage, courseInfo.masterCourseName)); + dispatch(fetchClassesData(institution.id, initialPage, courseId)); dispatch(fetchCoursesData(institution.id, initialPage, null)); } @@ -62,7 +62,7 @@ const CoursesDetailPage = () => { }, [dispatch, institution.id, courseId]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { - dispatch(fetchClassesData(institution.id, currentPage, courseInfo.masterCourseName)); + dispatch(fetchClassesData(institution.id, currentPage, courseId)); }, [currentPage]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { @@ -82,7 +82,7 @@ const CoursesDetailPage = () => { -

{courseId}

+

{courseInfo.masterCourseName}

diff --git a/src/features/Dashboard/data/_test_/redux.test.jsx b/src/features/Dashboard/data/_test_/redux.test.jsx index ff96ae3b..7df8eb3d 100644 --- a/src/features/Dashboard/data/_test_/redux.test.jsx +++ b/src/features/Dashboard/data/_test_/redux.test.jsx @@ -78,11 +78,12 @@ describe('Dashboard redux tests', () => { }); test('successful fetch classesNoInstructors data', async () => { - const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`; + const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`; const mockResponse = [ { classId: 'ccx-v1:demo+demo1+2020+ccx1', className: 'ccx 1', + masterCourseId: 'course-v1:USB+CCD+2023', masterCourseName: 'Demo Course 1', instructors: [], numberOfStudents: 0, @@ -125,11 +126,12 @@ describe('Dashboard redux tests', () => { }); test('successful fetch classes data', async () => { - const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_name=`; + const classesApiUrl = `${process.env.COURSE_OPERATIONS_API_V2_BASE_URL}/classes/?course_id=`; const mockResponse = [ { classId: 'ccx-v1:demo+demo1+2020+ccx1', className: 'ccx 1', + masterCourseId: 'course-v1:USB+CCD+2023', masterCourseName: 'Demo Course 1', instructors: [], numberOfStudents: 0,