Files
frontend-app-authoring/src/editors/data/services/cms/api.js
Ben Warzeski 09e9d865c2 Chore: Test coverage hunt (#36)
* chore: add brand mocking in gallery view

* feat: dev gallery app

* chore: link mock block ids to real block type api

* feat: image settings page features

* chore: more tests

* chore: keystore util and more testing

* chore: more tests

* chore: re-install lint plugin...

* chore: lint fixes

* chore: moar tests

* chore: remove brand from module.config and link gallery to edx.org brand
2022-03-24 11:15:32 -04:00

62 lines
1.4 KiB
JavaScript

import * as urls from './urls';
import { get, post } from './utils';
import * as module from './api';
import * as mockApi from './mockApi';
export const apiMethods = {
fetchBlockById: ({ blockId, studioEndpointUrl }) => get(
urls.block({ blockId, studioEndpointUrl }),
),
fetchByUnitId: ({ blockId, studioEndpointUrl }) => get(
urls.blockAncestor({ studioEndpointUrl, blockId }),
),
normalizeContent: ({
blockId,
blockType,
content,
courseId,
title,
}) => {
if (blockType === 'html') {
return {
category: blockType,
couseKey: courseId,
data: content,
has_changes: true,
id: blockId,
metadata: { display_name: title },
};
}
throw new TypeError(`No Block in V2 Editors named /"${blockType}/", Cannot Save Content.`);
},
saveBlock: ({
blockId,
blockType,
content,
courseId,
studioEndpointUrl,
title,
}) => post(
urls.block({ studioEndpointUrl, blockId }),
module.apiMethods.normalizeContent({
blockType,
content,
blockId,
courseId,
title,
}),
),
};
export const checkMockApi = (key) => {
if (process.env.REACT_APP_DEVGALLERY) {
return mockApi[key];
}
return module.apiMethods[key];
};
export default Object.keys(apiMethods).reduce(
(obj, key) => ({ ...obj, [key]: checkMockApi(key) }),
{},
);