Skip to content

Commit

Permalink
add test to service updateIncomingPayment and resolve observations
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaOneOut36 committed Aug 30, 2024
1 parent a34edb0 commit 1392629
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 44 deletions.
11 changes: 3 additions & 8 deletions bruno/collections/Rafiki/bruno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
"version": "1",
"name": "Rafiki",
"type": "collection",
"ignore": [
"node_modules",
".git"
],
"ignore": ["node_modules", ".git"],
"scripts": {
"moduleWhitelist": [
"crypto"
]
"moduleWhitelist": ["crypto"]
}
}
}
64 changes: 29 additions & 35 deletions packages/backend/src/graphql/resolvers/incoming_payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe('Incoming Payment Resolver', (): void => {
let incomingPaymentService: IncomingPaymentService
let accountingService: AccountingService
let asset: Asset
let incomingPayment: IncomingPaymentResponse

beforeAll(async (): Promise<void> => {
deps = await initIocContainer(Config)
Expand Down Expand Up @@ -444,8 +443,7 @@ describe('Incoming Payment Resolver', (): void => {

describe('Mutation.updateIncomingPayment', (): void => {
let amount: Amount
let expiresAt:Date
let id = 'ok'
let expiresAt: Date

beforeEach((): void => {
amount = {
Expand All @@ -456,38 +454,36 @@ describe('Incoming Payment Resolver', (): void => {
expiresAt = new Date(Date.now() + 30_000)
client = 'incoming-payment-client-update'
})


test.each`
id | metadata
${id} | ${{ description: 'Update metadata', status: 'COMPLETE' }}
${id} | ${{}}
metadata
${{ description: 'Update metadata', status: 'COMPLETE' }}
${{}}
`(
'Successfully updates an incoming payment with $id | $metadata',
async ({id, metadata}): Promise<void> => {

const incomingAmount = amount ? amount : undefined
const { id: walletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})
const payment = await createIncomingPayment(deps, {
walletAddressId,
client,
metadata,
expiresAt,
incomingAmount
})
'Successfully updates an incoming payment with $metadata',
async ({ metadata }): Promise<void> => {
const incomingAmount = amount ? amount : undefined
const { id: walletAddressId } = await createWalletAddress(deps, {
assetId: asset.id
})
const payment = await createIncomingPayment(deps, {
walletAddressId,
client,
metadata,
expiresAt,
incomingAmount
})
const input = {
id:payment.id,
id: payment.id,
metadata
}
const paymentUpdated = await updateIncomingPayment(deps,input)


const createSpy = jest
.spyOn(incomingPaymentService, 'update')
.mockResolvedValueOnce(paymentUpdated)

.mockResolvedValueOnce({
...payment,
metadata: input.metadata
} as IncomingPaymentModel)

const query = await appContainer.apolloClient
.query({
Expand All @@ -502,7 +498,7 @@ describe('Incoming Payment Resolver', (): void => {
}
}
}
`,
`,
variables: { input }
})
.then(
Expand Down Expand Up @@ -537,10 +533,10 @@ describe('Incoming Payment Resolver', (): void => {
await appContainer.apolloClient
.query({
query: gql`
mutation UpdateIncomingPayment(
$input: UpdateIncomingPaymentInput!) {
updateIncomingPayment(input: $input
) {
mutation UpdateIncomingPayment(
$input: UpdateIncomingPaymentInput!
) {
updateIncomingPayment(input: $input) {
payment {
id
metadata
Expand Down Expand Up @@ -568,7 +564,6 @@ describe('Incoming Payment Resolver', (): void => {
expect(createSpy).toHaveBeenCalledWith(input)
})


test('Internal server error', async (): Promise<void> => {
const createSpy = jest
.spyOn(incomingPaymentService, 'update')
Expand All @@ -584,9 +579,9 @@ describe('Incoming Payment Resolver', (): void => {
await appContainer.apolloClient
.query({
query: gql`
mutation UpdateIncomingPayment(
mutation UpdateIncomingPayment(
$input: UpdateIncomingPaymentInput!
) {
) {
updateIncomingPayment(input: $input) {
payment {
id
Expand Down Expand Up @@ -615,5 +610,4 @@ describe('Incoming Payment Resolver', (): void => {
expect(createSpy).toHaveBeenCalledWith(input)
})
})

})
3 changes: 2 additions & 1 deletion packages/backend/src/open_payments/payment/incoming/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import base64url from 'base64url'
export enum IncomingPaymentEventType {
IncomingPaymentCreated = 'incoming_payment.created',
IncomingPaymentExpired = 'incoming_payment.expired',
IncomingPaymentCompleted = 'incoming_payment.completed'
IncomingPaymentCompleted = 'incoming_payment.completed',
IncomingPaymentUpdated = 'incoming_payment.updated'
}

export enum IncomingPaymentState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,63 @@ describe('Incoming Payment Service', (): void => {
).resolves.toBe(IncomingPaymentError.InvalidExpiry)
})
})
describe('Update IncomingPayment', (): void => {
let amount: Amount
let payment: IncomingPayment

beforeEach(async (): Promise<void> => {
amount = {
value: BigInt(123),
assetCode: asset.code,
assetScale: asset.scale
}
payment = (await incomingPaymentService.create({
walletAddressId,
incomingAmount: amount
})) as IncomingPayment
assert.ok(!isIncomingPaymentError(payment))
})

test.each`
metadata
${{ description: 'Update metadata', status: 'COMPLETE' }}
${{}}
`('An incoming payment can be updated', async (metadata): Promise<void> => {
await expect(
IncomingPaymentEvent.query(knex).where({
type: IncomingPaymentEventType.IncomingPaymentUpdated
})
).resolves.toHaveLength(0)


const incomingPayment = await incomingPaymentService.update({
id:payment.id,
metadata
})
assert.ok(!isIncomingPaymentError(incomingPayment))
expect(incomingPayment).toMatchObject({
id: incomingPayment.id,
metadata
})
await expect(
IncomingPaymentEvent.query(knex).where({
type: IncomingPaymentEventType.IncomingPaymentUpdated
})
).resolves.toHaveLength(0)
})

test('Cannot update incoming payment for nonexistent incomingPaymentId', async (): Promise<void> => {
await expect(
incomingPaymentService.update({
id: uuid(),
metadata: {
description: 'Test incoming payment',
externalRef: '#123'
}
})
).resolves.toBe(IncomingPaymentError.UnknownPayment)
})
})

describe('get/getWalletAddressPage', (): void => {
getTests({
Expand Down

0 comments on commit 1392629

Please sign in to comment.