Add test for actor type filter

This commit is contained in:
Angelina Filippova 2020-10-23 23:36:52 +03:00
parent 5dc68eed02
commit 697138d38b
2 changed files with 38 additions and 7 deletions

View file

@ -31,6 +31,10 @@ const filterUsers = (str) => {
return applyFilters([], filters, users)
}
const filterUsersByActorType = filters => {
return users.filter(user => filters.includes(user.actor_type))
}
export async function fetchUser(id, authHost, token) {
return Promise.resolve({ data: userProfile })
}
@ -39,11 +43,13 @@ export async function fetchUserCredentials(nickname, authHost, token) {
return Promise.resolve({ data: {}})
}
export async function fetchUsers(filters, 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: {
users: filteredUsers,
count: filteredUsers.length,
users: response,
count: response.length,
page_size: 50
}})
}
@ -60,12 +66,13 @@ export async function getPasswordResetToken(nickname, authHost, token) {
return Promise.resolve({ data: { token: 'g05lxnBJQnL', link: 'http://url/api/pleroma/password_reset/g05lxnBJQnL' }})
}
export async function searchUsers(query, filters, authHost, token, page = 1) {
export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) {
const filteredUsers = filterUsers(filters)
const response = filteredUsers.filter(user => user.nickname === query)
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
return Promise.resolve({ data: {
users: response,
count: response.length,
users: response.filter(user => user.nickname === query),
count: response.filter(user => user.nickname === query).length,
page_size: 50
}})
}

View file

@ -91,4 +91,28 @@ describe('Filters users', () => {
done()
})
it('applies actor types filters', async (done) => {
expect(store.state.users.totalUsersCount).toEqual(4)
store.dispatch('ToggleActorTypeFilter', ["Person"])
await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(3)
expect(store.state.users.fetchedUsers[0].nickname).toEqual('allis')
store.dispatch('ToggleActorTypeFilter', ["Service"])
await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(1)
expect(store.state.users.fetchedUsers[0].nickname).toEqual('sally')
store.dispatch('ToggleActorTypeFilter', ["Person", "Service"])
await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(4)
store.dispatch('ToggleActorTypeFilter', ["Application"])
await flushPromises()
expect(store.state.users.totalUsersCount).toEqual(0)
done()
})
})