Skip to content

Commit

Permalink
test(fetchWorkingTimes.spec): Test for fetchWorkingTims by job
Browse files Browse the repository at this point in the history
  • Loading branch information
abalone0204 committed Sep 12, 2016
1 parent 97e288a commit 002578a
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/front-end/reducers/workingTimes.spec.js
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)
})

})
77 changes: 77 additions & 0 deletions tests/front-end/sagas/fetchWorkingTimes.spec.js
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)

})
})
})

0 comments on commit 002578a

Please sign in to comment.