Commit a7395c71 authored by Alexander Turinske's avatar Alexander Turinske

Update promises to async/await

- change alert status mutation to use async await
- clean up tests
parent d3e4fa9f
......@@ -40,34 +40,31 @@ export default {
handleError() {
this.$emit('alert-error', this.$options.i18n.updateError);
},
updateAlertStatus(status) {
async updateAlertStatus(status) {
this.isUpdating = true;
this.status = status;
this.$apollo
.mutate({
try {
const { data } = await this.$apollo.mutate({
mutation: updateAlertStatusMutation,
variables: {
iid: this.alert.iid,
status: status.toUpperCase(),
projectPath: this.projectPath,
},
})
.then(resp => {
const errors = resp.data?.updateAlertStatus?.errors || [];
if (errors[0]) {
this.handleError();
}
});
this.$emit('alert-update');
})
.catch(() => {
this.status = this.alert.status;
const errors = data?.updateAlertStatus?.errors || [];
if (errors[0]) {
this.handleError();
})
.finally(() => {
this.isUpdating = false;
});
}
this.$emit('alert-update');
} catch {
this.status = this.alert.status;
this.handleError();
} finally {
this.isUpdating = false;
}
},
},
};
......
......@@ -77,7 +77,7 @@ describe('AlertStatus', () => {
it('emits to the list to refetch alerts on a successful alert status change', async () => {
expect(wrapper.emitted('alert-update')).toBeUndefined();
await selectFirstStatusOption();
expect(wrapper.emitted('alert-update').length).toBe(1);
expect(wrapper.emitted('alert-update')).toHaveLength(1);
});
});
......@@ -98,7 +98,7 @@ describe('AlertStatus', () => {
await selectFirstStatusOption();
await wrapper.vm.$nextTick();
await selectFirstStatusOption();
expect(wrapper.emitted('alert-error').length > 1).toBe(true);
expect(wrapper.emitted('alert-error').length).toBeGreaterThan(1);
});
it('reverts the status of an alert on failure', async () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment