diff --git a/src/editors/data/constants/requests.js b/src/editors/data/constants/requests.js index 7487f806c..cf3eaf7fd 100644 --- a/src/editors/data/constants/requests.js +++ b/src/editors/data/constants/requests.js @@ -16,7 +16,6 @@ export const RequestKeys = StrictDict({ saveBlock: 'saveBlock', uploadAsset: 'uploadAsset', allowThumbnailUpload: 'allowThumbnailUpload', - videoSharingEnabledForCourse: 'videoSharingEnabledForCourse', uploadThumbnail: 'uploadThumbnail', uploadTranscript: 'uploadTranscript', deleteTranscript: 'deleteTranscript', @@ -27,4 +26,5 @@ export const RequestKeys = StrictDict({ importTranscript: 'importTranscript', uploadImage: 'uploadImage', fetchAdvanceSettings: 'fetchAdvanceSettings', + fetchVideoFeatures: 'fetchVideoFeatures', }); diff --git a/src/editors/data/redux/requests/reducer.js b/src/editors/data/redux/requests/reducer.js index 53a8fecef..1c28205fd 100644 --- a/src/editors/data/redux/requests/reducer.js +++ b/src/editors/data/redux/requests/reducer.js @@ -11,7 +11,6 @@ const initialState = { [RequestKeys.saveBlock]: { status: RequestStates.inactive }, [RequestKeys.uploadAsset]: { status: RequestStates.inactive }, [RequestKeys.allowThumbnailUpload]: { status: RequestStates.inactive }, - [RequestKeys.videoSharingEnabledForCourse]: { status: RequestStates.inactive }, [RequestKeys.uploadThumbnail]: { status: RequestStates.inactive }, [RequestKeys.uploadTranscript]: { status: RequestStates.inactive }, [RequestKeys.deleteTranscript]: { status: RequestStates.inactive }, @@ -19,6 +18,7 @@ const initialState = { [RequestKeys.fetchAssets]: { status: RequestStates.inactive }, [RequestKeys.checkTranscriptsForImport]: { status: RequestStates.inactive }, [RequestKeys.importTranscript]: { status: RequestStates.inactive }, + [RequestKeys.fetchVideoFeatures]: { status: RequestStates.inactive }, }; // eslint-disable-next-line no-unused-vars diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index bbb0000df..b265d2479 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -136,17 +136,6 @@ export const fetchAssets = ({ ...rest }) => (dispatch, getState) => { })); }; -export const videoSharingEnabledForCourse = ({ ...rest }) => (dispatch, getState) => { - dispatch(module.networkRequest({ - requestKey: RequestKeys.videoSharingEnabledForCourse, - promise: api.videoSharingEnabledForCourse({ - studioEndpointUrl: selectors.app.studioEndpointUrl(getState()), - learningContextId: selectors.app.learningContextId(getState()), - }), - ...rest, - })); -}; - export const allowThumbnailUpload = ({ ...rest }) => (dispatch, getState) => { dispatch(module.networkRequest({ requestKey: RequestKeys.allowThumbnailUpload, @@ -283,6 +272,17 @@ export const fetchAdvanceSettings = ({ ...rest }) => (dispatch, getState) => { })); }; +export const fetchVideoFeatures = ({ ...rest }) => (dispatch, getState) => { + dispatch(module.networkRequest({ + requestKey: RequestKeys.fetchVideoFeatures, + promise: api.fetchVideoFeatures({ + studioEndpointUrl: selectors.app.studioEndpointUrl(getState()), + learningContextId: selectors.app.learningContextId(getState()), + }), + ...rest, + })); +}; + export default StrictDict({ fetchBlock, fetchStudioView, @@ -290,7 +290,6 @@ export default StrictDict({ saveBlock, fetchAssets, uploadAsset, - videoSharingEnabledForCourse, allowThumbnailUpload, uploadThumbnail, deleteTranscript, @@ -301,4 +300,5 @@ export default StrictDict({ checkTranscriptsForImport, importTranscript, fetchAdvanceSettings, + fetchVideoFeatures, }); diff --git a/src/editors/data/redux/thunkActions/requests.test.js b/src/editors/data/redux/thunkActions/requests.test.js index a0d2e64dd..ea77e5d81 100644 --- a/src/editors/data/redux/thunkActions/requests.test.js +++ b/src/editors/data/redux/thunkActions/requests.test.js @@ -29,14 +29,13 @@ jest.mock('../../services/cms/api', () => ({ fetchAssets: ({ id, url }) => ({ id, url }), uploadAsset: (args) => args, loadImages: jest.fn(), - videoSharingEnabledForCourse: (args) => args, - allowThumbnailUpload: (args) => args, uploadThumbnail: (args) => args, uploadTranscript: (args) => args, deleteTranscript: (args) => args, getTranscript: (args) => args, checkTranscriptsForImport: (args) => args, importTranscript: (args) => args, + fetchVideoFeatures: (args) => args, })); const apiKeys = keyStore(api); @@ -303,35 +302,6 @@ describe('requests thunkActions module', () => { }, }); }); - describe('videoSharingEnabledForCourse', () => { - testNetworkRequestAction({ - action: requests.videoSharingEnabledForCourse, - args: { ...fetchParams }, - expectedString: 'with videoSharingEnabledForCourse promise', - expectedData: { - ...fetchParams, - requestKey: RequestKeys.videoSharingEnabledForCourse, - promise: api.videoSharingEnabledForCourse({ - studioEndpointUrl: selectors.app.studioEndpointUrl(testState), - learningContextId: selectors.app.learningContextId(testState), - }), - }, - }); - }); - describe('allowThumbnailUpload', () => { - testNetworkRequestAction({ - action: requests.allowThumbnailUpload, - args: { ...fetchParams }, - expectedString: 'with allowThumbnailUpload promise', - expectedData: { - ...fetchParams, - requestKey: RequestKeys.allowThumbnailUpload, - promise: api.allowThumbnailUpload({ - studioEndpointUrl: selectors.app.studioEndpointUrl(testState), - }), - }, - }); - }); describe('uploadThumbnail', () => { const thumbnail = 'SoME tHumbNAil CoNtent As String'; const videoId = 'SoME VidEOid CoNtent As String'; @@ -478,5 +448,20 @@ describe('requests thunkActions module', () => { }, }); }); + describe('fetchVideoFeatures', () => { + testNetworkRequestAction({ + action: requests.fetchVideoFeatures, + args: { ...fetchParams }, + expectedString: 'with fetchVideoFeatures promise', + expectedData: { + ...fetchParams, + requestKey: RequestKeys.fetchVideoFeatures, + promise: api.fetchVideoFeatures({ + studioEndpointUrl: selectors.app.studioEndpointUrl(testState), + learningContextId: selectors.app.learningContextId(testState), + }), + }, + }); + }); }); }); diff --git a/src/editors/data/redux/thunkActions/video.js b/src/editors/data/redux/thunkActions/video.js index 4839d68fe..837147c42 100644 --- a/src/editors/data/redux/thunkActions/video.js +++ b/src/editors/data/redux/thunkActions/video.js @@ -57,13 +57,9 @@ export const loadVideoData = () => (dispatch, getState) => { }, thumbnail: rawVideoData.thumbnail, })); - dispatch(requests.allowThumbnailUpload({ + dispatch(requests.fetchVideoFeatures({ onSuccess: (response) => dispatch(actions.video.updateField({ allowThumbnailUpload: response.data.allowThumbnailUpload, - })), - })); - dispatch(requests.videoSharingEnabledForCourse({ - onSuccess: (response) => dispatch(actions.video.updateField({ videoSharingEnabledForCourse: response.data.videoSharingEnabled, })), })); diff --git a/src/editors/data/redux/thunkActions/video.test.js b/src/editors/data/redux/thunkActions/video.test.js index e83043512..24ea9d60c 100644 --- a/src/editors/data/redux/thunkActions/video.test.js +++ b/src/editors/data/redux/thunkActions/video.test.js @@ -22,7 +22,6 @@ jest.mock('..', () => ({ })); jest.mock('./requests', () => ({ uploadAsset: (args) => ({ uploadAsset: args }), - videoSharingEnabledForCourse: (args) => ({ videoSharingEnabledForCourse: args }), allowThumbnailUpload: (args) => ({ allowThumbnailUpload: args }), uploadThumbnail: (args) => ({ uploadThumbnail: args }), deleteTranscript: (args) => ({ deleteTranscript: args }), @@ -31,6 +30,7 @@ jest.mock('./requests', () => ({ updateTranscriptLanguage: (args) => ({ updateTranscriptLanguage: args }), checkTranscriptsForImport: (args) => ({ checkTranscriptsForImport: args }), importTranscript: (args) => ({ importTranscript: args }), + fetchVideoFeatures: (args) => ({ fetchVideoFeatures: args }), })); jest.mock('../../../utils', () => ({ @@ -49,9 +49,13 @@ const mockFilename = 'soMEtRANscRipT.srt'; const mockThumbnail = 'sOMefILE'; const mockThumbnailResponse = { data: { image_url: 'soMEimAGEUrL' } }; const thumbnailUrl = 'soMEimAGEUrL'; -const mockAllowThumbnailUpload = { data: { allowThumbnailUpload: 'soMEbOolEAn' } }; const mockAllowTranscriptImport = { data: { command: 'import' } }; -const mockVideoSharingEnabledForCourse = { data: { videoSharingEnabled: 'someBOoOoOlean' } }; +const mockVideoFeatures = { + data: { + allowThumbnailUpload: 'soMEbOolEAn', + videoSharingEnabled: 'someBOoOoOlean', + }, +}; const testMetadata = { download_track: 'dOWNlOAdTraCK', @@ -100,7 +104,6 @@ describe('video thunkActions', () => { let dispatchedLoad; let dispatchedAction1; let dispatchedAction2; - let dispatchedAction3; beforeEach(() => { jest.spyOn(thunkActions, thunkActionsKeys.determineVideoSources).mockReturnValue({ videoUrl: 'videOsOurce', @@ -124,23 +127,18 @@ describe('video thunkActions', () => { [dispatchedLoad], [dispatchedAction1], [dispatchedAction2], - [dispatchedAction3], ] = dispatch.mock.calls; }); afterEach(() => { jest.restoreAllMocks(); }); - it('dispatches allowThumbnailUpload action', () => { + it('dispatches fetchVideoFeatures action', () => { expect(dispatchedLoad).not.toEqual(undefined); - expect(dispatchedAction1.allowThumbnailUpload).not.toEqual(undefined); - }); - it('dispatches videoSharingEnabledForCourse action', () => { - expect(dispatchedLoad).not.toEqual(undefined); - expect(dispatchedAction2.videoSharingEnabledForCourse).not.toEqual(undefined); + expect(dispatchedAction1.fetchVideoFeatures).not.toEqual(undefined); }); it('dispatches checkTranscriptsForImport action', () => { expect(dispatchedLoad).not.toEqual(undefined); - expect(dispatchedAction3.checkTranscriptsForImport).not.toEqual(undefined); + expect(dispatchedAction2.checkTranscriptsForImport).not.toEqual(undefined); }); it('dispatches actions.video.load', () => { expect(dispatchedLoad.load).toEqual({ @@ -176,18 +174,14 @@ describe('video thunkActions', () => { }); it('dispatches actions.video.updateField on success', () => { dispatch.mockClear(); - dispatchedAction1.allowThumbnailUpload.onSuccess(mockAllowThumbnailUpload); + dispatchedAction1.fetchVideoFeatures.onSuccess(mockVideoFeatures); expect(dispatch).toHaveBeenCalledWith(actions.video.updateField({ - allowThumbnailUpload: mockAllowThumbnailUpload.data.allowThumbnailUpload, + allowThumbnailUpload: mockVideoFeatures.data.allowThumbnailUpload, + videoSharingEnabledForCourse: mockVideoFeatures.data.videoSharingEnabled, })); dispatch.mockClear(); - dispatchedAction2.videoSharingEnabledForCourse.onSuccess(mockVideoSharingEnabledForCourse); - expect(dispatch).toHaveBeenCalledWith(actions.video.updateField({ - videoSharingEnabledForCourse: mockVideoSharingEnabledForCourse.data.videoSharingEnabled, - })); - - dispatchedAction3.checkTranscriptsForImport.onSuccess(mockAllowTranscriptImport); + dispatchedAction2.checkTranscriptsForImport.onSuccess(mockAllowTranscriptImport); expect(dispatch).toHaveBeenCalledWith(actions.video.updateField({ allowTranscriptImport: true, })); diff --git a/src/editors/data/services/cms/api.js b/src/editors/data/services/cms/api.js index 64abad560..67ad92eb5 100644 --- a/src/editors/data/services/cms/api.js +++ b/src/editors/data/services/cms/api.js @@ -36,17 +36,6 @@ export const apiMethods = { data, ); }, - videoSharingEnabledForCourse: ({ - studioEndpointUrl, - learningContextId, - }) => get( - urls.videoSharingEnabledForCourse({ studioEndpointUrl, learningContextId }), - ), - allowThumbnailUpload: ({ - studioEndpointUrl, - }) => get( - urls.allowThumbnailUpload({ studioEndpointUrl }), - ), uploadThumbnail: ({ studioEndpointUrl, learningContextId, @@ -211,6 +200,12 @@ export const apiMethods = { title, }), ), + fetchVideoFeatures: ({ + studioEndpointUrl, + learningContextId, + }) => get( + urls.videoFeatures({ studioEndpointUrl, learningContextId }), + ), }; export const loadImage = (imageData) => ({ diff --git a/src/editors/data/services/cms/api.test.js b/src/editors/data/services/cms/api.test.js index 0aeccea44..b2a97fa7f 100644 --- a/src/editors/data/services/cms/api.test.js +++ b/src/editors/data/services/cms/api.test.js @@ -22,7 +22,7 @@ jest.mock('./urls', () => ({ thumbnailUpload: jest.fn().mockName('urls.thumbnailUpload'), checkTranscriptsForImport: jest.fn().mockName('urls.checkTranscriptsForImport'), replaceTranscript: jest.fn().mockName('urls.replaceTranscript'), - videoSharingEnabledForCourse: jest.fn().mockName('urls.videoSharingEnabledForCourse'), + videoFeatures: jest.fn().mockName('urls.videoFeatures'), })); jest.mock('./utils', () => ({ @@ -246,21 +246,6 @@ describe('cms api', () => { ); }); }); - describe('allowThumbnailUpload', () => { - it('should call get with url.allowThumbnailUpload', () => { - apiMethods.allowThumbnailUpload({ studioEndpointUrl }); - expect(get).toHaveBeenCalledWith(urls.allowThumbnailUpload({ studioEndpointUrl })); - }); - }); - }); - describe('videoSharing', () => { - describe('videoSharingEnabledForCourse', () => { - it('should call get with url.videoSharingEnabledForCourse', () => { - const args = { studioEndpointUrl, learningContextId }; - apiMethods.videoSharingEnabledForCourse({ ...args }); - expect(get).toHaveBeenCalledWith(urls.videoSharingEnabledForCourse({ ...args })); - }); - }); }); describe('videoTranscripts', () => { const language = 'la'; @@ -516,4 +501,11 @@ describe('cms api', () => { expect(api.processLicense(licenseType, licenseDetails)).toEqual('all-rights-reserved'); }); }); + describe('fetchVideoFeatures', () => { + it('should call get with url.videoFeatures', () => { + const args = { studioEndpointUrl, learningContextId }; + apiMethods.fetchVideoFeatures({ ...args }); + expect(get).toHaveBeenCalledWith(urls.videoFeatures({ ...args })); + }); + }); }); diff --git a/src/editors/data/services/cms/mockApi.js b/src/editors/data/services/cms/mockApi.js index c93853f3d..c7e7cb279 100644 --- a/src/editors/data/services/cms/mockApi.js +++ b/src/editors/data/services/cms/mockApi.js @@ -123,14 +123,6 @@ export const fetchCourseDetails = ({ studioEndpointUrl, learningContextId }) => }, }); // eslint-disable-next-line -export const videoSharingEnabledForCourse = ({ studioEndpointUrl, learningContextId }) => mockPromise({ - data: true, -}); -// eslint-disable-next-line -export const allowThumbnailUpload = ({ studioEndpointUrl }) => mockPromise({ - data: true, -}); -// eslint-disable-next-line export const checkTranscripts = ({youTubeId, studioEndpointUrl, blockId, videoId}) => mockPromise({ data: { command: 'import', @@ -146,6 +138,13 @@ export const importTranscript = ({youTubeId, studioEndpointUrl, blockId}) => moc export const fetchAdvanceSettings = ({ studioEndpointUrl, learningContextId }) => mockPromise({ data: { allow_unsupported_xblocks: { value: true } }, }); +// eslint-disable-next-line +export const fetchVideoFeatures = ({ studioEndpointUrl, learningContextId }) => mockPromise({ + data: { + allowThumbnailUpload: true, + videoSharingEnabledForCourse: true, + }, +}); export const normalizeContent = ({ blockId, diff --git a/src/editors/data/services/cms/urls.js b/src/editors/data/services/cms/urls.js index f0e75d02f..c8642c741 100644 --- a/src/editors/data/services/cms/urls.js +++ b/src/editors/data/services/cms/urls.js @@ -31,14 +31,6 @@ export const courseAssets = ({ studioEndpointUrl, learningContextId }) => ( `${studioEndpointUrl}/assets/${learningContextId}/?page_size=500` ); -export const allowThumbnailUpload = ({ studioEndpointUrl }) => ( - `${studioEndpointUrl}/video_images_upload_enabled` -); - -export const videoSharingEnabledForCourse = ({ studioEndpointUrl, learningContextId }) => ( - `${studioEndpointUrl}/video_sharing_enabled/${learningContextId}` -); - export const thumbnailUpload = ({ studioEndpointUrl, learningContextId, videoId }) => ( `${studioEndpointUrl}/video_images/${learningContextId}/${videoId}` ); @@ -70,3 +62,7 @@ export const replaceTranscript = ({ studioEndpointUrl, parameters }) => ( export const courseAdvanceSettings = ({ studioEndpointUrl, learningContextId }) => ( `${studioEndpointUrl}/api/contentstore/v0/advanced_settings/${learningContextId}` ); + +export const videoFeatures = ({ studioEndpointUrl, learningContextId }) => ( + `${studioEndpointUrl}/video_features/${learningContextId}` +); diff --git a/src/editors/data/services/cms/urls.test.js b/src/editors/data/services/cms/urls.test.js index 572853a6d..9f5282a37 100644 --- a/src/editors/data/services/cms/urls.test.js +++ b/src/editors/data/services/cms/urls.test.js @@ -6,8 +6,6 @@ import { blockAncestor, blockStudioView, courseAssets, - videoSharingEnabledForCourse, - allowThumbnailUpload, thumbnailUpload, downloadVideoTranscriptURL, videoTranscripts, @@ -15,6 +13,7 @@ import { courseDetailsUrl, checkTranscriptsForImport, replaceTranscript, + videoFeatures, } from './urls'; describe('cms url methods', () => { @@ -84,18 +83,6 @@ describe('cms url methods', () => { .toEqual(`${studioEndpointUrl}/assets/${learningContextId}/?page_size=500`); }); }); - describe('allowThumbnailUpload', () => { - it('returns url with studioEndpointUrl', () => { - expect(allowThumbnailUpload({ studioEndpointUrl })) - .toEqual(`${studioEndpointUrl}/video_images_upload_enabled`); - }); - }); - describe('videoSharingEnabledForCourse', () => { - it('returns url with studioEndpointUrl and learningContextId', () => { - expect(videoSharingEnabledForCourse({ studioEndpointUrl, learningContextId })) - .toEqual(`${studioEndpointUrl}/video_sharing_enabled/${learningContextId}`); - }); - }); describe('thumbnailUpload', () => { it('returns url with studioEndpointUrl, learningContextId, and videoId', () => { expect(thumbnailUpload({ studioEndpointUrl, learningContextId, videoId })) @@ -138,4 +125,10 @@ describe('cms url methods', () => { .toEqual(`${studioEndpointUrl}/transcripts/replace?data=${parameters}`); }); }); + describe('videoFeatures', () => { + it('returns url with studioEndpointUrl and learningContextId', () => { + expect(videoFeatures({ studioEndpointUrl, learningContextId })) + .toEqual(`${studioEndpointUrl}/video_features/${learningContextId}`); + }); + }); });