-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathapi.test.ts
More file actions
67 lines (52 loc) · 1.99 KB
/
api.test.ts
File metadata and controls
67 lines (52 loc) · 1.99 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
import { initializeMocks } from '@src/testUtils';
import { textbooksMock } from 'CourseAuthoring/textbooks/__mocks__';
import {
getTextbooks,
createTextbook,
editTextbook,
deleteTextbook,
getTextbooksApiUrl,
getUpdateTextbooksApiUrl,
getEditTextbooksApiUrl,
} from './api';
let axiosMock;
const courseId = 'course-v1:org+101+101';
describe('getTextbooks', () => {
beforeEach(async () => {
const mocks = initializeMocks();
axiosMock = mocks.axiosMock;
axiosMock
.onGet(getTextbooksApiUrl(courseId))
.reply(200, textbooksMock);
});
it('should fetch textbooks for a course', async () => {
const textbooksData = [{ id: 1, title: 'Textbook 1' }, { id: 2, title: 'Textbook 2' }];
axiosMock.onGet(getTextbooksApiUrl(courseId)).reply(200, textbooksData);
const result = await getTextbooks(courseId);
expect(result).toEqual(textbooksData);
});
});
describe('createTextbook', () => {
it('should create a new textbook for a course', async () => {
const textbookData = { tabTitle: 'New Textbook', chapters: [] };
axiosMock.onPost(getUpdateTextbooksApiUrl(courseId)).reply(200, textbookData);
const result = await createTextbook(courseId, textbookData);
expect(result).toEqual(textbookData);
});
});
describe('editTextbook', () => {
it('should edit an existing textbook for a course', async () => {
const textbookId = '1';
const editedTextbookData = { id: '1', tabTitle: 'Edited Textbook', chapters: [] };
axiosMock.onPut(getEditTextbooksApiUrl(courseId, textbookId)).reply(200, editedTextbookData);
const result = await editTextbook(courseId, editedTextbookData);
expect(result).toEqual(editedTextbookData);
});
});
describe('deleteTextbook', () => {
it('should delete an existing textbook for a course', async () => {
const textbookId = '1';
axiosMock.onDelete(getEditTextbooksApiUrl(courseId, textbookId)).reply(200, {});
await expect(deleteTextbook(courseId, textbookId)).resolves.toBeUndefined();
});
});