Merge branch 'master' into adminCreateMultiplePendingCreations

This commit is contained in:
Hannes Heine 2021-12-21 13:17:11 +01:00 committed by GitHub
commit 003c534f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 100 additions and 30 deletions

View File

@ -237,7 +237,7 @@ export default {
},
})
.then(() => {
this.$emit('remove-confirm-result', item, 'remove')
this.$emit('remove-confirm-result', item, 'confirmed')
})
.catch((error) => {
this.$toasted.error(error.message)

View File

@ -3,7 +3,7 @@ import gql from 'graphql-tag'
export const createPendingCreation = gql`
mutation (
$email: String!
$amount: Int!
$amount: Float!
$memo: String!
$creationDate: String!
$moderator: Int!

View File

@ -4,7 +4,7 @@ export const updatePendingCreation = gql`
mutation (
$id: Int!
$email: String!
$amount: Int!
$amount: Float!
$memo: String!
$creationDate: String!
$moderator: Int!

View File

@ -81,7 +81,7 @@ describe('CreationConfirm', () => {
})
})
describe('confirm creation delete with success', () => {
describe('delete creation delete with success', () => {
beforeEach(async () => {
apolloQueryMock.mockResolvedValue({
data: {
@ -130,7 +130,7 @@ describe('CreationConfirm', () => {
})
})
describe('confirm creation delete with error', () => {
describe('delete creation delete with error', () => {
beforeEach(async () => {
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper
@ -143,6 +143,67 @@ 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 }, 'confirmed')
})
it('calls the deletePendingCreation mutation', () => {
expect(apolloMutateMock).not.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('delete creation delete with error', () => {
beforeEach(async () => {
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'confirm')
})
it('toasts an error message', () => {
expect(toastedErrorMock).toBeCalledWith('Case confirm is not supported')
})
})
describe('server response is error', () => {
beforeEach(() => {
jest.clearAllMocks()

View File

@ -51,25 +51,34 @@ export default {
},
methods: {
removeConfirmResult(e, event) {
if (event === 'remove') {
let index = 0
const findArr = this.confirmResult.find((arr) => arr.id === e.id)
this.$apollo
.mutate({
mutation: deletePendingCreation,
variables: {
id: findArr.id,
},
})
.then((result) => {
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
})
.catch((error) => {
this.$toasted.error(error.message)
})
let index = 0
const findArr = this.confirmResult.find((arr) => arr.id === e.id)
switch (event) {
case 'remove':
this.$apollo
.mutate({
mutation: deletePendingCreation,
variables: {
id: findArr.id,
},
})
.then((result) => {
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
})
.catch((error) => {
this.$toasted.error(error.message)
})
break
case 'confirmed':
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
break
default:
this.$toasted.error('Case ' + event + ' is not supported')
}
},
getPendingCreations() {
@ -80,7 +89,7 @@ export default {
})
.then((result) => {
this.$store.commit('resetOpenCreations')
this.confirmResult = result.data.getPendingCreations.reverse()
this.confirmResult = result.data.getPendingCreations
this.$store.commit('setOpenCreations', result.data.getPendingCreations.length)
})
.catch((error) => {

View File

@ -1,4 +1,4 @@
import { ArgsType, Field, InputType, Int } from 'type-graphql'
import { ArgsType, Field, Float, InputType, Int } from 'type-graphql'
@InputType()
@ArgsType()
@ -6,7 +6,7 @@ export default class CreatePendingCreationArgs {
@Field(() => String)
email: string
@Field(() => Int)
@Field(() => Float)
amount: number
@Field(() => String)

View File

@ -1,4 +1,4 @@
import { ArgsType, Field, Int } from 'type-graphql'
import { ArgsType, Field, Float, Int } from 'type-graphql'
@ArgsType()
export default class UpdatePendingCreationArgs {
@ -8,7 +8,7 @@ export default class UpdatePendingCreationArgs {
@Field(() => String)
email: string
@Field(() => Int)
@Field(() => Float)
amount: number
@Field(() => String)

View File

@ -177,7 +177,7 @@ export class AdminResolver {
return newPendingCreation
}),
)
return pendingCreationsPromise
return pendingCreationsPromise.reverse()
}
@Mutation(() => Boolean)