reset unit tests

This commit is contained in:
Moriz Wahl 2023-01-11 21:13:38 +01:00
parent 340554b815
commit 6389697bd6
2 changed files with 20 additions and 28 deletions

View File

@ -414,7 +414,7 @@ describe('ContributionResolver', () => {
resetToken()
})
describe.skip('wrong contribution id', () => {
describe('wrong contribution id', () => {
it('throws an error', async () => {
jest.clearAllMocks()
await expect(
@ -429,17 +429,13 @@ describe('ContributionResolver', () => {
}),
).resolves.toEqual(
expect.objectContaining({
errors: [
new GraphQLError('Contribution not found to given id or already confirmed.'),
],
errors: [new GraphQLError('No contribution found to given id.')],
}),
)
})
it('logs the error found', () => {
expect(logger.error).toBeCalledWith(
'Contribution not found to given id (-1) or already confirmed.',
)
expect(logger.error).toBeCalledWith('No contribution found to given id')
})
})
@ -794,7 +790,7 @@ describe('ContributionResolver', () => {
resetToken()
})
describe.skip('wrong contribution id', () => {
describe('wrong contribution id', () => {
it('returns an error', async () => {
await expect(
mutate({
@ -805,17 +801,13 @@ describe('ContributionResolver', () => {
}),
).resolves.toEqual(
expect.objectContaining({
errors: [
new GraphQLError('Contribution not found to given id or already confirmed.'),
],
errors: [new GraphQLError('Contribution not found for given id.')],
}),
)
})
it('logs the error found', () => {
expect(logger.error).toBeCalledWith(
'Contribution not found to given id (-1) or already confirmed.',
)
expect(logger.error).toBeCalledWith('Contribution not found for given id')
})
})
@ -844,7 +836,7 @@ describe('ContributionResolver', () => {
})
})
describe.skip('User deletes own contribution', () => {
describe('User deletes own contribution', () => {
it('deletes successfully', async () => {
await expect(
mutate({
@ -1841,21 +1833,17 @@ describe('ContributionResolver', () => {
}),
).resolves.toEqual(
expect.objectContaining({
errors: [
new GraphQLError('Contribution not found to given id or already confirmed.'),
],
errors: [new GraphQLError('Contribution not found to given id.')],
}),
)
})
it('logs the error thrown', () => {
expect(logger.error).toBeCalledWith(
'Contribution not found to given id (-1) or already confirmed.',
)
expect(logger.error).toBeCalledWith('Contribution not found for given id: -1')
})
})
describe.skip('confirm own creation', () => {
describe('confirm own creation', () => {
beforeAll(async () => {
const now = new Date()
creation = await creationFactory(testEnv, {
@ -1888,7 +1876,7 @@ describe('ContributionResolver', () => {
})
})
describe.skip('confirm creation for other user', () => {
describe('confirm creation for other user', () => {
beforeAll(async () => {
const now = new Date()
creation = await creationFactory(testEnv, {
@ -1920,7 +1908,7 @@ describe('ContributionResolver', () => {
)
})
it.skip('stores the contribution confirm event in the database', async () => {
it('stores the contribution confirm event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_CONFIRM,
@ -1989,7 +1977,7 @@ describe('ContributionResolver', () => {
})
})
it.skip('throws no error for the second confirmation', async () => {
it('throws no error for the second confirmation', async () => {
const r1 = mutate({
mutation: confirmContribution,
variables: {

View File

@ -557,10 +557,14 @@ export class ContributionResolver {
const releaseLock = await TRANSACTIONS_LOCK.acquire()
const clientTimezoneOffset = getClientTimezoneOffset(context)
const contribution = await DbContribution.findOne({ where: { id, confirmedAt: IsNull() } })
const contribution = await DbContribution.findOne(id)
if (!contribution) {
logger.error(`Contribution not found to given id (${id}) or already confirmed.`)
throw new Error('Contribution not found to given id or already confirmed.')
logger.error(`Contribution not found for given id: ${id}`)
throw new Error('Contribution not found to given id.')
}
if (contribution.confirmedAt) {
logger.error(`Contribution already confirmd: ${id}`)
throw new Error('Contribution already confirmd.')
}
const moderatorUser = getUser(context)
if (moderatorUser.id === contribution.userId) {