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

feat(outgoing-payment): add grantId to admin api #2841

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.

Loading