This is a text component which uses HTML.
', + metadata: { displayName: 'Introduction to Testing' }, +} satisfies api.XBlockFields; +mockXBlockFields.applyMock = () => { jest.spyOn(api, 'getXBlockFields').mockImplementation(mockXBlockFields); }; diff --git a/src/library-authoring/data/api.test.ts b/src/library-authoring/data/api.test.ts index 557488900d..36200ff91c 100644 --- a/src/library-authoring/data/api.test.ts +++ b/src/library-authoring/data/api.test.ts @@ -1,65 +1,46 @@ -import MockAdapter from 'axios-mock-adapter'; -import { initializeMockApp } from '@edx/frontend-platform'; -import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; -import { - commitLibraryChanges, - createLibraryBlock, - getCommitLibraryChangesUrl, - getCreateLibraryBlockUrl, - revertLibraryChanges, -} from './api'; - -let axiosMock; - -describe('library api calls', () => { - beforeEach(() => { - initializeMockApp({ - authenticatedUser: { - userId: 3, - username: 'abc123', - administrator: true, - roles: [], - }, +import { initializeMocks } from '../../testUtils'; +import * as api from './api'; + +describe('library data API', () => { + describe('createLibraryBlock', () => { + it('should create library block', async () => { + const { axiosMock } = initializeMocks(); + const libraryId = 'lib:org:1'; + const url = api.getCreateLibraryBlockUrl(libraryId); + axiosMock.onPost(url).reply(200); + await api.createLibraryBlock({ + libraryId, + blockType: 'html', + definitionId: '1', + }); + + expect(axiosMock.history.post[0].url).toEqual(url); }); - - axiosMock = new MockAdapter(getAuthenticatedHttpClient()); }); - afterEach(() => { - jest.clearAllMocks(); - axiosMock.restore(); - }); + describe('commitLibraryChanges', () => { + it('should commit library changes', async () => { + const { axiosMock } = initializeMocks(); + const libraryId = 'lib:org:1'; + const url = api.getCommitLibraryChangesUrl(libraryId); + axiosMock.onPost(url).reply(200); - it('should create library block', async () => { - const libraryId = 'lib:org:1'; - const url = getCreateLibraryBlockUrl(libraryId); - axiosMock.onPost(url).reply(200); - await createLibraryBlock({ - libraryId, - blockType: 'html', - definitionId: '1', - }); + await api.commitLibraryChanges(libraryId); - expect(axiosMock.history.post[0].url).toEqual(url); - }); - - it('should commit library changes', async () => { - const libraryId = 'lib:org:1'; - const url = getCommitLibraryChangesUrl(libraryId); - axiosMock.onPost(url).reply(200); - - await commitLibraryChanges(libraryId); - - expect(axiosMock.history.post[0].url).toEqual(url); + expect(axiosMock.history.post[0].url).toEqual(url); + }); }); - it('should revert library changes', async () => { - const libraryId = 'lib:org:1'; - const url = getCommitLibraryChangesUrl(libraryId); - axiosMock.onDelete(url).reply(200); + describe('revertLibraryChanges', () => { + it('should revert library changes', async () => { + const { axiosMock } = initializeMocks(); + const libraryId = 'lib:org:1'; + const url = api.getCommitLibraryChangesUrl(libraryId); + axiosMock.onDelete(url).reply(200); - await revertLibraryChanges(libraryId); + await api.revertLibraryChanges(libraryId); - expect(axiosMock.history.delete[0].url).toEqual(url); + expect(axiosMock.history.delete[0].url).toEqual(url); + }); }); }); diff --git a/src/library-authoring/data/api.ts b/src/library-authoring/data/api.ts index e622e6addf..323f57de93 100644 --- a/src/library-authoring/data/api.ts +++ b/src/library-authoring/data/api.ts @@ -8,7 +8,7 @@ const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; */ export const getContentLibraryApiUrl = (libraryId: string) => `${getApiBaseUrl()}/api/libraries/v2/${libraryId}/`; /** - * Get the URL for get block types of library. + * Get the URL for getting block types of a library (what types can be created). */ export const getLibraryBlockTypesUrl = (libraryId: string) => `${getApiBaseUrl()}/api/libraries/v2/${libraryId}/block_types/`; /** @@ -128,13 +128,9 @@ export interface UpdateXBlockFieldsRequest { } /** - * Fetch block types of a library + * Fetch the list of XBlock types that can be added to this library */ -export async function getLibraryBlockTypes(libraryId?: string): Promise