Skip to content

Commit

Permalink
test(outgoing-payment): check if grantId is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
golobitch committed Aug 6, 2024
1 parent adc680e commit 90c1ca5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
62 changes: 55 additions & 7 deletions packages/backend/src/graphql/resolvers/outgoing_payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { AppServices } from '../../app'
import { initIocContainer } from '../..'
import { Config } from '../../config/app'
import { createAsset } from '../../tests/asset'
import { createOutgoingPayment } from '../../tests/outgoingPayment'
import {
createOutgoingPayment,
CreateTestQuoteAndOutgoingPaymentOptions
} from '../../tests/outgoingPayment'
import { createWalletAddress } from '../../tests/walletAddress'
import { truncateTables } from '../../tests/tableManager'
import {
Expand Down Expand Up @@ -61,11 +64,14 @@ describe('OutgoingPayment Resolvers', (): void => {
await appContainer.shutdown()
})

const createPayment = async (options: {
walletAddressId: string
metadata?: Record<string, unknown>
}): Promise<OutgoingPaymentModel> => {
return await createOutgoingPayment(deps, {
const createPayment = async (
options: {
walletAddressId: string
metadata?: Record<string, unknown>
},
grantId?: string
): Promise<OutgoingPaymentModel> => {
const obj: CreateTestQuoteAndOutgoingPaymentOptions = {
...options,
method: 'ilp',
receiver: `${Config.openPaymentsUrl}/${uuid()}`,
Expand All @@ -75,12 +81,54 @@ describe('OutgoingPayment Resolvers', (): void => {
assetScale: asset.scale
},
validDestination: false
})
}

if (grantId) {
obj.grant = { id: grantId }
}

return await createOutgoingPayment(deps, obj)
}

describe('Query.outgoingPayment', (): void => {
let payment: OutgoingPaymentModel

describe('grantId', (): void => {
it('should return grantId', async (): Promise<void> => {
const grantId = uuid()

const { id: walletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})

const payment = await createPayment({ walletAddressId }, grantId)

const query = await appContainer.apolloClient
.query({
query: gql`
query OutgoingPayment($paymentId: String!) {
outgoingPayment(id: $paymentId) {
id
grantId
walletAddressId
}
}
`,
variables: {
paymentId: payment.id
}
})
.then((query): OutgoingPayment => query.data?.outgoingPayment)

expect(query).toEqual({
id: payment.id,
grantId: payment.grantId,
walletAddressId: payment.walletAddressId,
__typename: 'OutgoingPayment'
})
})
})

describe('metadata', (): void => {
const metadata = {
description: 'rent',
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/tests/outgoingPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IncomingPayment } from '../open_payments/payment/incoming/model'
import { createIncomingPayment } from './incomingPayment'
import assert from 'assert'

type CreateTestQuoteAndOutgoingPaymentOptions = Omit<
export type CreateTestQuoteAndOutgoingPaymentOptions = Omit<
CreateOutgoingPaymentOptions & CreateTestQuoteOptions,
'quoteId'
>
Expand Down

0 comments on commit 90c1ca5

Please sign in to comment.