-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Chen
authored and
Simon Chen
committed
Dec 5, 2018
1 parent
db25a18
commit adfefac
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import apiClient from '../apiClient'; | ||
import { fetchCohorts } from './cohorts'; | ||
import { | ||
STARTED_FETCHING_COHORTS, | ||
GOT_COHORTS, | ||
ERROR_FETCHING_COHORTS, | ||
} from '../constants/actionTypes/cohorts'; | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
const axiosMock = new MockAdapter(apiClient); | ||
|
||
describe('actions', () => { | ||
afterEach(() => { | ||
axiosMock.reset(); | ||
}); | ||
|
||
describe('fetchCohorts', () => { | ||
const courseId = 'course-v1:edX+DemoX+Demo_Course'; | ||
|
||
it('dispatches success action after fetching cohorts', () => { | ||
const responseData = { | ||
cohorts: [ | ||
{ | ||
assignment_type: 'manual', | ||
group_id: null, | ||
id: 1, | ||
name: 'default_group', | ||
user_count: 2, | ||
user_partition_id: null, | ||
}, | ||
{ | ||
assignment_type: 'auto', | ||
group_id: null, | ||
id: 2, | ||
name: 'auto_group', | ||
user_count: 5, | ||
user_partition_id: null, | ||
}], | ||
}; | ||
const expectedActions = [ | ||
{ type: STARTED_FETCHING_COHORTS }, | ||
{ type: GOT_COHORTS, cohorts: responseData.cohorts }, | ||
]; | ||
const store = mockStore(); | ||
|
||
axiosMock.onGet(`http://localhost:18000/courses/${courseId}/cohorts/`) | ||
.replyOnce(200, JSON.stringify(responseData)); | ||
|
||
return store.dispatch(fetchCohorts(courseId)).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
it('dispatches failure action after fetching cohorts', () => { | ||
const expectedActions = [ | ||
{ type: STARTED_FETCHING_COHORTS }, | ||
{ type: ERROR_FETCHING_COHORTS }, | ||
]; | ||
const store = mockStore(); | ||
|
||
axiosMock.onGet(`http://localhost:18000/courses/${courseId}/cohorts/`) | ||
.replyOnce(500, JSON.stringify({})); | ||
|
||
return store.dispatch(fetchCohorts(courseId)).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters