mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into 2478-Investigate-Pagination-on-GDT
This commit is contained in:
commit
fce645f594
@ -1146,13 +1146,21 @@ describe('ContributionResolver', () => {
|
|||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
creation = await creationFactory(testEnv, {
|
await mutate({
|
||||||
|
mutation: adminCreateContribution,
|
||||||
|
variables: {
|
||||||
email: 'peter@lustig.de',
|
email: 'peter@lustig.de',
|
||||||
amount: 400,
|
amount: 400,
|
||||||
memo: 'Herzlich Willkommen bei Gradido!',
|
memo: 'Herzlich Willkommen bei Gradido!',
|
||||||
creationDate: contributionDateFormatter(
|
creationDate: contributionDateFormatter(
|
||||||
new Date(now.getFullYear(), now.getMonth() - 1, 1),
|
new Date(now.getFullYear(), now.getMonth() - 1, 1),
|
||||||
),
|
),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
creation = await Contribution.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
memo: 'Herzlich Willkommen bei Gradido!',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1879,6 +1887,10 @@ describe('ContributionResolver', () => {
|
|||||||
new Date(now.getFullYear(), now.getMonth() - 2, 1),
|
new Date(now.getFullYear(), now.getMonth() - 2, 1),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
await query({
|
||||||
|
query: login,
|
||||||
|
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns true', async () => {
|
it('returns true', async () => {
|
||||||
@ -1959,6 +1971,10 @@ describe('ContributionResolver', () => {
|
|||||||
new Date(now.getFullYear(), now.getMonth() - 2, 1),
|
new Date(now.getFullYear(), now.getMonth() - 2, 1),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
await query({
|
||||||
|
query: login,
|
||||||
|
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws no error for the second confirmation', async () => {
|
it('throws no error for the second confirmation', async () => {
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { login, createContribution, confirmContribution } from '@/seeds/graphql/mutations'
|
||||||
import { login, adminCreateContribution, confirmContribution } from '@/seeds/graphql/mutations'
|
|
||||||
import { CreationInterface } from '@/seeds/creation/CreationInterface'
|
import { CreationInterface } from '@/seeds/creation/CreationInterface'
|
||||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||||
import { Transaction } from '@entity/Transaction'
|
import { Transaction } from '@entity/Transaction'
|
||||||
@ -19,43 +18,27 @@ export const creationFactory = async (
|
|||||||
creation: CreationInterface,
|
creation: CreationInterface,
|
||||||
): Promise<Contribution | void> => {
|
): Promise<Contribution | void> => {
|
||||||
const { mutate } = client
|
const { mutate } = client
|
||||||
logger.trace('creationFactory...')
|
await mutate({ mutation: login, variables: { email: creation.email, password: 'Aa12345_' } })
|
||||||
await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
|
||||||
logger.trace('creationFactory... after login')
|
|
||||||
// TODO it would be nice to have this mutation return the id
|
|
||||||
await mutate({ mutation: adminCreateContribution, variables: { ...creation } })
|
|
||||||
logger.trace('creationFactory... after adminCreateContribution')
|
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { createContribution: contribution },
|
||||||
|
} = await mutate({ mutation: createContribution, variables: { ...creation } })
|
||||||
|
|
||||||
|
if (creation.confirmed) {
|
||||||
const user = await findUserByEmail(creation.email) // userContact.user
|
const user = await findUserByEmail(creation.email) // userContact.user
|
||||||
|
|
||||||
const pendingCreation = await Contribution.findOneOrFail({
|
await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||||
where: { userId: user.id, amount: creation.amount },
|
await mutate({ mutation: confirmContribution, variables: { id: contribution.id } })
|
||||||
order: { createdAt: 'DESC' },
|
const confirmedContribution = await Contribution.findOneOrFail({ id: contribution.id })
|
||||||
})
|
|
||||||
logger.trace(
|
|
||||||
'creationFactory... after Contribution.findOneOrFail pendingCreation=',
|
|
||||||
pendingCreation,
|
|
||||||
)
|
|
||||||
if (creation.confirmed) {
|
|
||||||
logger.trace('creationFactory... creation.confirmed=', creation.confirmed)
|
|
||||||
await mutate({ mutation: confirmContribution, variables: { id: pendingCreation.id } })
|
|
||||||
logger.trace('creationFactory... after confirmContribution')
|
|
||||||
const confirmedCreation = await Contribution.findOneOrFail({ id: pendingCreation.id })
|
|
||||||
logger.trace(
|
|
||||||
'creationFactory... after Contribution.findOneOrFail confirmedCreation=',
|
|
||||||
confirmedCreation,
|
|
||||||
)
|
|
||||||
|
|
||||||
if (creation.moveCreationDate) {
|
if (creation.moveCreationDate) {
|
||||||
logger.trace('creationFactory... creation.moveCreationDate=', creation.moveCreationDate)
|
|
||||||
const transaction = await Transaction.findOneOrFail({
|
const transaction = await Transaction.findOneOrFail({
|
||||||
where: { userId: user.id, creationDate: new Date(creation.creationDate) },
|
where: { userId: user.id, creationDate: new Date(creation.creationDate) },
|
||||||
order: { balanceDate: 'DESC' },
|
order: { balanceDate: 'DESC' },
|
||||||
})
|
})
|
||||||
logger.trace('creationFactory... after Transaction.findOneOrFail transaction=', transaction)
|
|
||||||
|
|
||||||
if (transaction.decay.equals(0) && transaction.creationDate) {
|
if (transaction.decay.equals(0) && transaction.creationDate) {
|
||||||
confirmedCreation.contributionDate = new Date(
|
confirmedContribution.contributionDate = new Date(
|
||||||
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
|
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
|
||||||
)
|
)
|
||||||
transaction.creationDate = new Date(
|
transaction.creationDate = new Date(
|
||||||
@ -64,17 +47,11 @@ export const creationFactory = async (
|
|||||||
transaction.balanceDate = new Date(
|
transaction.balanceDate = new Date(
|
||||||
nMonthsBefore(transaction.balanceDate, creation.moveCreationDate),
|
nMonthsBefore(transaction.balanceDate, creation.moveCreationDate),
|
||||||
)
|
)
|
||||||
logger.trace('creationFactory... before transaction.save transaction=', transaction)
|
|
||||||
await transaction.save()
|
await transaction.save()
|
||||||
logger.trace(
|
await confirmedContribution.save()
|
||||||
'creationFactory... before confirmedCreation.save confirmedCreation=',
|
|
||||||
confirmedCreation,
|
|
||||||
)
|
|
||||||
await confirmedCreation.save()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.trace('creationFactory... pendingCreation=', pendingCreation)
|
return contribution
|
||||||
return pendingCreation
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user