fix: Disable Change of Month for Update Contribution (wallet and admin)

This commit is contained in:
Moriz Wahl 2022-10-11 20:44:41 +02:00
parent b291c56d7b
commit bc2889a9f8
4 changed files with 17 additions and 10 deletions

View File

@ -1202,7 +1202,8 @@ describe('AdminResolver', () => {
}) })
describe('creation update is not valid', () => { describe('creation update is not valid', () => {
it('throws an error', async () => { // as this test has not clearly defined that date, it is a false positive
it.skip('throws an error', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1227,7 +1228,8 @@ describe('AdminResolver', () => {
}) })
describe('creation update is successful changing month', () => { describe('creation update is successful changing month', () => {
it('returns update creation object', async () => { // skipped as changing the month is currently disable
it.skip('returns update creation object', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1255,7 +1257,8 @@ describe('AdminResolver', () => {
}) })
describe('creation update is successful without changing month', () => { describe('creation update is successful without changing month', () => {
it('returns update creation object', async () => { // actually this mutation IS changing the month
it.skip('returns update creation object', async () => {
await expect( await expect(
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
@ -1299,10 +1302,10 @@ describe('AdminResolver', () => {
lastName: 'Lustig', lastName: 'Lustig',
email: 'peter@lustig.de', email: 'peter@lustig.de',
date: expect.any(String), date: expect.any(String),
memo: 'Das war leider zu Viel!', memo: 'Herzlich Willkommen bei Gradido!',
amount: '200', amount: '400',
moderator: admin.id, moderator: admin.id,
creation: ['1000', '1000', '300'], creation: ['1000', '600', '500'],
}, },
{ {
id: expect.any(Number), id: expect.any(Number),
@ -1313,7 +1316,7 @@ describe('AdminResolver', () => {
memo: 'Grundeinkommen', memo: 'Grundeinkommen',
amount: '500', amount: '500',
moderator: admin.id, moderator: admin.id,
creation: ['1000', '1000', '300'], creation: ['1000', '600', '500'],
}, },
{ {
id: expect.any(Number), id: expect.any(Number),

View File

@ -339,6 +339,9 @@ export class AdminResolver {
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 {
logger.error('Currently the month of the contribution cannot change.')
throw new Error('Currently the month of the contribution cannot change.')
} }
// all possible cases not to be true are thrown in this function // all possible cases not to be true are thrown in this function

View File

@ -489,9 +489,7 @@ describe('ContributionResolver', () => {
}), }),
).resolves.toEqual( ).resolves.toEqual(
expect.objectContaining({ expect.objectContaining({
errors: [ errors: [new GraphQLError('Currently the month of the contribution cannot change.')],
new GraphQLError('No information for available creations for the given date'),
],
}), }),
) )
}) })

View File

@ -164,6 +164,9 @@ export class ContributionResolver {
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 {
logger.error('Currently the month of the contribution cannot change.')
throw new Error('Currently the month of the contribution cannot change.')
} }
// all possible cases not to be true are thrown in this function // all possible cases not to be true are thrown in this function