From 232d5d840756de2e47563fe238da520da64acfa5 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Sat, 27 Jul 2019 11:51:31 +0000 Subject: [PATCH] Remove deleted users --- src/store/modules/users.js | 10 ++++------ test/views/users/index.test.js | 10 +++------- test/views/users/multipleUsersMenu.test.js | 14 ++------------ 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 94715954..e626a547 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -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 }) { diff --git a/test/views/users/index.test.js b/test/views/users/index.test.js index 7d688554..5d604226 100644 --- a/test/views/users/index.test.js +++ b/test/views/users/index.test.js @@ -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() }) diff --git a/test/views/users/multipleUsersMenu.test.js b/test/views/users/multipleUsersMenu.test.js index 74dcccf8..b4388716 100644 --- a/test/views/users/multipleUsersMenu.test.js +++ b/test/views/users/multipleUsersMenu.test.js @@ -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() })