From 3936737b48182d5c05cb1520f2da8544236ebe3f Mon Sep 17 00:00:00 2001 From: Marcos Rigoli Date: Thu, 20 Jun 2024 11:17:08 -0300 Subject: [PATCH] feat: Include org filter when requesting LTI providers (#1114) * feat: Include org filter when requesting LTI providers * chore: Created silent version for CI testing to avoid log flooding --- Makefile | 2 +- package.json | 1 + plugins/course-apps/proctoring/Settings.jsx | 4 +++- .../course-apps/proctoring/Settings.test.jsx | 23 ++++++++++++++++--- src/data/services/ExamsApiService.js | 4 ++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index aea3dd304..5c2f29356 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ validate: npm run i18n_extract npm run lint -- --max-warnings 0 npm run types - npm run test + npm run test:ci npm run build .PHONY: validate.ci diff --git a/package.json b/package.json index 7ab1b5790..30ad0c6b0 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "start": "fedx-scripts webpack-dev-server --progress", "start:with-theme": "paragon install-theme && npm start && npm install", "test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests", + "test:ci": "TZ=UTC fedx-scripts jest --silent --coverage --passWithNoTests", "types": "tsc --noEmit" }, "husky": { diff --git a/plugins/course-apps/proctoring/Settings.jsx b/plugins/course-apps/proctoring/Settings.jsx index 255152aa7..4debbcfd7 100644 --- a/plugins/course-apps/proctoring/Settings.jsx +++ b/plugins/course-apps/proctoring/Settings.jsx @@ -64,6 +64,8 @@ const ProctoringSettings = ({ intl, onClose }) => { } const { courseId } = useContext(PagesAndResourcesContext); + const courseDetails = useModel('courseDetails', courseId); + const org = courseDetails?.org; const appInfo = useModel('courseApps', 'proctoring'); const alertRef = React.createRef(); const saveStatusAlertRef = React.createRef(); @@ -490,7 +492,7 @@ const ProctoringSettings = ({ intl, onClose }) => { Promise.all([ StudioApiService.getProctoredExamSettingsData(courseId), ExamsApiService.isAvailable() ? ExamsApiService.getCourseExamConfiguration(courseId) : Promise.resolve(), - ExamsApiService.isAvailable() ? ExamsApiService.getAvailableProviders() : Promise.resolve(), + ExamsApiService.isAvailable() ? ExamsApiService.getAvailableProviders(org) : Promise.resolve(), ]) .then( ([settingsResponse, examConfigResponse, ltiProvidersResponse]) => { diff --git a/plugins/course-apps/proctoring/Settings.test.jsx b/plugins/course-apps/proctoring/Settings.test.jsx index c4455be4e..e0e700edc 100644 --- a/plugins/course-apps/proctoring/Settings.test.jsx +++ b/plugins/course-apps/proctoring/Settings.test.jsx @@ -15,8 +15,9 @@ import initializeStore from 'CourseAuthoring/store'; import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider'; import ProctoredExamSettings from './Settings'; +const courseId = 'course-v1%3AedX%2BDemoX%2BDemo_Course'; const defaultProps = { - courseId: 'course-v1%3AedX%2BDemoX%2BDemo_Course', + courseId, onClose: () => {}, }; const IntlProctoredExamSettings = injectIntl(ProctoredExamSettings); @@ -34,7 +35,7 @@ const intlWrapper = children => ( let axiosMock; describe('ProctoredExamSettings', () => { - function setupApp(isAdmin = true) { + function setupApp(isAdmin = true, org = undefined) { mergeConfig({ EXAMS_BASE_URL: 'http://exams.testing.co', }, 'CourseAuthoringConfig'); @@ -52,12 +53,18 @@ describe('ProctoredExamSettings', () => { courseApps: { proctoring: {}, }, + courseDetails: { + [courseId]: { + start: Date(), + }, + }, + ...(org ? { courseDetails: { [courseId]: { org } } } : {}), }, }); axiosMock = new MockAdapter(getAuthenticatedHttpClient()); axiosMock.onGet( - `${ExamsApiService.getExamsBaseUrl()}/api/v1/providers`, + `${ExamsApiService.getExamsBaseUrl()}/api/v1/providers${org ? `?org=${org}` : ''}`, ).reply(200, [ { name: 'test_lti', @@ -416,6 +423,16 @@ describe('ProctoredExamSettings', () => { expect(providerOption.hasAttribute('disabled')).toEqual(false); }); + it('Sends the org to the proctoring provider endpoint', async () => { + const isAdmin = false; + const org = 'test-org'; + setupApp(isAdmin, org); + mockCourseData(mockGetFutureCourseData); + await act(async () => render(intlWrapper())); + const providerOption = screen.getByTestId('proctortrack'); + expect(providerOption.hasAttribute('disabled')).toEqual(false); + }); + it('Enables all proctoring provider options if user administrator and it is after start date', async () => { const isAdmin = true; setupApp(isAdmin); diff --git a/src/data/services/ExamsApiService.js b/src/data/services/ExamsApiService.js index aa438444d..ec9b57320 100644 --- a/src/data/services/ExamsApiService.js +++ b/src/data/services/ExamsApiService.js @@ -15,9 +15,9 @@ class ExamsApiService { return `${ExamsApiService.getExamsBaseUrl()}/api/v1/configs/course_id/${courseId}`; } - static getAvailableProviders() { + static getAvailableProviders(org) { const apiClient = getAuthenticatedHttpClient(); - const providersUrl = `${ExamsApiService.getExamsBaseUrl()}/api/v1/providers`; + const providersUrl = `${ExamsApiService.getExamsBaseUrl()}/api/v1/providers${org ? `?org=${org}` : ''}`; return apiClient.get(providersUrl); }