|
| 1 | +import ShowsAction from './ShowsAction'; |
| 2 | +import ActionUtility from '../../utilities/ActionUtility'; |
| 3 | +import { mockStoreFixture } from '../../__fixtures__/reduxFixtures'; |
| 4 | +import ShowModel from './models/shows/ShowModel'; |
| 5 | +import ShowsEffect from './ShowsEffect'; |
| 6 | +import EpisodeModel from './models/episodes/EpisodeModel'; |
| 7 | +import CastModel from './models/cast/CastModel'; |
| 8 | + |
| 9 | +describe('ShowsAction', () => { |
| 10 | + let store; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + store = mockStoreFixture({ |
| 14 | + shows: { |
| 15 | + currentShowId: '74', |
| 16 | + }, |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + afterEach(() => { |
| 21 | + jest.clearAllMocks(); |
| 22 | + jest.restoreAllMocks(); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('requestShow', () => { |
| 26 | + it('has a successful response', async () => { |
| 27 | + const expectedResponse = new ShowModel({}); |
| 28 | + |
| 29 | + jest.spyOn(ShowsEffect, 'requestShow').mockImplementation(async () => expectedResponse); |
| 30 | + |
| 31 | + await store.dispatch(ShowsAction.requestShow()); |
| 32 | + |
| 33 | + const actualResult = store.getActions(); |
| 34 | + const expectedResult = [ |
| 35 | + ActionUtility.createAction(ShowsAction.REQUEST_SHOW), |
| 36 | + ActionUtility.createAction(ShowsAction.REQUEST_SHOW_FINISHED, expectedResponse), |
| 37 | + ]; |
| 38 | + |
| 39 | + expect(actualResult).toEqual(expectedResult); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('requestEpisodes', () => { |
| 44 | + it('has a successful response', async () => { |
| 45 | + const expectedResponse = [new EpisodeModel({})]; |
| 46 | + |
| 47 | + jest.spyOn(ShowsEffect, 'requestEpisodes').mockImplementation(async () => expectedResponse); |
| 48 | + |
| 49 | + await store.dispatch(ShowsAction.requestEpisodes()); |
| 50 | + |
| 51 | + const actualResult = store.getActions(); |
| 52 | + const expectedResult = [ |
| 53 | + ActionUtility.createAction(ShowsAction.REQUEST_EPISODES), |
| 54 | + ActionUtility.createAction(ShowsAction.REQUEST_EPISODES_FINISHED, expectedResponse), |
| 55 | + ]; |
| 56 | + |
| 57 | + expect(actualResult).toEqual(expectedResult); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('requestCast', () => { |
| 62 | + it('has a successful response', async () => { |
| 63 | + const expectedResponse = [new CastModel({})]; |
| 64 | + |
| 65 | + jest.spyOn(ShowsEffect, 'requestCast').mockImplementation(async () => expectedResponse); |
| 66 | + |
| 67 | + await store.dispatch(ShowsAction.requestCast()); |
| 68 | + |
| 69 | + const actualResult = store.getActions(); |
| 70 | + const expectedResult = [ |
| 71 | + ActionUtility.createAction(ShowsAction.REQUEST_CAST), |
| 72 | + ActionUtility.createAction(ShowsAction.REQUEST_CAST_FINISHED, expectedResponse), |
| 73 | + ]; |
| 74 | + |
| 75 | + expect(actualResult).toEqual(expectedResult); |
| 76 | + }); |
| 77 | + }); |
| 78 | +}); |
0 commit comments