-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtaskEffects.test.js
More file actions
48 lines (45 loc) · 1.8 KB
/
taskEffects.test.js
File metadata and controls
48 lines (45 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import '@testing-library/jest-dom/extend-expect'
import taskDispatch, {taskEvent} from './taskDispatch';
import taskEffects from './taskEffects';
import createSample from '../test-util/sample';
import createEnvironment from '../environment/environment';
import createFetchFake from '../test-util/fetch-fake';
import {createMemoryHistory} from 'history';
describe('task effects', () => {
test('fetch tasks', async () => {
// given
const sample = createSample()
const profile = sample.profile()
const task1 = sample.task({profile: profile.id})
const task2 = sample.task()
const task3 = sample.task({profile: profile.id})
const tasks = [task1, task2, task3]
const tasksInProfile = [task1, task3]
const httpGetProfile = {
uri: `/proxy/profile/${profile.id}`,
responseText: JSON.stringify(profile)
}
const httpGetTasks = {
uri: `/proxy/task`,
responseText: JSON.stringify(tasks)
}
const fetchSpecs = [httpGetProfile, httpGetTasks]
const fetch = createFetchFake(fetchSpecs)
const uri = `/task/${profile.id}`
const history = createMemoryHistory()
history.push(uri)
history.go(0)
const environment = createEnvironment({fetch, history})
const generator = taskEffects[taskEvent.FETCH_TASKS_REQUEST](environment)
// when
const iterator = generator()
// then
expect(await iterator.next().value).toEqual(profile)
expect(await iterator.next(profile).value).toEqual(tasks)
expect(iterator.next(tasks).value.payload.action).toEqual(taskDispatch.fetchTasksSuccess({
profile,
tasks: tasksInProfile
}))
expect(iterator.next().done).toBeTruthy()
})
})