Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backend, auth): verify try-catches in tests #2782

Merged
merged 35 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f8180b7
feat: add logging plugin
sabineschaller Apr 17, 2024
646d7a1
wip: update graphql schema
sabineschaller Apr 17, 2024
ca151ac
chore: update asset resolvers
sabineschaller Apr 17, 2024
509d48d
wip: update autopeering resolvers
sabineschaller Apr 17, 2024
e2555bf
feat: further simplify asset resolver
sabineschaller Apr 17, 2024
4004989
feat: update fee resolvers
sabineschaller Apr 17, 2024
aebe65e
fix: autopeering tests
sabineschaller Apr 17, 2024
ae5ada7
feat: update incoming payments
sabineschaller Apr 17, 2024
1d74d9b
fix: improve error handling on incoming payment resolver
sabineschaller Apr 17, 2024
f24381e
feat: update outgoing payment resolvers
sabineschaller Apr 17, 2024
21cc64f
feat: update peer resolvers
sabineschaller Apr 17, 2024
3fc1188
feat: update quote resolvers
sabineschaller Apr 17, 2024
407f1e1
feat: update receiver resolvers
sabineschaller Apr 22, 2024
4f36844
feat: update wallet address resolvers
sabineschaller Apr 22, 2024
7174b71
feat: update wallet address key resolvers
sabineschaller Apr 22, 2024
a59451d
feat(wip): backend graphql logs
njlie May 30, 2024
c72a1cb
feat(backend): updated logs for graphql resolvers, remove code & mess…
njlie Jun 5, 2024
486ba03
update frontend types
njlie Jun 5, 2024
0cc23ff
chore: formatting
njlie Jun 5, 2024
bb02bce
feat: update integration tests
njlie Jun 5, 2024
7882d1d
fix: rebase induced test errors
njlie Jun 6, 2024
2ecec47
fix: frontend wallet address update
njlie Jun 7, 2024
febb43d
fix: reinstate and fix removed test
njlie Jun 8, 2024
766aea2
fix: change some payment gql error codes
njlie Jun 10, 2024
9d34ad5
feat: change liquidity response to just return success
njlie Jun 13, 2024
29a48eb
fix: bigints, integration query
njlie Jun 13, 2024
3175268
fix: integration tests
njlie Jun 14, 2024
02b5816
fix: asset test
njlie Jun 18, 2024
f308c4a
fix: delete unnecessary code
njlie Jun 18, 2024
3d569f4
fix: test for graphqlerror instead of apolloerror
njlie Jun 20, 2024
4a246ea
chore: formatting
njlie Jun 20, 2024
a999fb6
fix: inspect error object in tests
njlie Jun 25, 2024
a470603
chore(backend, auth): verify try-catches in tests
mkurapov Jun 25, 2024
665afc8
Merge branch 'main' into 2575/mk/error-assertions-in-tests
mkurapov Jun 25, 2024
2fadf08
chore(backend): fix auto-peering test
mkurapov Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions packages/auth/src/graphql/resolvers/grant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ describe('Grant Resolvers', (): void => {
})

test('Returns error for unknown grant', async (): Promise<void> => {
let gqlQuery
expect.assertions(2)
try {
gqlQuery = appContainer.apolloClient
await appContainer.apolloClient
.mutate({
mutation: gql`
query GetGrant($id: ID!) {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -563,13 +561,13 @@ describe('Grant Resolvers', (): void => {
})

test('Returns error if grant id is not provided', async (): Promise<void> => {
let gqlQuery
expect.assertions(2)
try {
const input: RevokeGrantInput = {
grantId: ''
}

gqlQuery = appContainer.apolloClient
await appContainer.apolloClient
.mutate({
mutation: gql`
mutation revokeGrant($input: RevokeGrantInput!) {
Expand All @@ -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')
Expand All @@ -601,13 +597,13 @@ describe('Grant Resolvers', (): void => {
})

test('Returns error if id does not exist', async (): Promise<void> => {
let gqlQuery
expect.assertions(2)
try {
const input: RevokeGrantInput = {
grantId: uuid()
}

gqlQuery = appContainer.apolloClient
await appContainer.apolloClient
.mutate({
mutation: gql`
mutation revokeGrant($input: RevokeGrantInput!) {
Expand All @@ -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')
Expand All @@ -639,13 +633,14 @@ describe('Grant Resolvers', (): void => {
})

test('Returns error if grant id is in invalid format', async (): Promise<void> => {
let gqlQuery
expect.assertions(1)

try {
const input: RevokeGrantInput = {
grantId: '123'
}

gqlQuery = appContainer.apolloClient
await appContainer.apolloClient
.mutate({
mutation: gql`
mutation revokeGrant($input: RevokeGrantInput!) {
Expand All @@ -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(
Expand Down
26 changes: 16 additions & 10 deletions packages/backend/src/graphql/middleware/index.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion packages/backend/src/graphql/resolvers/asset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ describe('Asset Resolvers', (): void => {

test('Returns error for duplicate asset', async (): Promise<void> => {
const input = randomAsset()
await expect(assetService.create(input)).resolves.toMatchObject(input)

await assetService.create(input)

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -173,6 +176,7 @@ describe('Asset Resolvers', (): void => {
.spyOn(assetService, 'create')
.mockRejectedValueOnce(new Error('unexpected'))

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -359,6 +363,7 @@ describe('Asset Resolvers', (): void => {
})

test('Returns error for unknown asset', async (): Promise<void> => {
expect.assertions(2)
try {
await appContainer.apolloClient
.query({
Expand Down Expand Up @@ -624,6 +629,7 @@ describe('Asset Resolvers', (): void => {
)

test('Returns error for unknown asset', async (): Promise<void> => {
expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -703,6 +709,7 @@ describe('Asset Resolvers', (): void => {
})

test('Returns error for unknown asset', async (): Promise<void> => {
expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -746,6 +753,7 @@ describe('Asset Resolvers', (): void => {
throw new Error('unexpected')
})

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/graphql/resolvers/auto-peering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -283,6 +284,7 @@ describe('Auto Peering Resolvers', (): void => {
.spyOn(autoPeeringService, 'initiatePeeringRequest')
.mockRejectedValueOnce(new Error('unexpected'))

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/graphql/resolvers/fee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ describe('Fee Resolvers', () => {
basisPoints: 100
}
}

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -141,6 +143,8 @@ describe('Fee Resolvers', () => {
basisPoints: -10_000
}
}

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down Expand Up @@ -192,6 +196,8 @@ describe('Fee Resolvers', () => {
basisPoints: -10_000
}
}

expect.assertions(2)
try {
await appContainer.apolloClient
.mutate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe('Incoming Payment Resolver', (): void => {
walletAddressId: uuid()
}

expect.assertions(3)
try {
await appContainer.apolloClient
.query({
Expand Down Expand Up @@ -231,7 +232,7 @@ describe('Incoming Payment Resolver', (): void => {
})
)
}
await expect(createSpy).toHaveBeenCalledWith(input)
expect(createSpy).toHaveBeenCalledWith(input)
})

test('Internal server error', async (): Promise<void> => {
Expand All @@ -243,6 +244,7 @@ describe('Incoming Payment Resolver', (): void => {
walletAddressId: uuid()
}

expect.assertions(3)
try {
await appContainer.apolloClient
.query({
Expand Down Expand Up @@ -275,7 +277,7 @@ describe('Incoming Payment Resolver', (): void => {
})
)
}
await expect(createSpy).toHaveBeenCalledWith(input)
expect(createSpy).toHaveBeenCalledWith(input)
})
})

Expand Down Expand Up @@ -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`
Expand Down
Loading
Loading