Fix filtering function in testing mocks

This commit is contained in:
Angelina Filippova 2019-03-28 21:29:24 +07:00
parent 174efc30c3
commit 9a4209cb4e

View file

@ -9,10 +9,15 @@ const filterUsers = (str) => {
if (filters.length === 0) {
return users
}
return filters.reduce((acc, filter) => {
const filteredUsers = users.filter(user => user[filter])
return [...acc, ...filteredUsers]
}, [])
const applyFilters = (acc, filters, users) => {
if (filters.length === 0) {
return acc
}
const filteredUsers = users.filter(user => user[filters[0]])
const newAcc = [...filteredUsers]
return applyFilters(newAcc, filters.slice(1), filteredUsers)
}
return applyFilters([], filters, users)
}
export async function fetchUsers(filters, authHost, token, page = 1) {