Fix toggling verification state

This commit is contained in:
Pig Fang 2018-08-23 11:13:54 +08:00
parent 932f9e9bb2
commit af9cf005ff
2 changed files with 12 additions and 4 deletions

View File

@ -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({

View File

@ -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');
});