Commit 57975803 authored by Andrew Fontaine's avatar Andrew Fontaine

Find errors correctly when deleting an environment

The error message was not fetched appropriately when trying to see if
there were any errors upon deleting an environment.

This corrects that, as apollo shoves the errors into the following
shape:

{
  data: {
    deleteEnvironment: {
      errors: [messages]
    }
  }
}

This is now also tested for.
parent fdaff68a
......@@ -62,7 +62,8 @@ export default {
mutation: deleteEnvironmentMutation,
variables: { environment: this.environment },
})
.then(([message]) => {
.then(({ data }) => {
const [message] = data?.deleteEvironment?.errors ?? [];
if (message) {
createFlash({ message });
}
......
......@@ -5,8 +5,11 @@ import VueApollo from 'vue-apollo';
import { s__, sprintf } from '~/locale';
import DeleteEnvironmentModal from '~/environments/components/delete_environment_modal.vue';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash';
import { resolvedEnvironment } from './graphql/mock_data';
jest.mock('~/flash');
Vue.use(VueApollo);
describe('~/environments/components/delete_environment_modal.vue', () => {
......@@ -54,6 +57,34 @@ describe('~/environments/components/delete_environment_modal.vue', () => {
await nextTick();
expect(createFlash).not.toHaveBeenCalled();
expect(deleteResolver).toHaveBeenCalledWith(
expect.anything(),
{ environment: resolvedEnvironment },
expect.anything(),
expect.anything(),
);
});
it('should flash a message on error', async () => {
createComponent({ apolloProvider: mockApollo });
deleteResolver.mockRejectedValue();
wrapper.findComponent(GlModal).vm.$emit('primary');
await waitForPromises();
expect(createFlash).toHaveBeenCalledWith(
expect.objectContaining({
message: s__(
'Environments|An error occurred while deleting the environment. Check if the environment stopped; if not, stop it and try again.',
),
captureError: true,
}),
);
expect(deleteResolver).toHaveBeenCalledWith(
expect.anything(),
{ environment: resolvedEnvironment },
......
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