mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
rename mutations to create admin contributions
This commit is contained in:
parent
916706a973
commit
e60f06bb9b
@ -1,14 +1,14 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import CreationFormular from './CreationFormular.vue'
|
||||
import { createPendingCreation } from '../graphql/createPendingCreation'
|
||||
import { createPendingCreations } from '../graphql/createPendingCreations'
|
||||
import { adminCreateContribution } from '../graphql/adminCreateContribution'
|
||||
import { adminCreateContributions } from '../graphql/adminCreateContributions'
|
||||
import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
const apolloMutateMock = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
createPendingCreation: [0, 0, 0],
|
||||
adminCreateContribution: [0, 0, 0],
|
||||
},
|
||||
})
|
||||
const stateCommitMock = jest.fn()
|
||||
@ -110,7 +110,7 @@ describe('CreationFormular', () => {
|
||||
it('sends ... to apollo', () => {
|
||||
expect(apolloMutateMock).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
mutation: createPendingCreation,
|
||||
mutation: adminCreateContribution,
|
||||
variables: {
|
||||
email: 'benjamin@bluemchen.de',
|
||||
creationDate: getCreationDate(2),
|
||||
@ -334,7 +334,7 @@ describe('CreationFormular', () => {
|
||||
jest.clearAllMocks()
|
||||
apolloMutateMock.mockResolvedValue({
|
||||
data: {
|
||||
createPendingCreations: {
|
||||
adminCreateContributions: {
|
||||
success: true,
|
||||
successfulCreation: ['bob@baumeister.de', 'bibi@bloxberg.de'],
|
||||
failedCreation: [],
|
||||
@ -355,7 +355,7 @@ describe('CreationFormular', () => {
|
||||
it('calls the API', () => {
|
||||
expect(apolloMutateMock).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
mutation: createPendingCreations,
|
||||
mutation: adminCreateContributions,
|
||||
variables: {
|
||||
pendingCreations: [
|
||||
{
|
||||
@ -390,7 +390,7 @@ describe('CreationFormular', () => {
|
||||
jest.clearAllMocks()
|
||||
apolloMutateMock.mockResolvedValue({
|
||||
data: {
|
||||
createPendingCreations: {
|
||||
adminCreateContributions: {
|
||||
success: true,
|
||||
successfulCreation: [],
|
||||
failedCreation: ['bob@baumeister.de', 'bibi@bloxberg.de'],
|
||||
|
||||
@ -85,8 +85,8 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { createPendingCreation } from '../graphql/createPendingCreation'
|
||||
import { createPendingCreations } from '../graphql/createPendingCreations'
|
||||
import { adminCreateContribution } from '../graphql/adminCreateContribution'
|
||||
import { adminCreateContributions } from '../graphql/adminCreateContributions'
|
||||
import { creationMonths } from '../mixins/creationMonths'
|
||||
export default {
|
||||
name: 'CreationFormular',
|
||||
@ -158,7 +158,7 @@ export default {
|
||||
})
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: createPendingCreations,
|
||||
mutation: adminCreateContributions,
|
||||
variables: {
|
||||
pendingCreations: submitObj,
|
||||
},
|
||||
@ -168,10 +168,10 @@ export default {
|
||||
const failedCreations = []
|
||||
this.$store.commit(
|
||||
'openCreationsPlus',
|
||||
result.data.createPendingCreations.successfulCreation.length,
|
||||
result.data.adminCreateContributions.successfulCreation.length,
|
||||
)
|
||||
if (result.data.createPendingCreations.failedCreation.length > 0) {
|
||||
result.data.createPendingCreations.failedCreation.forEach((email) => {
|
||||
if (result.data.adminCreateContributions.failedCreation.length > 0) {
|
||||
result.data.adminCreateContributions.failedCreation.forEach((email) => {
|
||||
failedCreations.push(email)
|
||||
})
|
||||
}
|
||||
@ -190,11 +190,11 @@ export default {
|
||||
}
|
||||
this.$apollo
|
||||
.mutate({
|
||||
mutation: createPendingCreation,
|
||||
mutation: adminCreateContribution,
|
||||
variables: submitObj,
|
||||
})
|
||||
.then((result) => {
|
||||
this.$emit('update-user-data', this.item, result.data.createPendingCreation)
|
||||
this.$emit('update-user-data', this.item, result.data.adminCreateContribution)
|
||||
this.$store.commit('openCreationsPlus', 1)
|
||||
this.toastSuccess(
|
||||
this.$t('creation_form.toasted', {
|
||||
|
||||
12
admin/src/graphql/adminCreateContribution.js
Normal file
12
admin/src/graphql/adminCreateContribution.js
Normal file
@ -0,0 +1,12 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const adminCreateContribution = gql`
|
||||
mutation ($email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
adminCreateContribution(
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
)
|
||||
}
|
||||
`
|
||||
@ -1,8 +1,8 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const createPendingCreations = gql`
|
||||
export const adminCreateContributions = gql`
|
||||
mutation ($pendingCreations: [AdminCreateContributionArgs!]!) {
|
||||
createPendingCreations(pendingCreations: $pendingCreations) {
|
||||
adminCreateContributions(pendingCreations: $pendingCreations) {
|
||||
success
|
||||
successfulCreation
|
||||
failedCreation
|
||||
@ -1,7 +0,0 @@
|
||||
import gql from 'graphql-tag'
|
||||
|
||||
export const createPendingCreation = gql`
|
||||
mutation ($email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
createPendingCreation(email: $email, amount: $amount, memo: $memo, creationDate: $creationDate)
|
||||
}
|
||||
`
|
||||
@ -15,8 +15,8 @@ import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
|
||||
import {
|
||||
deleteUser,
|
||||
unDeleteUser,
|
||||
createPendingCreation,
|
||||
createPendingCreations,
|
||||
adminCreateContribution,
|
||||
adminCreateContributions,
|
||||
updatePendingCreation,
|
||||
deletePendingCreation,
|
||||
confirmPendingCreation,
|
||||
@ -497,9 +497,9 @@ describe('AdminResolver', () => {
|
||||
}
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
describe('createPendingCreation', () => {
|
||||
describe('adminCreateContribution', () => {
|
||||
it('returns an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
await expect(mutate({ mutation: adminCreateContribution, variables })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('401 Unauthorized')],
|
||||
}),
|
||||
@ -507,11 +507,11 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('createPendingCreations', () => {
|
||||
describe('adminCreateContributions', () => {
|
||||
it('returns an error', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPendingCreations,
|
||||
mutation: adminCreateContributions,
|
||||
variables: { pendingCreations: [variables] },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
@ -607,9 +607,9 @@ describe('AdminResolver', () => {
|
||||
resetToken()
|
||||
})
|
||||
|
||||
describe('createPendingCreation', () => {
|
||||
describe('adminCreateContribution', () => {
|
||||
it('returns an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
await expect(mutate({ mutation: adminCreateContribution, variables })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('401 Unauthorized')],
|
||||
}),
|
||||
@ -617,11 +617,11 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('createPendingCreations', () => {
|
||||
describe('adminCreateContributions', () => {
|
||||
it('returns an error', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPendingCreations,
|
||||
mutation: adminCreateContributions,
|
||||
variables: { pendingCreations: [variables] },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
@ -716,7 +716,7 @@ describe('AdminResolver', () => {
|
||||
resetToken()
|
||||
})
|
||||
|
||||
describe('createPendingCreation', () => {
|
||||
describe('adminCreateContribution', () => {
|
||||
beforeAll(async () => {
|
||||
const now = new Date()
|
||||
creation = await creationFactory(testEnv, {
|
||||
@ -729,7 +729,9 @@ describe('AdminResolver', () => {
|
||||
|
||||
describe('user to create for does not exist', () => {
|
||||
it('throws an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
await expect(
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('Could not find user with email: bibi@bloxberg.de')],
|
||||
}),
|
||||
@ -744,7 +746,9 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
|
||||
it('throws an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
await expect(
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('This user was deleted. Cannot make a creation.')],
|
||||
}),
|
||||
@ -759,7 +763,9 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
|
||||
it('throws an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
await expect(
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('Creation could not be saved, Email is not activated')],
|
||||
}),
|
||||
@ -776,7 +782,7 @@ describe('AdminResolver', () => {
|
||||
describe('date of creation is not a date string', () => {
|
||||
it('throws an error', async () => {
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
@ -796,7 +802,7 @@ describe('AdminResolver', () => {
|
||||
1,
|
||||
).toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
@ -816,7 +822,7 @@ describe('AdminResolver', () => {
|
||||
1,
|
||||
).toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
@ -831,7 +837,7 @@ describe('AdminResolver', () => {
|
||||
it('throws an error', async () => {
|
||||
variables.creationDate = new Date().toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
@ -848,11 +854,11 @@ describe('AdminResolver', () => {
|
||||
it('returns an array of the open creations for the last three months', async () => {
|
||||
variables.amount = new Decimal(200)
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
createPendingCreation: [1000, 1000, 800],
|
||||
adminCreateContribution: [1000, 1000, 800],
|
||||
},
|
||||
}),
|
||||
)
|
||||
@ -863,7 +869,7 @@ describe('AdminResolver', () => {
|
||||
it('returns an array of the open creations for the last three months', async () => {
|
||||
variables.amount = new Decimal(1000)
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
mutate({ mutation: adminCreateContribution, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
@ -878,7 +884,7 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('createPendingCreations', () => {
|
||||
describe('adminCreateContributions', () => {
|
||||
// at this point we have this data in DB:
|
||||
// bibi@bloxberg.de: [1000, 1000, 800]
|
||||
// peter@lustig.de: [1000, 600, 1000]
|
||||
@ -903,13 +909,13 @@ describe('AdminResolver', () => {
|
||||
it('returns success, two successful creation and three failed creations', async () => {
|
||||
await expect(
|
||||
mutate({
|
||||
mutation: createPendingCreations,
|
||||
mutation: adminCreateContributions,
|
||||
variables: { pendingCreations: massCreationVariables },
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
createPendingCreations: {
|
||||
adminCreateContributions: {
|
||||
success: true,
|
||||
successfulCreation: ['bibi@bloxberg.de', 'peter@lustig.de'],
|
||||
failedCreation: [
|
||||
|
||||
@ -166,11 +166,11 @@ export class AdminResolver {
|
||||
|
||||
@Authorized([RIGHTS.CREATE_PENDING_CREATION])
|
||||
@Mutation(() => [Number])
|
||||
async createPendingCreation(
|
||||
async adminCreateContribution(
|
||||
@Args() { email, amount, memo, creationDate }: AdminCreateContributionArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<Decimal[]> {
|
||||
logger.trace('createPendingCreation...')
|
||||
logger.trace('adminCreateContribution...')
|
||||
const user = await dbUser.findOne({ email }, { withDeleted: true })
|
||||
if (!user) {
|
||||
throw new Error(`Could not find user with email: ${email}`)
|
||||
@ -203,7 +203,7 @@ export class AdminResolver {
|
||||
|
||||
@Authorized([RIGHTS.CREATE_PENDING_CREATION])
|
||||
@Mutation(() => AdminCreateContribution)
|
||||
async createPendingCreations(
|
||||
async adminCreateContributions(
|
||||
@Arg('pendingCreations', () => [AdminCreateContributionArgs])
|
||||
contributions: AdminCreateContributionArgs[],
|
||||
@Ctx() context: Context,
|
||||
@ -212,7 +212,7 @@ export class AdminResolver {
|
||||
const successfulCreation: string[] = []
|
||||
const failedCreation: string[] = []
|
||||
for (const contribution of contributions) {
|
||||
await this.createPendingCreation(contribution, context)
|
||||
await this.adminCreateContribution(contribution, context)
|
||||
.then(() => {
|
||||
successfulCreation.push(contribution.email)
|
||||
success = true
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { createPendingCreation, confirmPendingCreation } from '@/seeds/graphql/mutations'
|
||||
import { adminCreateContribution, confirmPendingCreation } from '@/seeds/graphql/mutations'
|
||||
import { login } from '@/seeds/graphql/queries'
|
||||
import { CreationInterface } from '@/seeds/creation/CreationInterface'
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
@ -23,7 +23,7 @@ export const creationFactory = async (
|
||||
await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||
|
||||
// TODO it would be nice to have this mutation return the id
|
||||
await mutate({ mutation: createPendingCreation, variables: { ...creation } })
|
||||
await mutate({ mutation: adminCreateContribution, variables: { ...creation } })
|
||||
|
||||
const user = await User.findOneOrFail({ where: { email: creation.email } })
|
||||
|
||||
|
||||
@ -81,9 +81,14 @@ export const createTransactionLink = gql`
|
||||
|
||||
// from admin interface
|
||||
|
||||
export const createPendingCreation = gql`
|
||||
export const adminCreateContribution = gql`
|
||||
mutation ($email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
|
||||
createPendingCreation(email: $email, amount: $amount, memo: $memo, creationDate: $creationDate)
|
||||
adminCreateContribution(
|
||||
email: $email
|
||||
amount: $amount
|
||||
memo: $memo
|
||||
creationDate: $creationDate
|
||||
)
|
||||
}
|
||||
`
|
||||
|
||||
@ -105,9 +110,9 @@ export const unDeleteUser = gql`
|
||||
}
|
||||
`
|
||||
|
||||
export const createPendingCreations = gql`
|
||||
export const adminCreateContributions = gql`
|
||||
mutation ($pendingCreations: [AdminCreateContributionArgs!]!) {
|
||||
createPendingCreations(pendingCreations: $pendingCreations) {
|
||||
adminCreateContributions(pendingCreations: $pendingCreations) {
|
||||
success
|
||||
successfulCreation
|
||||
failedCreation
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user