Skip to content

Commit

Permalink
feat(outgoing-payment): add grantId to admin api (#2841)
Browse files Browse the repository at this point in the history
* feat(backend): support for returning grantId when querying outgoing payment

When querying outgoing payment, either single one, or list of them via pagination, etc., it will be
possible to also get a grantId under which the outgoing

* test(outgoing-payment): check if grantId is returned

* docs(bruno): include grantId when fetching outgoing payment
  • Loading branch information
golobitch authored Aug 7, 2024
1 parent 969301c commit aac63c7
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ body:graphql {
error
metadata
id
grantId
walletAddressId
quote {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ body:graphql {
error
metadata
id
grantId
walletAddressId
client
quote {
Expand Down
3 changes: 3 additions & 0 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions packages/backend/src/graphql/generated/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/backend/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
3 changes: 2 additions & 1 deletion packages/backend/src/graphql/resolvers/outgoing_payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export function paymentToGraphql(
receiveAmount: payment.receiveAmount,
metadata: payment.metadata,
createdAt: new Date(+payment.createdAt).toISOString(),
quote: quoteToGraphql(payment.quote)
quote: quoteToGraphql(payment.quote),
grantId: payment.grantId
}
}
2 changes: 2 additions & 0 deletions packages/backend/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ type OutgoingPayment implements BasePayment & Model {
sentAmount: Amount!
"Date-time of creation"
createdAt: String!
"Id of the Grant under which this outgoing payment was created"
grantId: String
}

enum OutgoingPaymentState {
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
3 changes: 3 additions & 0 deletions packages/frontend/app/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/mock-account-service-lib/src/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/integration/lib/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aac63c7

Please sign in to comment.