forked from AkkomaGang/admin-fe
Merge branch 'fix/delete-user' into 'master'
Remove deleted users See merge request pleroma/admin-fe!26
This commit is contained in:
commit
af610f4669
3 changed files with 9 additions and 25 deletions
|
@ -68,17 +68,15 @@ const users = {
|
||||||
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
|
||||||
dispatch('FetchUsers', { page: state.currentPage })
|
dispatch('FetchUsers', { page: state.currentPage })
|
||||||
},
|
},
|
||||||
async DeleteUser({ commit, getters }, user) {
|
async DeleteUser({ commit, dispatch, getters, state }, user) {
|
||||||
await deleteUser(user.nickname, getters.authHost, getters.token)
|
const { nickname } = await deleteUser(user.nickname, getters.authHost, getters.token)
|
||||||
const updatedUser = { ...user, deactivated: true }
|
const users = state.fetchedUsers.filter(user => user.nickname !== nickname)
|
||||||
commit('SWAP_USER', updatedUser)
|
commit('SET_USERS', users)
|
||||||
},
|
},
|
||||||
async FetchUsers({ commit, state, getters }, { page }) {
|
async FetchUsers({ commit, state, getters }, { page }) {
|
||||||
commit('SET_LOADING', true)
|
commit('SET_LOADING', true)
|
||||||
|
|
||||||
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
|
||||||
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
|
||||||
|
|
||||||
loadUsers(commit, page, response.data)
|
loadUsers(commit, page, response.data)
|
||||||
},
|
},
|
||||||
async RemoveTag({ commit, getters }, { users, tag }) {
|
async RemoveTag({ commit, getters }, { users, tag }) {
|
||||||
|
|
|
@ -129,22 +129,18 @@ describe('Users actions', () => {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('deactivates user when Delete action is called', async (done) => {
|
it('deletes user', async (done) => {
|
||||||
const wrapper = mount(Users, {
|
const wrapper = mount(Users, {
|
||||||
store,
|
store,
|
||||||
localVue,
|
localVue,
|
||||||
sync: false
|
sync: false
|
||||||
})
|
})
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
expect(store.state.users.fetchedUsers.length).toEqual(3)
|
||||||
const user = store.state.users.fetchedUsers[1]
|
|
||||||
expect(user.deactivated).toBe(false)
|
|
||||||
|
|
||||||
wrapper.find(htmlElement(2, 2)).trigger('click')
|
wrapper.find(htmlElement(2, 2)).trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
expect(store.state.users.fetchedUsers.length).toEqual(2)
|
||||||
const updatedUser = store.state.users.fetchedUsers[1]
|
|
||||||
expect(updatedUser.deactivated).toBe(true)
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -229,21 +229,11 @@ describe('Apply users actions to multiple users', () => {
|
||||||
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
|
||||||
|
|
||||||
const remove = wrapper.vm.mappers().remove
|
const remove = wrapper.vm.mappers().remove
|
||||||
const user1 = store.state.users.fetchedUsers[0]
|
expect(store.state.users.fetchedUsers.length).toEqual(3)
|
||||||
const user2 = store.state.users.fetchedUsers[1]
|
|
||||||
const user3 = store.state.users.fetchedUsers[2]
|
|
||||||
expect(user1.deactivated).toBe(false)
|
|
||||||
expect(user2.deactivated).toBe(false)
|
|
||||||
expect(user3.deactivated).toBe(true)
|
|
||||||
remove()
|
remove()
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
const updatedUser1 = store.state.users.fetchedUsers[0]
|
expect(store.state.users.fetchedUsers.length).toEqual(0)
|
||||||
const updatedUser2 = store.state.users.fetchedUsers[1]
|
|
||||||
const updatedUser3 = store.state.users.fetchedUsers[2]
|
|
||||||
expect(updatedUser1.deactivated).toBe(true)
|
|
||||||
expect(updatedUser2.deactivated).toBe(true)
|
|
||||||
expect(updatedUser3.deactivated).toBe(true)
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue