import nanoid from 'nanoid' ; import { getRandomInt } from './getRandomInt' ; import { Todo } from 'features/todos/todosSlice' ; param payload param { number } timeout returns { Promise < string > } export const mockIncrement = ( payload , timeout = 1000 ) => { const randomInt = getRandomInt ( 9 ) ; return new Promise < any > ( ( resolve , reject ) => { setTimeout ( ( ) => { randomInt > 1 ? resolve ( { message : 'Mock increment API success!' , data : payload } ) : reject ( { message : 'Mock increment API error' , id : nanoid ( ) } ) ; } , timeout ) ; } ) ; } ; param { Todo } payload param { number } timeout returns { Promise < string > } export const mockAddTodo = ( payload , timeout = 1000 ) => { const randomInt = getRandomInt ( 9 ) ; return new Promise < string > ( ( resolve , reject ) => { setTimeout ( ( ) => { randomInt > 1 ? resolve ( 'Mock API successfully added todo!' ) : reject ( { message : 'Mock API failed' , id : payload . id } ) ; } , timeout ) ; } ) ; } ;