11import React from 'react' ;
2- import { logError } from '@edx/frontend-platform/logging' ;
32import { AppContext } from '@edx/frontend-platform/react' ;
43import { keyStore } from 'utils' ;
54import { RequestKeys } from 'data/constants/requests' ;
@@ -11,24 +10,17 @@ import * as apiHooks from './api';
1110
1211const reduxKeys = keyStore ( reduxHooks ) ;
1312
14- jest . mock ( '@edx/frontend-platform/logging' , ( ) => ( {
15- logError : jest . fn ( ) ,
16- } ) ) ;
17-
1813jest . mock ( 'data/services/lms/utils' , ( ) => ( {
1914 post : jest . fn ( ( ...args ) => ( { post : args } ) ) ,
2015} ) ) ;
21-
2216jest . mock ( 'data/services/lms/api' , ( ) => ( {
2317 initializeList : jest . fn ( ) ,
2418 updateEntitlementEnrollment : jest . fn ( ) ,
2519 unenrollFromCourse : jest . fn ( ) ,
2620 deleteEntitlementEnrollment : jest . fn ( ) ,
2721 updateEmailSettings : jest . fn ( ) ,
2822 createCreditRequest : jest . fn ( ) ,
29- getProgramsConfig : jest . fn ( ) ,
3023} ) ) ;
31-
3224jest . mock ( 'data/redux/hooks' , ( ) => ( {
3325 useCardCourseRunData : jest . fn ( ) ,
3426 useCardCreditData : jest . fn ( ) ,
@@ -118,34 +110,6 @@ describe('api hooks', () => {
118110 } ) ;
119111 } ) ;
120112
121- describe ( 'useProgramsConfig' , ( ) => {
122- let mockState ;
123- const setState = jest . fn ( ( newState ) => { Object . assign ( mockState , newState ) ; } ) ;
124- beforeEach ( ( ) => {
125- mockState = { } ;
126- React . useState . mockReturnValue ( [ mockState , setState ] ) ;
127- } ) ;
128-
129- it ( 'should return the programs configuration when the API call is successful' , async ( ) => {
130- api . getProgramsConfig . mockResolvedValue ( { data : { enabled : true } } ) ;
131- const config = apiHooks . useProgramsConfig ( ) ;
132- const [ cb ] = React . useEffect . mock . calls [ 0 ] ;
133- await cb ( ) ;
134- expect ( setState ) . toHaveBeenCalled ( ) ;
135- expect ( config ) . toEqual ( { enabled : true } ) ;
136- } ) ;
137-
138- it ( 'should return an empty object if the api call fails' , async ( ) => {
139- mockState = { } ;
140- api . getProgramsConfig . mockRejectedValue ( new Error ( 'error test' ) ) ;
141- const config = apiHooks . useProgramsConfig ( ) ;
142- const [ cb ] = React . useEffect . mock . calls [ 0 ] ;
143- await cb ( ) ;
144- expect ( config ) . toEqual ( { } ) ;
145- expect ( logError ) . toHaveBeenCalled ( ) ;
146- } ) ;
147- } ) ;
148-
149113 describe ( 'entitlement enrollment hooks' , ( ) => {
150114 beforeEach ( ( ) => {
151115 jest . spyOn ( apiHooks , moduleKeys . useInitializeApp ) . mockReturnValue ( initializeApp ) ;
0 commit comments