Remove deleted users

This commit is contained in:
Angelina Filippova 2019-07-27 11:51:31 +00:00 committed by Maxim Filippov
parent 8b3a6ef4fd
commit 232d5d8407
3 changed files with 9 additions and 25 deletions

View file

@ -68,17 +68,15 @@ const users = {
await createNewAccount(nickname, email, password, getters.authHost, getters.token)
dispatch('FetchUsers', { page: state.currentPage })
},
async DeleteUser({ commit, getters }, user) {
await deleteUser(user.nickname, getters.authHost, getters.token)
const updatedUser = { ...user, deactivated: true }
commit('SWAP_USER', updatedUser)
async DeleteUser({ commit, dispatch, getters, state }, user) {
const { nickname } = await deleteUser(user.nickname, getters.authHost, getters.token)
const users = state.fetchedUsers.filter(user => user.nickname !== nickname)
commit('SET_USERS', users)
},
async FetchUsers({ commit, state, getters }, { page }) {
commit('SET_LOADING', true)
const filters = Object.keys(state.filters).filter(filter => state.filters[filter]).join()
const response = await fetchUsers(filters, getters.authHost, getters.token, page)
loadUsers(commit, page, response.data)
},
async RemoveTag({ commit, getters }, { users, tag }) {

View file

@ -129,22 +129,18 @@ describe('Users actions', () => {
done()
})
it('deactivates user when Delete action is called', async (done) => {
it('deletes user', async (done) => {
const wrapper = mount(Users, {
store,
localVue,
sync: false
})
await flushPromises()
const user = store.state.users.fetchedUsers[1]
expect(user.deactivated).toBe(false)
expect(store.state.users.fetchedUsers.length).toEqual(3)
wrapper.find(htmlElement(2, 2)).trigger('click')
await flushPromises()
const updatedUser = store.state.users.fetchedUsers[1]
expect(updatedUser.deactivated).toBe(true)
expect(store.state.users.fetchedUsers.length).toEqual(2)
done()
})

View file

@ -229,21 +229,11 @@ describe('Apply users actions to multiple users', () => {
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
const remove = wrapper.vm.mappers().remove
const user1 = store.state.users.fetchedUsers[0]
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)
expect(store.state.users.fetchedUsers.length).toEqual(3)
remove()
await flushPromises()
const updatedUser1 = store.state.users.fetchedUsers[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)
expect(store.state.users.fetchedUsers.length).toEqual(0)
done()
})