|
1
|
|
|
/* global jest, jasmine, describe, it, expect, beforeEach */ |
|
2
|
|
|
|
|
3
|
|
|
import * as actions from '../CampaignActions'; |
|
4
|
|
|
import ACTION_TYPES from '../CampaignActionTypes'; |
|
5
|
|
|
import configureMockStore from 'redux-mock-store'; |
|
6
|
|
|
import thunk from 'redux-thunk'; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
describe('CampaignActions', () => { |
|
10
|
|
|
const middlewares = [thunk]; |
|
11
|
|
|
const mockStore = configureMockStore(middlewares); |
|
12
|
|
|
|
|
13
|
|
|
describe('removeCampaignItems()', () => { |
|
14
|
|
|
it('should create 2 actions, request and success, when resolved', () => { |
|
15
|
|
|
const store = mockStore({}); |
|
16
|
|
|
const removeItemApi = () => Promise.resolve(); |
|
17
|
|
|
const expectedActions = [ |
|
18
|
|
|
{ |
|
19
|
|
|
type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST, |
|
20
|
|
|
payload: { campaignId: 1, itemId: 2 }, |
|
21
|
|
|
}, |
|
22
|
|
|
{ |
|
23
|
|
|
type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_SUCCESS, |
|
24
|
|
|
payload: { campaignId: 1, itemId: 2 }, |
|
25
|
|
|
}, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
return store.dispatch( |
|
29
|
|
|
actions.removeCampaignItem(removeItemApi, 1, 2) |
|
30
|
|
|
).then(() => { |
|
31
|
|
|
// return of async actions |
|
32
|
|
|
expect(store.getActions()).toEqual(expectedActions); |
|
33
|
|
|
}); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
it('should create 2 actions, request and failure, when rejected', () => { |
|
37
|
|
|
const store = mockStore({}); |
|
38
|
|
|
const removeItemApi = () => new Promise((resolve, reject) => { |
|
39
|
|
|
reject(null); |
|
40
|
|
|
}); |
|
41
|
|
|
const expectedActions = [ |
|
42
|
|
|
{ |
|
43
|
|
|
type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST, |
|
44
|
|
|
payload: { campaignId: 1, itemId: 2 }, |
|
45
|
|
|
}, |
|
46
|
|
|
{ |
|
47
|
|
|
type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_FAILURE, |
|
48
|
|
|
payload: { error: null }, |
|
49
|
|
|
}, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
return store.dispatch( |
|
53
|
|
|
actions.removeCampaignItem(removeItemApi, 1, 2) |
|
54
|
|
|
).then(() => { |
|
55
|
|
|
// return of async actions |
|
56
|
|
|
expect(store.getActions()).toEqual(expectedActions); |
|
57
|
|
|
}); |
|
58
|
|
|
}); |
|
59
|
|
|
}); |
|
60
|
|
|
}); |
|
61
|
|
|
|