forked from abalone0204/Clairvoyance
-
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.
test(fetchWorkingTimes.spec): Test for fetchWorkingTims by job
- Loading branch information
1 parent
97e288a
commit 002578a
Showing
2 changed files
with
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
assert, | ||
} from 'chai' | ||
|
||
import reducer from 'reducers/workingTimes.js' | ||
|
||
import { | ||
requestFetchWorkingTimeByJobTitle, | ||
receiveWorkingTime, | ||
failToFetchWorkingTimeByJobTitle, | ||
} from 'actions/fetchWorkingTime.js' | ||
|
||
const createInitState = () => { | ||
return { | ||
status: 'init', | ||
} | ||
} | ||
|
||
describe('Reducer/ workingTimes', () => { | ||
|
||
it('should have an init state', () => { | ||
const initState = createInitState() | ||
const expected = initState | ||
const actual = reducer(undefined, {}) | ||
assert.deepEqual(expected, actual) | ||
}) | ||
|
||
it('should handle request fetch workingtime by job', () => { | ||
const initState = createInitState() | ||
const expected = { | ||
status: 'loading' | ||
} | ||
const actual = reducer(initState, requestFetchWorkingTimeByJobTitle({ | ||
job_title: '業務', | ||
page: 0, | ||
})) | ||
assert.deepEqual(expected, actual) | ||
}) | ||
|
||
|
||
it('should handle response of fetching workingtime by job', () => { | ||
const initState = createInitState() | ||
const response = { | ||
"total_count": 1, | ||
"total_page": 1, | ||
"page": "0", | ||
"workings": [{ | ||
"company": { | ||
"name": "業務人資訊" | ||
}, | ||
"created_at": "2016-07-19T12:47:01.065Z", | ||
"job_title": "網頁工程師", | ||
"week_work_time": 45 | ||
}] | ||
} | ||
const expected = Object.assign({}, { | ||
status: 'completed', | ||
}, response) | ||
|
||
const actual = reducer(initState, receiveWorkingTime(response)) | ||
assert.deepEqual(expected, actual) | ||
}) | ||
|
||
|
||
it('should handle fail to fetch workingtime by job', () => { | ||
const initState = createInitState() | ||
const error = { | ||
message: 'mock error', | ||
} | ||
const expected = { | ||
status: 'error', | ||
error, | ||
} | ||
const actual = reducer(initState, failToFetchWorkingTimeByJobTitle(error)) | ||
assert.deepEqual(expected, actual) | ||
}) | ||
|
||
}) |
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,77 @@ | ||
import 'babel-polyfill' | ||
import { | ||
assert | ||
} from 'chai' | ||
import { | ||
takeEvery | ||
} from 'redux-saga' | ||
|
||
import { | ||
put, | ||
call, | ||
} from 'redux-saga/effects' | ||
|
||
import { | ||
fetchWorkingTimeFlow, | ||
watchRequestFetchWorkingTimes, | ||
} from 'sagas/fetchWorkingTimes' | ||
|
||
import goodjobAPI from 'API/goodjob' | ||
|
||
import { | ||
REQUEST_FETCH_WORKING_TIME_BY_JOB_TITLE, | ||
requestFetchWorkingTimeByJobTitle, | ||
receiveWorkingTime, | ||
failToFetchWorkingTimeByJobTitle, | ||
} from 'actions/fetchWorkingTime.js' | ||
|
||
const { | ||
searchByJob, | ||
} = goodjobAPI | ||
|
||
|
||
describe('Saga/ fetchWorkingTimes', () => { | ||
|
||
describe('watchRequestFetchWorkingTimes', () => { | ||
const iterator = watchRequestFetchWorkingTimes() | ||
it('should take every requestFetchWorkingTimes\' request', () => { | ||
const expected = call(takeEvery, REQUEST_FETCH_WORKING_TIME_BY_JOB_TITLE, fetchWorkingTimeFlow) | ||
const actual = iterator.next().value | ||
assert.deepEqual(expected, actual) | ||
}) | ||
}) | ||
|
||
describe('fetchWorkingTimesFlow', () => { | ||
const mockAction = requestFetchWorkingTimeByJobTitle({ | ||
job_title: 'mock engineer', | ||
page: 0, | ||
}) | ||
const iterator = fetchWorkingTimeFlow(mockAction) | ||
it('should call searchByJob API', () => { | ||
const expected = call(searchByJob, { | ||
job_title: 'mock engineer', | ||
page: 0, | ||
}) | ||
const actual = iterator.next().value | ||
assert.deepEqual(expected, actual) | ||
|
||
}) | ||
|
||
it('should receive response from fetchWorkingTimes API', () => { | ||
const response = { | ||
body: 'mock', | ||
} | ||
const expected = put(receiveWorkingTime(response)) | ||
const actual = iterator.next(response).value | ||
assert.deepEqual(expected, actual) | ||
}) | ||
|
||
it('should handle error', () => { | ||
const error = new Error('mock') | ||
const expected = put(failToFetchWorkingTimeByJobTitle(error)) | ||
const actual = iterator.throw(error).value | ||
assert.deepEqual(expected, actual) | ||
|
||
}) | ||
}) | ||
}) |