Test of createContribution are now centered on the final object.

This commit is contained in:
elweyn 2023-02-08 11:29:38 +01:00
parent 778a800cce
commit 65488b5c5c

View File

@ -72,8 +72,6 @@ let mutate: any, query: any, con: any
let testEnv: any let testEnv: any
let creation: Contribution | void let creation: Contribution | void
let admin: User let admin: User
// let result: any
// let contribution: any
let pendingContribution: any let pendingContribution: any
let inProgressContribution: any let inProgressContribution: any
let contributionToConfirm: any let contributionToConfirm: any
@ -173,16 +171,12 @@ describe('ContributionResolver', () => {
describe('createContribution', () => { describe('createContribution', () => {
describe('unauthenticated', () => { describe('unauthenticated', () => {
it('returns an error', async () => { it('returns an error', async () => {
await expect( const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({
mutate({
mutation: createContribution, mutation: createContribution,
variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' }, variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' },
}), })
).resolves.toEqual(
expect.objectContaining({ expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')])
errors: [new GraphQLError('401 Unauthorized')],
}),
)
}) })
}) })
@ -202,20 +196,18 @@ describe('ContributionResolver', () => {
it('throws error when memo length smaller than 5 chars', async () => { it('throws error when memo length smaller than 5 chars', async () => {
jest.clearAllMocks() jest.clearAllMocks()
const date = new Date() const date = new Date()
await expect( const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({
mutate({
mutation: createContribution, mutation: createContribution,
variables: { variables: {
amount: 100.0, amount: 100.0,
memo: 'Test', memo: 'Test',
creationDate: date.toString(), creationDate: date.toString(),
}, },
}), })
).resolves.toEqual(
expect.objectContaining({ expect(errorObjects).toMatchObject([
errors: [new GraphQLError('memo text is too short (5 characters minimum)')], new GraphQLError('memo text is too short (5 characters minimum)'),
}), ])
)
}) })
it('logs the error found', () => { it('logs the error found', () => {
@ -225,20 +217,17 @@ describe('ContributionResolver', () => {
it('throws error when memo length greater than 255 chars', async () => { it('throws error when memo length greater than 255 chars', async () => {
jest.clearAllMocks() jest.clearAllMocks()
const date = new Date() const date = new Date()
await expect( const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({
mutate({
mutation: createContribution, mutation: createContribution,
variables: { variables: {
amount: 100.0, amount: 100.0,
memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test',
creationDate: date.toString(), creationDate: date.toString(),
}, },
}), })
).resolves.toEqual( expect(errorObjects).toMatchObject([
expect.objectContaining({ new GraphQLError('memo text is too long (255 characters maximum)'),
errors: [new GraphQLError('memo text is too long (255 characters maximum)')], ])
}),
)
}) })
it('logs the error found', () => { it('logs the error found', () => {
@ -247,22 +236,17 @@ describe('ContributionResolver', () => {
it('throws error when creationDate not-valid', async () => { it('throws error when creationDate not-valid', async () => {
jest.clearAllMocks() jest.clearAllMocks()
await expect( const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({
mutate({
mutation: createContribution, mutation: createContribution,
variables: { variables: {
amount: 100.0, amount: 100.0,
memo: 'Test env contribution', memo: 'Test env contribution',
creationDate: 'not-valid', creationDate: 'not-valid',
}, },
}), })
).resolves.toEqual( expect(errorObjects).toMatchObject([
expect.objectContaining({
errors: [
new GraphQLError('No information for available creations for the given date'), new GraphQLError('No information for available creations for the given date'),
], ])
}),
)
}) })
it('logs the error found', () => { it('logs the error found', () => {
@ -275,22 +259,17 @@ describe('ContributionResolver', () => {
it('throws error when creationDate 3 month behind', async () => { it('throws error when creationDate 3 month behind', async () => {
jest.clearAllMocks() jest.clearAllMocks()
const date = new Date() const date = new Date()
await expect( const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({
mutate({
mutation: createContribution, mutation: createContribution,
variables: { variables: {
amount: 100.0, amount: 100.0,
memo: 'Test env contribution', memo: 'Test env contribution',
creationDate: date.setMonth(date.getMonth() - 3).toString(), creationDate: date.setMonth(date.getMonth() - 3).toString(),
}, },
}), })
).resolves.toEqual( expect(errorObjects).toMatchObject([
expect.objectContaining({
errors: [
new GraphQLError('No information for available creations for the given date'), new GraphQLError('No information for available creations for the given date'),
], ])
}),
)
}) })
it('logs the error found', () => { it('logs the error found', () => {
@ -303,17 +282,11 @@ describe('ContributionResolver', () => {
describe('valid input', () => { describe('valid input', () => {
it('creates contribution', async () => { it('creates contribution', async () => {
expect(pendingContribution).toEqual( expect(pendingContribution.data.createContribution).toMatchObject({
expect.objectContaining({
data: {
createContribution: {
id: expect.any(Number), id: expect.any(Number),
amount: '100', amount: '100',
memo: 'Test PENDING contribution', memo: 'Test PENDING contribution',
}, })
},
}),
)
}) })
it('stores the create contribution event in the database', async () => { it('stores the create contribution event in the database', async () => {