diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index 86f90231b..90db3a93f 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -1,14 +1,17 @@ import { mount } from '@vue/test-utils' import CreationConfirm from './CreationConfirm.vue' +import { deletePendingCreation } from '../graphql/deletePendingCreation' const localVue = global.localVue const storeCommitMock = jest.fn() const toastedErrorMock = jest.fn() +const toastedSuccessMock = jest.fn() const apolloQueryMock = jest.fn().mockResolvedValue({ data: { getPendingCreations: [ { + id: 1, firstName: 'Bibi', lastName: 'Bloxberg', email: 'bibi@bloxberg.de', @@ -18,6 +21,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ moderator: 0, }, { + id: 2, firstName: 'Räuber', lastName: 'Hotzenplotz', email: 'raeuber@hotzenplotz.de', @@ -30,15 +34,19 @@ const apolloQueryMock = jest.fn().mockResolvedValue({ }, }) +const apolloMutateMock = jest.fn().mockResolvedValue({}) + const mocks = { $store: { commit: storeCommitMock, }, $apollo: { query: apolloQueryMock, + mutate: apolloMutateMock, }, $toasted: { error: toastedErrorMock, + success: toastedSuccessMock, }, $moment: jest.fn((value) => { return { @@ -73,6 +81,68 @@ describe('CreationConfirm', () => { }) }) + describe('confirm creation delete with success', () => { + beforeEach(async () => { + apolloQueryMock.mockResolvedValue({ + data: { + getPendingCreations: [ + { + id: 1, + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + amount: 500, + memo: 'Danke für alles', + date: new Date(), + moderator: 0, + }, + { + id: 2, + firstName: 'Räuber', + lastName: 'Hotzenplotz', + email: 'raeuber@hotzenplotz.de', + amount: 1000000, + memo: 'Gut Ergatert', + date: new Date(), + moderator: 0, + }, + ], + }, + }) + await wrapper + .findComponent({ name: 'UserTable' }) + .vm.$emit('remove-confirm-result', { id: 1 }, 'remove') + }) + + it('calls the deletePendingCreation mutation', () => { + expect(apolloMutateMock).toBeCalledWith({ + mutation: deletePendingCreation, + variables: { id: 1 }, + }) + }) + + it('commits openCreationsMinus to store', () => { + expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1) + }) + + it('toasts a success message', () => { + expect(toastedSuccessMock).toBeCalledWith('Pending Creation has been deleted') + }) + }) + + describe('confirm creation delete with error', () => { + beforeEach(async () => { + apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' }) + await wrapper + .findComponent({ name: 'UserTable' }) + .vm.$emit('remove-confirm-result', { id: 1 }, 'remove') + }) + + it('toasts an error message', () => { + expect(toastedErrorMock).toBeCalledWith('Ouchhh!') + }) + }) + describe('server response is error', () => { beforeEach(() => { jest.clearAllMocks() @@ -86,17 +156,5 @@ describe('CreationConfirm', () => { expect(toastedErrorMock).toBeCalledWith('Ouch!') }) }) - - describe('confirm creation', () => { - beforeEach(async () => { - await wrapper - .findComponent({ name: 'UserTable' }) - .vm.$emit('remove-confirm-result', 1, 'remove') - }) - - it('commits openCreationsMinus to store', () => { - expect(storeCommitMock).toBeCalledWith('openCreationsMinus', 1) - }) - }) }) }) diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index d8094ca69..42ff6da50 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -49,16 +49,11 @@ export default { confirmResult: [], } }, - methods: { removeConfirmResult(e, event) { if (event === 'remove') { let index = 0 - let findArr = {} - - findArr = this.confirmResult.find((arr) => arr.id === e.id) - - // console.log('findArr', findArr) + const findArr = this.confirmResult.find((arr) => arr.id === e.id) this.$apollo .mutate({ mutation: deletePendingCreation,