1- import MockAdapter from 'axios-mock-adapter' ;
2- import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
3- import { initializeMockApp } from '@edx/frontend-platform' ;
1+ import { initializeMocks } from '@src/testUtils' ;
42
53import { textbooksMock } from 'CourseAuthoring/textbooks/__mocks__' ;
64import {
@@ -18,25 +16,14 @@ const courseId = 'course-v1:org+101+101';
1816
1917describe ( 'getTextbooks' , ( ) => {
2018 beforeEach ( async ( ) => {
21- initializeMockApp ( {
22- authenticatedUser : {
23- userId : 3 ,
24- username : 'abc123' ,
25- administrator : true ,
26- roles : [ ] ,
27- } ,
28- } ) ;
19+ const mocks = initializeMocks ( ) ;
2920
30- axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
21+ axiosMock = mocks . axiosMock ;
3122 axiosMock
3223 . onGet ( getTextbooksApiUrl ( courseId ) )
3324 . reply ( 200 , textbooksMock ) ;
3425 } ) ;
3526
36- afterEach ( ( ) => {
37- axiosMock . reset ( ) ;
38- } ) ;
39-
4027 it ( 'should fetch textbooks for a course' , async ( ) => {
4128 const textbooksData = [ { id : 1 , title : 'Textbook 1' } , { id : 2 , title : 'Textbook 2' } ] ;
4229 axiosMock . onGet ( getTextbooksApiUrl ( courseId ) ) . reply ( 200 , textbooksData ) ;
@@ -49,7 +36,7 @@ describe('getTextbooks', () => {
4936
5037describe ( 'createTextbook' , ( ) => {
5138 it ( 'should create a new textbook for a course' , async ( ) => {
52- const textbookData = { title : 'New Textbook' , chapters : [ ] } ;
39+ const textbookData = { tabTitle : 'New Textbook' , chapters : [ ] } ;
5340 axiosMock . onPost ( getUpdateTextbooksApiUrl ( courseId ) ) . reply ( 200 , textbookData ) ;
5441
5542 const result = await createTextbook ( courseId , textbookData ) ;
@@ -61,7 +48,7 @@ describe('createTextbook', () => {
6148describe ( 'editTextbook' , ( ) => {
6249 it ( 'should edit an existing textbook for a course' , async ( ) => {
6350 const textbookId = '1' ;
64- const editedTextbookData = { id : '1' , title : 'Edited Textbook' , chapters : [ ] } ;
51+ const editedTextbookData = { id : '1' , tabTitle : 'Edited Textbook' , chapters : [ ] } ;
6552 axiosMock . onPut ( getEditTextbooksApiUrl ( courseId , textbookId ) ) . reply ( 200 , editedTextbookData ) ;
6653
6754 const result = await editTextbook ( courseId , editedTextbookData ) ;
@@ -75,8 +62,6 @@ describe('deleteTextbook', () => {
7562 const textbookId = '1' ;
7663 axiosMock . onDelete ( getEditTextbooksApiUrl ( courseId , textbookId ) ) . reply ( 200 , { } ) ;
7764
78- const result = await deleteTextbook ( courseId , textbookId ) ;
79-
80- expect ( result ) . toEqual ( { } ) ;
65+ await expect ( deleteTextbook ( courseId , textbookId ) ) . resolves . toBeUndefined ( ) ;
8166 } ) ;
8267} ) ;
0 commit comments