From af9cf005ffd73c59601494b7be95319223c78670 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 23 Aug 2018 11:13:54 +0800 Subject: [PATCH] Fix toggling verification state --- resources/assets/src/components/admin/Users.vue | 10 +++++++--- resources/assets/tests/components/admin/Users.test.js | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/resources/assets/src/components/admin/Users.vue b/resources/assets/src/components/admin/Users.vue index fbd46db4..2071f6a5 100644 --- a/resources/assets/src/components/admin/Users.vue +++ b/resources/assets/src/components/admin/Users.vue @@ -195,12 +195,16 @@ export default { } }, async toggleVerification(user) { - const { msg } = await this.$http.post( + const { errno, msg } = await this.$http.post( '/admin/users?action=verification', { uid: user.uid } ); - user.verified = !user.verified; - toastr.success(msg); + if (errno === 0) { + user.verified = !user.verified; + toastr.success(msg); + } else { + toastr.warning(msg); + } }, async changeNickName(user) { const { dismiss, value } = await swal({ diff --git a/resources/assets/tests/components/admin/Users.test.js b/resources/assets/tests/components/admin/Users.test.js index 96892db7..7308ade1 100644 --- a/resources/assets/tests/components/admin/Users.test.js +++ b/resources/assets/tests/components/admin/Users.test.js @@ -330,7 +330,9 @@ test('toggle verification', async () => { Vue.prototype.$http.get.mockResolvedValue({ data: [ { uid: 1, verified: false }, ] }); - Vue.prototype.$http.post.mockResolvedValue({ errno: 0, msg: '0' }); + Vue.prototype.$http.post + .mockResolvedValueOnce({ errno: 1, msg: '1' }) + .mockResolvedValueOnce({ errno: 0, msg: '0' }); const wrapper = mount(Users); await wrapper.vm.$nextTick(); @@ -342,6 +344,8 @@ test('toggle verification', async () => { '/admin/users?action=verification', { uid: 1 } ); + + button.trigger('click'); await flushPromises(); expect(wrapper.text()).toContain('admin.verified'); });