/* ***********************************************************
* Wiring Instructions
* To make this test work, you'll need to:
*  - Add a Fixture named get<%= name %> to the
*    ./App/Services/FixtureApi file. You can just keep adding
*    functions to that file.
*************************************************************/

import FixtureAPI from '../../App/Services/FixtureApi'
import { call, put } from 'redux-saga/effects'
import { get<%= name %> } from '../../App/Sagas/<%= name %>Sagas'
import <%= name %>Actions from '../../App/Redux/<%= name %>Redux'

const stepper = (fn) => (mock) => fn.next(mock).value

it('first calls API', () => {
  const step = stepper(get<%= name %>(FixtureAPI, {data: 'taco'}))
  // first yield is the API
  expect(step()).toEqual(call(FixtureAPI.get<%= name %>, 'taco'))
})

it('success path', () => {
  const response = FixtureAPI.get<%= name %>('taco')
  const step = stepper(get<%= name %>(FixtureAPI, {data: 'taco'}))
  // Step 1: Hit the api
  step()
  // Step 2: Successful return and data!
  expect(step(response)).toEqual(put(<%= name.charAt(0).toUpperCase() + name.slice(1) %>Actions.<%= name.toLowerCase() %>Success(21)))
})

it('failure path', () => {
  const response = {ok: false}
  const step = stepper(get<%= name %>(FixtureAPI, {data: 'taco'}))
  // Step 1: Hit the api
  step()
  // Step 2: Failed response.
  expect(step(response)).toEqual(put(<%= name.charAt(0).toUpperCase() + name.slice(1) %>Actions.<%= name.toLowerCase() %>Failure()))
})
