Skip to content

Commit

Permalink
fix(backend): graphql resolver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Sep 24, 2024
1 parent 7c1ea24 commit 83342a9
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 76 deletions.
14 changes: 14 additions & 0 deletions packages/backend/src/graphql/middleware/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApolloError, gql } from '@apollo/client'
import assert from 'assert'
import { v4 as uuid } from 'uuid'
import { faker } from '@faker-js/faker'

import { createTestApp, TestContainer } from '../../tests/app'
import { IocContract } from '@adonisjs/fold'
Expand All @@ -17,6 +18,8 @@ import {
} from '../generated/graphql'
import { GraphQLError } from 'graphql'
import { AssetError, errorToMessage, errorToCode } from '../../asset/errors'
import { createTenant } from '../../tests/tenant'
import { EndpointType } from '../../tenant/endpoints/model'

describe('GraphQL Middleware', (): void => {
let deps: IocContract<AppServices>
Expand All @@ -29,6 +32,17 @@ describe('GraphQL Middleware', (): void => {
assetService = await deps.use('assetService')
})

beforeEach(async (): Promise<void> => {
await createTenant(deps, {
email: Config.kratosAdminEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
})

afterEach(async (): Promise<void> => {
await truncateTables(appContainer.knex)
})
Expand Down
14 changes: 14 additions & 0 deletions packages/backend/src/graphql/resolvers/asset.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApolloError, gql } from '@apollo/client'
import assert from 'assert'
import { v4 as uuid } from 'uuid'
import { faker } from '@faker-js/faker'

import { getPageTests } from './page.test'
import { createTestApp, TestContainer } from '../../tests/app'
Expand Down Expand Up @@ -32,6 +33,8 @@ import { isFeeError } from '../../fee/errors'
import { createFee } from '../../tests/fee'
import { createAsset } from '../../tests/asset'
import { GraphQLErrorCode } from '../errors'
import { createTenant } from '../../tests/tenant'
import { EndpointType } from '../../tenant/endpoints/model'

describe('Asset Resolvers', (): void => {
let deps: IocContract<AppServices>
Expand All @@ -48,6 +51,17 @@ describe('Asset Resolvers', (): void => {
feeService = await deps.use('feeService')
})

beforeEach(async (): Promise<void> => {
await createTenant(deps, {
email: Config.kratosAdminEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
})

afterEach(async (): Promise<void> => {
await truncateTables(appContainer.knex)
})
Expand Down
14 changes: 13 additions & 1 deletion packages/backend/src/graphql/resolvers/auto-peering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import { createAsset } from '../../tests/asset'
import { CreateOrUpdatePeerByUrlInput } from '../generated/graphql'
import { AutoPeeringService } from '../../payment-method/ilp/auto-peering/service'
import { v4 as uuid } from 'uuid'
import nock from 'nock'
import { GraphQLErrorCode } from '../errors'
import { createTenant } from '../../tests/tenant'
import { EndpointType } from '../../tenant/endpoints/model'

const nock = (global as unknown as { nock: typeof import('nock') }).nock

describe('Auto Peering Resolvers', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -90,6 +93,15 @@ describe('Auto Peering Resolvers', (): void => {

beforeEach(async (): Promise<void> => {
asset = await createAsset(deps)
const config = await deps.use('config')
await createTenant(deps, {
email: config.kratosAdminEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
})

afterEach(async (): Promise<void> => {
Expand Down
67 changes: 54 additions & 13 deletions packages/backend/src/graphql/resolvers/combined_payments.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IocContract } from '@adonisjs/fold'
import { gql } from '@apollo/client'
import { faker } from '@faker-js/faker'
import { AppServices } from '../../app'
import { createTestApp, TestContainer } from '../../tests/app'
import { initIocContainer } from '../..'
Expand All @@ -18,11 +19,16 @@ import {
} from '../../tests/combinedPayment'
import { PaymentType } from '../../open_payments/payment/combined/model'
import { getPageTests } from './page.test'
import { createTenant } from '../../tests/tenant'
import { EndpointType } from '../../tenant/endpoints/model'

const nock = (global as unknown as { nock: typeof import('nock') }).nock

describe('Payment', (): void => {
let deps: IocContract<AppServices>
let appContainer: TestContainer
let asset: Asset
let tenantId: string

beforeAll(async (): Promise<void> => {
deps = initIocContainer(Config)
Expand All @@ -31,6 +37,21 @@ describe('Payment', (): void => {

beforeEach(async (): Promise<void> => {
asset = await createAsset(deps)
nock(Config.kratosAdminUrl)
.get('/identities')
.query({ credentials_identifier: Config.kratosAdminEmail })
.reply(200, [{ id: uuid(), metadata_public: {} }])
.persist()
tenantId = (
await createTenant(deps, {
email: Config.kratosAdminEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
).id
})

afterEach(async (): Promise<void> => {
Expand All @@ -44,18 +65,23 @@ describe('Payment', (): void => {

getPageTests({
getClient: () => appContainer.apolloClient,
createModel: () => createCombinedPayment(deps),
createModel: () => createCombinedPayment(deps, tenantId),
pagedQuery: 'payments'
})

test('Can get payments', async (): Promise<void> => {
const { id: outWalletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})
const { id: outWalletAddressId } = await createWalletAddress(
deps,
tenantId,
{
assetId: asset.id
}
)

const client = 'client-test'
const outgoingPayment = await createOutgoingPayment(deps, {
walletAddressId: outWalletAddressId,
tenantId,
client: client,
method: 'ilp',
receiver: `${Config.openPaymentsUrl}/${uuid()}`,
Expand All @@ -67,11 +93,16 @@ describe('Payment', (): void => {
validDestination: false
})

const { id: inWalletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})
const { id: inWalletAddressId } = await createWalletAddress(
deps,
tenantId,
{
assetId: asset.id
}
)
const incomingPayment = await createIncomingPayment(deps, {
walletAddressId: inWalletAddressId,
tenantId,
client: client
})

Expand Down Expand Up @@ -145,9 +176,13 @@ describe('Payment', (): void => {
})

test('Can filter payments by type and wallet address', async (): Promise<void> => {
const { id: outWalletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})
const { id: outWalletAddressId } = await createWalletAddress(
deps,
tenantId,
{
assetId: asset.id
}
)

const baseOutgoingPayment = {
receiver: `${Config.openPaymentsUrl}/${uuid()}`,
Expand All @@ -162,16 +197,22 @@ describe('Payment', (): void => {
const client = 'client-test-type-wallet-address'
const outgoingPayment = await createOutgoingPayment(deps, {
walletAddressId: outWalletAddressId,
tenantId,
client: client,
method: 'ilp',
...baseOutgoingPayment
})

const { id: outWalletAddressId2 } = await createWalletAddress(deps, {
assetId: asset.id
})
const { id: outWalletAddressId2 } = await createWalletAddress(
deps,
tenantId,
{
assetId: asset.id
}
)
await createOutgoingPayment(deps, {
walletAddressId: outWalletAddressId2,
tenantId,
client: client,
method: 'ilp',
...baseOutgoingPayment
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/graphql/resolvers/fee.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IocContract } from '@adonisjs/fold'
import { faker } from '@faker-js/faker'
import { AppServices } from '../../app'
import { initIocContainer } from '../..'
import { Config } from '../../config/app'
Expand All @@ -13,6 +14,8 @@ import { FeeService } from '../../fee/service'
import { v4 } from 'uuid'
import { FeeError, errorToMessage, errorToCode } from '../../fee/errors'
import { GraphQLErrorCode } from '../errors'
import { createTenant } from '../../tests/tenant'
import { EndpointType } from '../../tenant/endpoints/model'

describe('Fee Resolvers', () => {
let deps: IocContract<AppServices>
Expand All @@ -28,6 +31,15 @@ describe('Fee Resolvers', () => {

beforeEach(async (): Promise<void> => {
asset = await createAsset(deps)
const config = await deps.use('config')
await createTenant(deps, {
email: config.kratosAdminEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
})

afterEach(async () => {
Expand Down
Loading

0 comments on commit 83342a9

Please sign in to comment.