forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.test.ts
More file actions
163 lines (123 loc) · 4.81 KB
/
api.test.ts
File metadata and controls
163 lines (123 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { initializeMocks } from '../../testUtils';
import * as api from './api';
let axiosMock;
describe('library data API', () => {
beforeEach(() => {
({ axiosMock } = initializeMocks());
});
describe('createLibraryBlock', () => {
it('should create library block', async () => {
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);
});
});
describe('deleteLibraryBlock', () => {
it('should delete a library block', async () => {
const usageKey = 'lib:org:1';
const url = api.getLibraryBlockMetadataUrl(usageKey);
axiosMock.onDelete(url).reply(200);
await api.deleteLibraryBlock({ usageKey });
expect(axiosMock.history.delete[0].url).toEqual(url);
});
});
describe('restoreLibraryBlock', () => {
it('should restore a soft-deleted library block', async () => {
const usageKey = 'lib:org:1';
const url = api.getLibraryBlockRestoreUrl(usageKey);
axiosMock.onPost(url).reply(200);
await api.restoreLibraryBlock({ usageKey });
expect(axiosMock.history.post[0].url).toEqual(url);
});
});
describe('commitLibraryChanges', () => {
it('should commit library changes', async () => {
const libraryId = 'lib:org:1';
const url = api.getCommitLibraryChangesUrl(libraryId);
axiosMock.onPost(url).reply(200);
await api.commitLibraryChanges(libraryId);
expect(axiosMock.history.post[0].url).toEqual(url);
});
});
describe('revertLibraryChanges', () => {
it('should revert library changes', async () => {
const libraryId = 'lib:org:1';
const url = api.getCommitLibraryChangesUrl(libraryId);
axiosMock.onDelete(url).reply(200);
await api.revertLibraryChanges(libraryId);
expect(axiosMock.history.delete[0].url).toEqual(url);
});
});
describe('getBlockTypes', () => {
it('should get block types metadata', async () => {
const libraryId = 'lib:org:1';
const url = api.getBlockTypesMetaDataUrl(libraryId);
axiosMock.onGet(url).reply(200);
await api.getBlockTypes(libraryId);
expect(axiosMock.history.get[0].url).toEqual(url);
});
});
it('should create collection', async () => {
const libraryId = 'lib:org:1';
const url = api.getLibraryCollectionsApiUrl(libraryId);
axiosMock.onPost(url).reply(200);
await api.createCollection(libraryId, {
title: 'This is a test',
description: 'This is only a test',
});
expect(axiosMock.history.post[0].url).toEqual(url);
});
it('should delete a container', async () => {
const containerId = 'lct:org:lib1';
const url = api.getLibraryContainerApiUrl(containerId);
axiosMock.onDelete(url).reply(200);
await api.deleteContainer(containerId);
expect(axiosMock.history.delete[0].url).toEqual(url);
});
it('should restore a container', async () => {
const containerId = 'lct:org:lib1';
const url = api.getLibraryContainerRestoreApiUrl(containerId);
axiosMock.onPost(url).reply(200);
await api.restoreContainer(containerId);
});
it('should add components to unit', async () => {
const componentId = 'lb:org:lib:html:1';
const containerId = 'lct:org:lib:unit:1';
const url = api.getLibraryContainerChildrenApiUrl(containerId);
axiosMock.onPost(url).reply(200);
await api.addComponentsToContainer(containerId, [componentId]);
expect(axiosMock.history.post[0].url).toEqual(url);
});
it('should update container children', async () => {
const containerId = 'lct:org:lib1';
const url = api.getLibraryContainerChildrenApiUrl(containerId);
axiosMock.onPatch(url).reply(200);
await api.updateLibraryContainerChildren(containerId, ['test']);
expect(axiosMock.history.patch[0].url).toEqual(url);
});
it('should remove container children', async () => {
const containerId = 'lct:org:lib1';
const url = api.getLibraryContainerChildrenApiUrl(containerId);
axiosMock.onDelete(url).reply(200);
await api.removeLibraryContainerChildren(containerId, ['test']);
expect(axiosMock.history.delete[0].url).toEqual(url);
});
it('getContentLibraryV2List', async () => {
const url = api.getContentLibraryV2ListApiUrl();
axiosMock.onGet(url).reply(200, { some: 'data' });
await api.getContentLibraryV2List({ type: 'complex' });
expect(axiosMock.history.get[0].url).toEqual(url);
});
it('getLibraryBlockLimits', async () => {
const url = api.getLibraryBlockLimitsUrl();
axiosMock.onGet(url).reply(200, { some: 'data' });
await api.getLibraryBlockLimits();
expect(axiosMock.history.get[0].url).toEqual(url);
});
});