diff --git a/packages/auth/src/graphql/resolvers/grant.test.ts b/packages/auth/src/graphql/resolvers/grant.test.ts index 55a46eecf1..e72e5fd7d2 100644 --- a/packages/auth/src/graphql/resolvers/grant.test.ts +++ b/packages/auth/src/graphql/resolvers/grant.test.ts @@ -483,9 +483,9 @@ describe('Grant Resolvers', (): void => { }) test('Returns error for unknown grant', async (): Promise => { - let gqlQuery + expect.assertions(2) try { - gqlQuery = appContainer.apolloClient + await appContainer.apolloClient .mutate({ mutation: gql` query GetGrant($id: ID!) { @@ -515,8 +515,6 @@ describe('Grant Resolvers', (): void => { throw new Error('Data was empty') } }) - - await gqlQuery // throw error to inspect error object } catch (error) { assert.ok(error instanceof ApolloError) expect(error.message).toBe('No grant') @@ -563,13 +561,13 @@ describe('Grant Resolvers', (): void => { }) test('Returns error if grant id is not provided', async (): Promise => { - let gqlQuery + expect.assertions(2) try { const input: RevokeGrantInput = { grantId: '' } - gqlQuery = appContainer.apolloClient + await appContainer.apolloClient .mutate({ mutation: gql` mutation revokeGrant($input: RevokeGrantInput!) { @@ -589,8 +587,6 @@ describe('Grant Resolvers', (): void => { throw new Error('Data was empty') } }) - - await gqlQuery // throw error to inspect error object } catch (error) { assert.ok(error instanceof ApolloError) expect(error.message).toBe('Grant id is not provided') @@ -601,13 +597,13 @@ describe('Grant Resolvers', (): void => { }) test('Returns error if id does not exist', async (): Promise => { - let gqlQuery + expect.assertions(2) try { const input: RevokeGrantInput = { grantId: uuid() } - gqlQuery = appContainer.apolloClient + await appContainer.apolloClient .mutate({ mutation: gql` mutation revokeGrant($input: RevokeGrantInput!) { @@ -627,8 +623,6 @@ describe('Grant Resolvers', (): void => { throw new Error('Data was empty') } }) - - await gqlQuery // throw error to inspect error object } catch (error) { assert.ok(error instanceof ApolloError) expect(error.message).toBe('Revoke grant was not successful') @@ -639,13 +633,14 @@ describe('Grant Resolvers', (): void => { }) test('Returns error if grant id is in invalid format', async (): Promise => { - let gqlQuery + expect.assertions(1) + try { const input: RevokeGrantInput = { grantId: '123' } - gqlQuery = appContainer.apolloClient + await appContainer.apolloClient .mutate({ mutation: gql` mutation revokeGrant($input: RevokeGrantInput!) { @@ -665,8 +660,6 @@ describe('Grant Resolvers', (): void => { throw new Error('Data was empty') } }) - - await gqlQuery // throw error to inspect error object } catch (error) { assert.ok(error instanceof ApolloError) expect(error.graphQLErrors[0].extensions.code).toEqual( diff --git a/packages/backend/src/graphql/middleware/index.test.ts b/packages/backend/src/graphql/middleware/index.test.ts index 9631870034..1c816dd1cd 100644 --- a/packages/backend/src/graphql/middleware/index.test.ts +++ b/packages/backend/src/graphql/middleware/index.test.ts @@ -1,4 +1,4 @@ -import { gql } from '@apollo/client' +import { ApolloError, gql } from '@apollo/client' import assert from 'assert' import { v4 as uuid } from 'uuid' @@ -193,16 +193,22 @@ describe('GraphQL Middleware', (): void => { createAssetSpy.mockClear() - const repeatResponse = callCreateAssetMutation({ - ...input, - idempotencyKey: uuid() - }) - - await expect(repeatResponse).rejects.toThrow( - new GraphQLError(errorToMessage[AssetError.DuplicateAsset], { - extensions: { + let error + try { + await callCreateAssetMutation({ + ...input, + idempotencyKey: uuid() + }) + } catch (err) { + error = err + } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: errorToMessage[AssetError.DuplicateAsset], + extensions: expect.objectContaining({ code: errorToCode[AssetError.DuplicateAsset] - } + }) }) ) expect(createAssetSpy).toHaveBeenCalledTimes(1) diff --git a/packages/backend/src/graphql/resolvers/asset.test.ts b/packages/backend/src/graphql/resolvers/asset.test.ts index 99d2f642ed..d174e32a2b 100644 --- a/packages/backend/src/graphql/resolvers/asset.test.ts +++ b/packages/backend/src/graphql/resolvers/asset.test.ts @@ -131,7 +131,10 @@ describe('Asset Resolvers', (): void => { test('Returns error for duplicate asset', async (): Promise => { const input = randomAsset() - await expect(assetService.create(input)).resolves.toMatchObject(input) + + await assetService.create(input) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -173,6 +176,7 @@ describe('Asset Resolvers', (): void => { .spyOn(assetService, 'create') .mockRejectedValueOnce(new Error('unexpected')) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -359,6 +363,7 @@ describe('Asset Resolvers', (): void => { }) test('Returns error for unknown asset', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .query({ @@ -624,6 +629,7 @@ describe('Asset Resolvers', (): void => { ) test('Returns error for unknown asset', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -703,6 +709,7 @@ describe('Asset Resolvers', (): void => { }) test('Returns error for unknown asset', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -746,6 +753,7 @@ describe('Asset Resolvers', (): void => { throw new Error('unexpected') }) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/auto-peering.test.ts b/packages/backend/src/graphql/resolvers/auto-peering.test.ts index 81c1191981..49715fdfe0 100644 --- a/packages/backend/src/graphql/resolvers/auto-peering.test.ts +++ b/packages/backend/src/graphql/resolvers/auto-peering.test.ts @@ -240,6 +240,7 @@ describe('Auto Peering Resolvers', (): void => { .spyOn(autoPeeringService, 'initiatePeeringRequest') .mockResolvedValueOnce(testError) const input = createOrUpdatePeerByUrlInput() + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -283,6 +284,7 @@ describe('Auto Peering Resolvers', (): void => { .spyOn(autoPeeringService, 'initiatePeeringRequest') .mockRejectedValueOnce(new Error('unexpected')) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/fee.test.ts b/packages/backend/src/graphql/resolvers/fee.test.ts index 13a14b9c05..ee7306f2ef 100644 --- a/packages/backend/src/graphql/resolvers/fee.test.ts +++ b/packages/backend/src/graphql/resolvers/fee.test.ts @@ -93,6 +93,8 @@ describe('Fee Resolvers', () => { basisPoints: 100 } } + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -141,6 +143,8 @@ describe('Fee Resolvers', () => { basisPoints: -10_000 } } + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -192,6 +196,8 @@ describe('Fee Resolvers', () => { basisPoints: -10_000 } } + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/incoming_payment.test.ts b/packages/backend/src/graphql/resolvers/incoming_payment.test.ts index 3278c9d58c..61a185980c 100644 --- a/packages/backend/src/graphql/resolvers/incoming_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/incoming_payment.test.ts @@ -199,6 +199,7 @@ describe('Incoming Payment Resolver', (): void => { walletAddressId: uuid() } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -231,7 +232,7 @@ describe('Incoming Payment Resolver', (): void => { }) ) } - await expect(createSpy).toHaveBeenCalledWith(input) + expect(createSpy).toHaveBeenCalledWith(input) }) test('Internal server error', async (): Promise => { @@ -243,6 +244,7 @@ describe('Incoming Payment Resolver', (): void => { walletAddressId: uuid() } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -275,7 +277,7 @@ describe('Incoming Payment Resolver', (): void => { }) ) } - await expect(createSpy).toHaveBeenCalledWith(input) + expect(createSpy).toHaveBeenCalledWith(input) }) }) @@ -412,6 +414,7 @@ describe('Incoming Payment Resolver', (): void => { .spyOn(incomingPaymentService, 'get') .mockImplementation(async () => undefined) + expect.assertions(2) try { await appContainer.apolloClient.query({ query: gql` diff --git a/packages/backend/src/graphql/resolvers/liquidity.test.ts b/packages/backend/src/graphql/resolvers/liquidity.test.ts index 26fdfdca3a..e0968b27e1 100644 --- a/packages/backend/src/graphql/resolvers/liquidity.test.ts +++ b/packages/backend/src/graphql/resolvers/liquidity.test.ts @@ -104,6 +104,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns an error for invalid id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -132,20 +133,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for unknown peer', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -174,17 +177,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'unknown peer', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'unknown peer', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -196,6 +200,8 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(100) }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -224,20 +230,23 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) test('Returns an error for zero amount', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -266,17 +275,19 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer amount is zero', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Forbidden - }) - }) - ) + } catch (err) { + error = err } + + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer amount is zero', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Forbidden + }) + }) + ) }) }) @@ -321,6 +332,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns an error for invalid id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -349,20 +361,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for unknown asset', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -391,17 +405,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown asset', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown asset', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -413,6 +428,8 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(100) }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -441,20 +458,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) test('Returns an error for zero amount', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -483,17 +502,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer amount is zero', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Forbidden - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer amount is zero', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Forbidden + }) + }) + ) }) }) @@ -547,6 +567,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns an error for unknown peer', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -576,20 +597,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown peer', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown peer', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test('Returns an error for invalid id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -619,17 +642,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -641,6 +665,8 @@ describe('Liquidity Resolvers', (): void => { amount: 10n }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -670,17 +696,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) test.each` @@ -690,6 +717,7 @@ describe('Liquidity Resolvers', (): void => { `( 'Returns error for $code', async ({ amount, message, code }): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -719,17 +747,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message, - extensions: expect.objectContaining({ - code - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message, + extensions: expect.objectContaining({ + code + }) + }) + ) } ) }) @@ -784,6 +813,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns an error for unknown asset', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -813,20 +843,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown asset', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown asset', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test('Returns an error for invalid id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -856,17 +888,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -878,6 +911,8 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(10) }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -907,17 +942,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) test.each` @@ -927,6 +963,7 @@ describe('Liquidity Resolvers', (): void => { `( 'Returns error for $error', async ({ amount, code, message }): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -956,17 +993,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message, - extensions: expect.objectContaining({ - code - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message, + extensions: expect.objectContaining({ + code + }) + }) + ) } ) }) @@ -1035,6 +1073,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns an error for unknown wallet address', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1065,20 +1104,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown wallet address', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown wallet address', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test('Returns an error for invalid id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1109,17 +1150,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -1131,6 +1173,8 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(10) }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -1161,17 +1205,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) test('Returns an error for empty balance', async (): Promise => { @@ -1183,6 +1228,8 @@ describe('Liquidity Resolvers', (): void => { timeout: 0 }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -1213,17 +1260,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer amount is zero', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Forbidden - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer amount is zero', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Forbidden + }) + }) + ) }) }) @@ -1284,6 +1332,7 @@ describe('Liquidity Resolvers', (): void => { }) test("Can't post non-existent withdrawal", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1310,20 +1359,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown transfer', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown transfer', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test("Can't post invalid withdrawal id", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1350,23 +1401,26 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test("Can't post posted withdrawal", async (): Promise => { await expect( accountingService.postWithdrawal(withdrawalId) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -1391,25 +1445,28 @@ describe('Liquidity Resolvers', (): void => { return query.data.postLiquidityWithdrawal } else { throw new Error('Data was empty') - } - }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already posted', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Conflict - }) + } }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already posted', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Conflict + }) + }) + ) }) test("Can't post voided withdrawal", async (): Promise => { await expect( accountingService.voidWithdrawal(withdrawalId) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -1436,17 +1493,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already voided', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Conflict - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already voided', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Conflict + }) + }) + ) }) } ) @@ -1508,6 +1566,7 @@ describe('Liquidity Resolvers', (): void => { }) test("Can't void non-existent withdrawal", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1534,20 +1593,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Unknown transfer', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.NotFound - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Unknown transfer', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.NotFound + }) + }) + ) }) test("Can't void invalid withdrawal id", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1574,23 +1635,25 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test("Can't void posted withdrawal", async (): Promise => { await expect( accountingService.postWithdrawal(withdrawalId) ).resolves.toBeUndefined() + let error try { await appContainer.apolloClient .mutate({ @@ -1617,23 +1680,25 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already posted', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Conflict - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already posted', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Conflict + }) + }) + ) }) test("Can't void voided withdrawal", async (): Promise => { await expect( accountingService.voidWithdrawal(withdrawalId) ).resolves.toBeUndefined() + let error try { await appContainer.apolloClient .mutate({ @@ -1660,17 +1725,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already voided', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Conflict - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already voided', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Conflict + }) + }) + ) }) } ) @@ -1768,6 +1834,7 @@ describe('Liquidity Resolvers', (): void => { }) test("Can't deposit for non-existent webhook event id", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -1794,17 +1861,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -1815,6 +1883,7 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(100) }) ).resolves.toBeUndefined() + let error try { await appContainer.apolloClient .mutate({ @@ -1841,17 +1910,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) } ) @@ -1990,6 +2060,7 @@ describe('Liquidity Resolvers', (): void => { }) test('Returns error for non-existent webhook event id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -2016,23 +2087,26 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns error for already completed withdrawal', async (): Promise => { await expect( accountingService.createWithdrawal(withdrawal) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -2059,17 +2133,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) } ) @@ -2194,6 +2269,7 @@ describe('Liquidity Resolvers', (): void => { amount } }) + let error try { await appContainer.apolloClient .mutate({ @@ -2221,20 +2297,22 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns error when related webhook not found', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -2262,17 +2340,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns error for already completed withdrawal', async (): Promise => { @@ -2295,6 +2374,8 @@ describe('Liquidity Resolvers', (): void => { amount: amount }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -2322,17 +2403,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) }) }) @@ -2409,6 +2491,7 @@ describe('Liquidity Resolvers', (): void => { describe('Cannot withdraw liquidity', () => { test('Returns error for non-existent outgoing payment id', async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -2436,17 +2519,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns error when related webhook not found', async (): Promise => { @@ -2457,6 +2541,7 @@ describe('Liquidity Resolvers', (): void => { amount: amount }) ).resolves.toBeUndefined() + let error try { await appContainer.apolloClient .mutate({ @@ -2484,17 +2569,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns error for already completed withdrawal', async (): Promise => { @@ -2516,6 +2602,8 @@ describe('Liquidity Resolvers', (): void => { amount: amount }) ).resolves.toBeUndefined() + + let error try { await appContainer.apolloClient .mutate({ @@ -2543,17 +2631,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Insufficient transfer balance', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Forbidden - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Insufficient transfer balance', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Forbidden + }) + }) + ) }) }) }) @@ -2618,6 +2707,7 @@ describe('Liquidity Resolvers', (): void => { }) test("Can't deposit for non-existent outgoing payment id", async (): Promise => { + let error try { await appContainer.apolloClient .mutate({ @@ -2644,17 +2734,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Invalid transfer id', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.BadUserInput - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Invalid transfer id', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.BadUserInput + }) + }) + ) }) test('Returns an error for existing transfer', async (): Promise => { @@ -2665,6 +2756,7 @@ describe('Liquidity Resolvers', (): void => { amount: BigInt(100) }) ).resolves.toBeUndefined() + let error try { await appContainer.apolloClient .mutate({ @@ -2691,17 +2783,18 @@ describe('Liquidity Resolvers', (): void => { throw new Error('Data was empty') } }) - } catch (error) { - expect(error).toBeInstanceOf(ApolloError) - expect((error as ApolloError).graphQLErrors).toContainEqual( - expect.objectContaining({ - message: 'Transfer already exists', - extensions: expect.objectContaining({ - code: GraphQLErrorCode.Duplicate - }) - }) - ) + } catch (err) { + error = err } + expect(error).toBeInstanceOf(ApolloError) + expect((error as ApolloError).graphQLErrors).toContainEqual( + expect.objectContaining({ + message: 'Transfer already exists', + extensions: expect.objectContaining({ + code: GraphQLErrorCode.Duplicate + }) + }) + ) }) } ) diff --git a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts index e7ee1d1b20..53d7d9bb48 100644 --- a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts @@ -249,6 +249,7 @@ describe('OutgoingPayment Resolvers', (): void => { .spyOn(outgoingPaymentService, 'get') .mockImplementation(async () => undefined) + expect.assertions(2) try { await appContainer.apolloClient.query({ query: gql` @@ -330,6 +331,7 @@ describe('OutgoingPayment Resolvers', (): void => { quoteId: uuid() } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -362,7 +364,7 @@ describe('OutgoingPayment Resolvers', (): void => { }) ) } - await expect(createSpy).toHaveBeenCalledWith(input) + expect(createSpy).toHaveBeenCalledWith(input) }) test('internal server error', async (): Promise => { @@ -375,6 +377,7 @@ describe('OutgoingPayment Resolvers', (): void => { quoteId: uuid() } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -475,6 +478,7 @@ describe('OutgoingPayment Resolvers', (): void => { } } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -525,6 +529,7 @@ describe('OutgoingPayment Resolvers', (): void => { } } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -636,6 +641,7 @@ describe('OutgoingPayment Resolvers', (): void => { const input = { id: uuid() } + expect.assertions(3) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/peer.test.ts b/packages/backend/src/graphql/resolvers/peer.test.ts index deec0406af..8fc24012d2 100644 --- a/packages/backend/src/graphql/resolvers/peer.test.ts +++ b/packages/backend/src/graphql/resolvers/peer.test.ts @@ -160,6 +160,8 @@ describe('Peer Resolvers', (): void => { `('Error - $error', async ({ error: testError }): Promise => { jest.spyOn(peerService, 'create').mockResolvedValueOnce(testError) const peer = randomPeer() + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -203,6 +205,7 @@ describe('Peer Resolvers', (): void => { throw new Error('unexpected') }) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -332,6 +335,7 @@ describe('Peer Resolvers', (): void => { }) test('Returns error for unknown peer', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .query({ @@ -541,6 +545,7 @@ describe('Peer Resolvers', (): void => { ${PeerError.UnknownPeer} `('Error - $error', async ({ error: testError }): Promise => { jest.spyOn(peerService, 'update').mockResolvedValueOnce(testError) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -585,6 +590,7 @@ describe('Peer Resolvers', (): void => { throw new Error('unexpected') }) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -670,6 +676,7 @@ describe('Peer Resolvers', (): void => { }) test('Returns error for unknown peer', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -710,6 +717,7 @@ describe('Peer Resolvers', (): void => { jest.spyOn(peerService, 'delete').mockImplementationOnce(async () => { throw new Error('unexpected') }) + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/quote.test.ts b/packages/backend/src/graphql/resolvers/quote.test.ts index 8202a6f410..39efdac43c 100644 --- a/packages/backend/src/graphql/resolvers/quote.test.ts +++ b/packages/backend/src/graphql/resolvers/quote.test.ts @@ -137,6 +137,7 @@ describe('Quote Resolvers', (): void => { test('Not found', async (): Promise => { jest.spyOn(quoteService, 'get').mockImplementation(async () => undefined) + expect.assertions(2) try { await appContainer.apolloClient.query({ query: gql` @@ -236,6 +237,7 @@ describe('Quote Resolvers', (): void => { }) test('unknown walletAddress', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .query({ @@ -269,6 +271,7 @@ describe('Quote Resolvers', (): void => { .spyOn(quoteService, 'create') .mockRejectedValueOnce(new Error('unexpected')) + expect.assertions(3) try { await appContainer.apolloClient .query({ diff --git a/packages/backend/src/graphql/resolvers/receiver.test.ts b/packages/backend/src/graphql/resolvers/receiver.test.ts index 8b0988ea90..2ee01cb326 100644 --- a/packages/backend/src/graphql/resolvers/receiver.test.ts +++ b/packages/backend/src/graphql/resolvers/receiver.test.ts @@ -143,6 +143,7 @@ describe('Receiver Resolver', (): void => { walletAddressUrl: walletAddress.id } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -199,6 +200,7 @@ describe('Receiver Resolver', (): void => { walletAddressUrl: walletAddress.id } + expect.assertions(3) try { await appContainer.apolloClient .query({ @@ -318,19 +320,18 @@ describe('Receiver Resolver', (): void => { .spyOn(receiverService, 'get') .mockImplementation(async () => undefined) + expect.assertions(2) try { - await expect( - appContainer.apolloClient.query({ - query: gql` - query GetReceiver($id: String!) { - receiver(id: $id) { - id - } + await appContainer.apolloClient.query({ + query: gql` + query GetReceiver($id: String!) { + receiver(id: $id) { + id } - `, - variables: { id: uuid() } - }) - ).rejects.toThrow('receiver does not exist') + } + `, + variables: { id: uuid() } + }) } catch (error) { expect(error).toBeInstanceOf(ApolloError) expect((error as ApolloError).graphQLErrors).toContainEqual( diff --git a/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts b/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts index 69db46f44b..660ffbd5ba 100644 --- a/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts +++ b/packages/backend/src/graphql/resolvers/walletAddressKey.test.ts @@ -113,6 +113,7 @@ describe('Wallet Address Key Resolvers', (): void => { jwk: TEST_KEY } + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -220,6 +221,7 @@ describe('Wallet Address Key Resolvers', (): void => { }) test('Returns not found if key does not exist', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/graphql/resolvers/wallet_address.test.ts b/packages/backend/src/graphql/resolvers/wallet_address.test.ts index d57e3d71b4..ff51dd0d1f 100644 --- a/packages/backend/src/graphql/resolvers/wallet_address.test.ts +++ b/packages/backend/src/graphql/resolvers/wallet_address.test.ts @@ -214,6 +214,8 @@ describe('Wallet Address Resolvers', (): void => { jest .spyOn(walletAddressService, 'create') .mockResolvedValueOnce(testError) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -260,6 +262,8 @@ describe('Wallet Address Resolvers', (): void => { .mockImplementationOnce(async (_args) => { throw new Error('unexpected') }) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -540,6 +544,8 @@ describe('Wallet Address Resolvers', (): void => { jest .spyOn(walletAddressService, 'update') .mockResolvedValueOnce(testError) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -585,6 +591,8 @@ describe('Wallet Address Resolvers', (): void => { .mockImplementationOnce(async () => { throw new Error('unexpected') }) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ @@ -711,6 +719,7 @@ describe('Wallet Address Resolvers', (): void => { ) test('Returns error for unknown wallet address', async (): Promise => { + expect.assertions(2) try { await appContainer.apolloClient .query({ @@ -881,6 +890,8 @@ describe('Wallet Address Resolvers', (): void => { jest .spyOn(walletAddressService, 'triggerEvents') .mockRejectedValueOnce(new Error('unexpected')) + + expect.assertions(2) try { await appContainer.apolloClient .mutate({ diff --git a/packages/backend/src/payment-method/ilp/service.test.ts b/packages/backend/src/payment-method/ilp/service.test.ts index 728a9e5b12..6c0fcb1a4f 100644 --- a/packages/backend/src/payment-method/ilp/service.test.ts +++ b/packages/backend/src/payment-method/ilp/service.test.ts @@ -638,6 +638,7 @@ describe('IlpPaymentService', (): void => { mockIlpPay({}, Object.keys(retryableIlpErrors)[0] as Pay.PaymentError) + expect.assertions(4) try { await ilpPaymentService.pay({ receiver,