Remove functions that mock filtering users

This commit is contained in:
Angelina Filippova 2021-01-22 22:13:22 +03:00
parent df0abd99c7
commit 3ff2c3ae38

View file

@ -1,12 +1,12 @@
import userChats from './chat' import userChats from './chat'
export let users = [ export let users = [
{ active: true, is_confirmed: true, is_approved: true, is_active: true, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' }, { is_confirmed: true, is_approved: true, is_active: true, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' },
{ active: true, is_confirmed: true, is_approved: true, is_active: true, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' }, { is_confirmed: true, is_approved: true, is_active: true, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' },
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' }, { is_confirmed: true, is_approved: false, is_active: true, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' },
{ active: false, is_confirmed: true, is_approved: true, is_active: false, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' }, { is_confirmed: true, is_approved: true, is_active: false, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' },
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' }, { is_confirmed: true, is_approved: false, is_active: true, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' },
{ active: true, is_confirmed: true, is_approved: false, is_active: true, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' } { is_confirmed: true, is_approved: false, is_active: true, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' }
] ]
const userProfile = { avatar: 'avatar.jpg', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false } const userProfile = { avatar: 'avatar.jpg', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false }
@ -17,26 +17,6 @@ const userStatuses = [
{ account: { id: '9n1bySks25olxWrku0', nickname: 'dolin' }, content: 'what is yout favorite pizza?', id: '9jop82OBXeFPYulVjM', created_at: '2020-05-22T17:34:34.000Z', visibility: 'public' } { account: { id: '9n1bySks25olxWrku0', nickname: 'dolin' }, content: 'what is yout favorite pizza?', id: '9jop82OBXeFPYulVjM', created_at: '2020-05-22T17:34:34.000Z', visibility: 'public' }
] ]
const filterUsers = (str) => {
const filters = str.split(',').filter(item => item.length > 0)
if (filters.length === 0) {
return users
}
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)
}
const filterUsersByActorType = filters => {
return users.filter(user => filters.includes(user.actor_type))
}
export async function fetchUser(id, authHost, token) { export async function fetchUser(id, authHost, token) {
return Promise.resolve({ data: userProfile }) return Promise.resolve({ data: userProfile })
} }
@ -46,12 +26,9 @@ export async function fetchUserCredentials(nickname, authHost, token) {
} }
export async function fetchUsers(filters, actorTypeFilters, authHost, token, page = 1) { export async function fetchUsers(filters, actorTypeFilters, authHost, token, page = 1) {
const filteredUsers = filterUsers(filters)
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
return Promise.resolve({ data: { return Promise.resolve({ data: {
users: response, users,
count: response.length, count: users.length,
page_size: 50 page_size: 50
}}) }})
} }
@ -69,12 +46,10 @@ export async function getPasswordResetToken(nickname, authHost, token) {
} }
export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) { export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) {
const filteredUsers = filterUsers(filters) const response = users.filter(user => user.nickname === query)
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
return Promise.resolve({ data: { return Promise.resolve({ data: {
users: response.filter(user => user.nickname === query), users: response,
count: response.filter(user => user.nickname === query).length, count: response.length,
page_size: 50 page_size: 50
}}) }})
} }