forked from USStateDept/State-TalentMAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #610 from MetaPhase-Consulting/tests/mock-request-…
…testing-2 Check that mocks were called
- Loading branch information
Showing
9 changed files
with
243 additions
and
339 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
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 |
---|---|---|
@@ -1,71 +1,57 @@ | ||
import { setupAsyncMocks } from '../testUtilities/testUtilities'; | ||
import { setupAsyncMocks, spyMockAdapter, expectMockWasCalled } from '../testUtilities/testUtilities'; | ||
import * as actions from './aboutContent'; | ||
|
||
const { mockStore, mockAdapter } = setupAsyncMocks(); | ||
const { mockStore } = setupAsyncMocks(); | ||
|
||
describe('async actions', () => { | ||
beforeEach(() => { | ||
mockAdapter.onGet('http://localhost:8000/api/v1/aboutpage/').reply(200, | ||
{ text: 'text', is_visible: true }, | ||
); | ||
mockAdapter.onPatch('http://localhost:8000/api/v1/aboutpage/').reply(200, | ||
null, | ||
); | ||
}); | ||
let mock; | ||
let spy; | ||
|
||
it('fetches the about content', (done) => { | ||
const store = mockStore({}); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.aboutContentFetchData()); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: 'http://localhost:8000/api/v1/aboutpage/', response: [200, { text: 'text', is_visible: true }], | ||
})); mock(); | ||
|
||
store.dispatch(actions.aboutContentFetchData()); | ||
|
||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
|
||
it('handles errors when fetching the about content', (done) => { | ||
const store = mockStore({}); | ||
|
||
mockAdapter.onGet('http://localhost:8000/api/v1/aboutpage/').reply(404, | ||
null, | ||
); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.aboutContentFetchData()); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: 'http://localhost:8000/api/v1/aboutpage/', response: [404, null], | ||
})); mock(); | ||
|
||
store.dispatch(actions.aboutContentFetchData()); | ||
|
||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
|
||
it('patches the home banner content', (done) => { | ||
const store = mockStore({}); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.aboutContentPatchData({ content: 'text' })); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: 'http://localhost:8000/api/v1/aboutpage/', response: [200, null], type: 'onPatch', | ||
})); mock(); | ||
|
||
store.dispatch(actions.aboutContentPatchData({ content: 'text' })); | ||
|
||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
|
||
it('handles errors when patching the home banner content', (done) => { | ||
const store = mockStore({}); | ||
|
||
mockAdapter.onPatch('http://localhost:8000/api/v1/aboutpage/').reply(404, | ||
null, | ||
); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.aboutContentPatchData({ content: 'text' })); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: 'http://localhost:8000/api/v1/aboutpage/', response: [404, null], type: 'onPatch', | ||
})); mock(); | ||
|
||
store.dispatch(actions.aboutContentPatchData({ content: 'text' })); | ||
|
||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,62 +1,43 @@ | ||
import { setupAsyncMocks } from '../testUtilities/testUtilities'; | ||
import { setupAsyncMocks, spyMockAdapter, expectMockWasCalled } from '../testUtilities/testUtilities'; | ||
import * as actions from './assignment'; | ||
import assignmentObject from '../__mocks__/assignmentObject'; | ||
|
||
const { mockStore, mockAdapter } = setupAsyncMocks(); | ||
const { mockStore } = setupAsyncMocks(); | ||
|
||
describe('async actions', () => { | ||
let [mock, spy, store] = Array(3); | ||
|
||
beforeEach(() => { | ||
mockAdapter.onGet('http://localhost:8000/api/v1/profile/assignments/?status=active').reply(200, | ||
{ results: [assignmentObject] }, | ||
); | ||
store = mockStore({ assignment: {} }); | ||
|
||
mockAdapter.onGet('http://localhost:8000/api/v1/profile/assignments/?status=closed').reply(200, | ||
{ results: [assignmentObject] }, | ||
); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: '/profile/assignments/?status=active', response: [200, { results: [assignmentObject] }], | ||
})); mock(); | ||
}); | ||
|
||
it('can fetch assignments', (done) => { | ||
const store = mockStore({ assignment: {} }); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.assignmentFetchData()); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
store.dispatch(actions.assignmentFetchData()); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
|
||
it('can fetch assignments where status = closed', (done) => { | ||
const store = mockStore({ assignment: {} }); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.assignmentFetchData('closed')); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: '/profile/assignments/?status=closed', response: [200, { results: [assignmentObject] }], | ||
})); mock(); | ||
|
||
store.dispatch(actions.assignmentFetchData('closed')); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
|
||
it('can handle errors when fetching assignments', (done) => { | ||
const store = mockStore({ assignment: {} }); | ||
|
||
mockAdapter.reset(); | ||
|
||
mockAdapter.onGet('http://localhost:8000/api/v1/profile/assignments/?status=active').reply(404, | ||
null, | ||
); | ||
|
||
const f = () => { | ||
setTimeout(() => { | ||
store.dispatch(actions.assignmentFetchData()); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
done(); | ||
}, 0); | ||
}; | ||
f(); | ||
({ mock, spy } = spyMockAdapter({ | ||
url: '/profile/assignments/?status=active', response: [404], | ||
})); mock(); | ||
|
||
store.dispatch(actions.assignmentFetchData()); | ||
store.dispatch(actions.assignmentIsLoading()); | ||
expectMockWasCalled({ spy, cb: done }); | ||
}); | ||
}); |
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
Oops, something went wrong.