fixed test with new info

This commit is contained in:
joseji 2022-10-25 12:37:08 +02:00
parent 2bf1bd6d36
commit 7662d281f7
2 changed files with 24 additions and 16 deletions

View File

@ -1300,7 +1300,9 @@ describe('AdminResolver', () => {
email: 'bibi@bloxberg.de', email: 'bibi@bloxberg.de',
amount: new Decimal(300), amount: new Decimal(300),
memo: 'Danke Bibi!', memo: 'Danke Bibi!',
creationDate: new Date().toString(), creationDate: creation
? creation.contributionDate.toString()
: new Date().toString(),
}, },
}), }),
).resolves.toEqual( ).resolves.toEqual(
@ -1323,7 +1325,7 @@ describe('AdminResolver', () => {
describe('creation update is not valid', () => { describe('creation update is not valid', () => {
// as this test has not clearly defined that date, it is a false positive // as this test has not clearly defined that date, it is a false positive
it.skip('throws an error', async () => { it('throws an error', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1332,14 +1334,16 @@ describe('AdminResolver', () => {
email: 'peter@lustig.de', email: 'peter@lustig.de',
amount: new Decimal(1900), amount: new Decimal(1900),
memo: 'Danke Peter!', memo: 'Danke Peter!',
creationDate: new Date().toString(), creationDate: creation
? creation.contributionDate.toString()
: new Date().toString(),
}, },
}), }),
).resolves.toEqual( ).resolves.toEqual(
expect.objectContaining({ expect.objectContaining({
errors: [ errors: [
new GraphQLError( new GraphQLError(
'The amount (1900 GDD) to be created exceeds the amount (500 GDD) still available for this month.', 'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
), ),
], ],
}), }),
@ -1348,14 +1352,14 @@ describe('AdminResolver', () => {
it('logs the error thrown', () => { it('logs the error thrown', () => {
expect(logger.error).toBeCalledWith( expect(logger.error).toBeCalledWith(
'The amount (1900 GDD) to be created exceeds the amount (500 GDD) still available for this month.', 'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
) )
}) })
}) })
describe('creation update is successful changing month', () => { describe('creation update is successful changing month', () => {
// skipped as changing the month is currently disable // skipped as changing the month is currently disable
it.skip('returns update creation object', async () => { it('returns update creation object', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1364,7 +1368,9 @@ describe('AdminResolver', () => {
email: 'peter@lustig.de', email: 'peter@lustig.de',
amount: new Decimal(300), amount: new Decimal(300),
memo: 'Danke Peter!', memo: 'Danke Peter!',
creationDate: new Date().toString(), creationDate: creation
? creation.contributionDate.toString()
: new Date().toString(),
}, },
}), }),
).resolves.toEqual( ).resolves.toEqual(
@ -1374,7 +1380,7 @@ describe('AdminResolver', () => {
date: expect.any(String), date: expect.any(String),
memo: 'Danke Peter!', memo: 'Danke Peter!',
amount: '300', amount: '300',
creation: ['1000', '1000', '200'], creation: ['1000', '700', '500'],
}, },
}, },
}), }),
@ -1393,7 +1399,7 @@ describe('AdminResolver', () => {
describe('creation update is successful without changing month', () => { describe('creation update is successful without changing month', () => {
// actually this mutation IS changing the month // actually this mutation IS changing the month
it.skip('returns update creation object', async () => { it('returns update creation object', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1402,7 +1408,9 @@ describe('AdminResolver', () => {
email: 'peter@lustig.de', email: 'peter@lustig.de',
amount: new Decimal(200), amount: new Decimal(200),
memo: 'Das war leider zu Viel!', memo: 'Das war leider zu Viel!',
creationDate: new Date().toString(), creationDate: creation
? creation.contributionDate.toString()
: new Date().toString(),
}, },
}), }),
).resolves.toEqual( ).resolves.toEqual(
@ -1412,7 +1420,7 @@ describe('AdminResolver', () => {
date: expect.any(String), date: expect.any(String),
memo: 'Das war leider zu Viel!', memo: 'Das war leider zu Viel!',
amount: '200', amount: '200',
creation: ['1000', '1000', '300'], creation: ['1000', '800', '500'],
}, },
}, },
}), }),
@ -1446,10 +1454,10 @@ describe('AdminResolver', () => {
lastName: 'Lustig', lastName: 'Lustig',
email: 'peter@lustig.de', email: 'peter@lustig.de',
date: expect.any(String), date: expect.any(String),
memo: 'Herzlich Willkommen bei Gradido!', memo: 'Das war leider zu Viel!',
amount: '400', amount: '200',
moderator: admin.id, moderator: admin.id,
creation: ['1000', '600', '500'], creation: ['1000', '800', '500'],
}, },
{ {
id: expect.any(Number), id: expect.any(Number),
@ -1460,7 +1468,7 @@ describe('AdminResolver', () => {
memo: 'Grundeinkommen', memo: 'Grundeinkommen',
amount: '500', amount: '500',
moderator: admin.id, moderator: admin.id,
creation: ['1000', '600', '500'], creation: ['1000', '800', '500'],
}, },
{ {
id: expect.any(Number), id: expect.any(Number),

View File

@ -348,7 +348,6 @@ export class AdminResolver {
const contributionToUpdate = await DbContribution.findOne({ const contributionToUpdate = await DbContribution.findOne({
where: { id, confirmedAt: IsNull() }, where: { id, confirmedAt: IsNull() },
}) })
if (!contributionToUpdate) { if (!contributionToUpdate) {
logger.error('No contribution found to given id.') logger.error('No contribution found to given id.')
throw new Error('No contribution found to given id.') throw new Error('No contribution found to given id.')
@ -366,6 +365,7 @@ export class AdminResolver {
const creationDateObj = new Date(creationDate) const creationDateObj = new Date(creationDate)
let creations = await getUserCreation(user.id) let creations = await getUserCreation(user.id)
if (contributionToUpdate.contributionDate.getMonth() === creationDateObj.getMonth()) { if (contributionToUpdate.contributionDate.getMonth() === creationDateObj.getMonth()) {
creations = updateCreations(creations, contributionToUpdate) creations = updateCreations(creations, contributionToUpdate)
} else { } else {