import { path } from "ramda" ; import { call , put } from "redux-saga/effects" ; import { GithubActions } from "../../Reducers/GithubReducers" ; import FixtureAPI from "../../Services/FixtureApi" ; import { getUserAvatar } from "./index" ; const stepper = ( fn ) => ( mock ? ) => fn . next ( mock ) . value ; test ( "first calls API" , ( ) => { const step = stepper ( getUserAvatar ( FixtureAPI , GithubActions . userRequest ( { username : "ascorbic" } ) ) ) ; expect ( step ( ) ) . toEqual ( call ( FixtureAPI . getUser , "ascorbic" ) ) ; } ) ; test ( "success path" , ( ) => { FixtureAPI . getUser ( "ascorbic" ) . then ( ( response ) => { const step = stepper ( getUserAvatar ( FixtureAPI , GithubActions . userRequest ( { username : "ascorbic" } ) ) ) ; step ( ) ; const stepResponse = step ( response ) ; const firstUser = path ( [ "data" , "items" ] , response ) [ 0 ] ; const avatar = firstUser . avatar_url ; expect ( stepResponse ) . toEqual ( put ( GithubActions . userSuccess ( avatar ) ) ) ; } ) ; } ) ; test ( "failure path" , ( ) => { const response = { ok : false } ; const step = stepper ( getUserAvatar ( FixtureAPI , GithubActions . userRequest ( { username : "ascorbic" } ) ) ) ; step ( ) ; expect ( step ( response ) ) . toEqual ( put ( GithubActions . userFailure ( ) ) ) ; } ) ;