From cf50262ee2982dcfc6c0f479f31a48f259719497 Mon Sep 17 00:00:00 2001 From: golobitch Date: Mon, 5 Aug 2024 22:58:44 +0200 Subject: [PATCH] test(outgoing-payment): check if grantId is returned --- .../resolvers/outgoing_payment.test.ts | 62 ++++++++++++++++--- packages/backend/src/tests/outgoingPayment.ts | 2 +- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts index 53d7d9bb48..71c51affcc 100644 --- a/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts +++ b/packages/backend/src/graphql/resolvers/outgoing_payment.test.ts @@ -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 { @@ -61,11 +64,14 @@ describe('OutgoingPayment Resolvers', (): void => { await appContainer.shutdown() }) - const createPayment = async (options: { - walletAddressId: string - metadata?: Record - }): Promise => { - return await createOutgoingPayment(deps, { + const createPayment = async ( + options: { + walletAddressId: string + metadata?: Record + }, + grantId?: string + ): Promise => { + const obj: CreateTestQuoteAndOutgoingPaymentOptions = { ...options, method: 'ilp', receiver: `${Config.openPaymentsUrl}/${uuid()}`, @@ -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 => { + 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', diff --git a/packages/backend/src/tests/outgoingPayment.ts b/packages/backend/src/tests/outgoingPayment.ts index 13d756653d..f28b38e694 100644 --- a/packages/backend/src/tests/outgoingPayment.ts +++ b/packages/backend/src/tests/outgoingPayment.ts @@ -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' >