Skip to content

Commit

Permalink
fix: combined payments tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Sep 11, 2024
1 parent 5077af0 commit 365734f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IocContract } from '@adonisjs/fold'
import { faker } from '@faker-js/faker'
import { v4 as uuid } from 'uuid'
import { AppServices } from '../../../app'
import { TestContainer, createTestApp } from '../../../tests/app'
import { initIocContainer } from '../../..'
Expand All @@ -21,6 +23,10 @@ import {
createCombinedPayment,
toCombinedPayment
} from '../../../tests/combinedPayment'
import { createTenant } from '../../../tests/tenant'
import { EndpointType } from '../../../tenant/endpoints/model'

const nock = (global as unknown as { nock: typeof import('nock') }).nock

describe('Combined Payment Service', (): void => {
let deps: IocContract<AppServices>
Expand All @@ -42,10 +48,27 @@ describe('Combined Payment Service', (): void => {
beforeEach(async (): Promise<void> => {
sendAsset = await createAsset(deps)
receiveAsset = await createAsset(deps)
const config = await deps.use('config')
const tenantEmail = faker.internet.email()
nock(config.kratosAdminUrl)
.get('/identities')
.query({ credentials_identifier: tenantEmail })
.reply(200, [{ id: uuid(), metadata_public: {} }])
.persist()
const tenantId = (
await createTenant(deps, {
email: tenantEmail,
idpSecret: 'testsecret',
idpConsentEndpoint: faker.internet.url(),
endpoints: [
{ type: EndpointType.WebhookBaseUrl, value: faker.internet.url() }
]
})
).id
sendWalletAddressId = (
await createWalletAddress(deps, { assetId: sendAsset.id })
await createWalletAddress(deps, tenantId, { assetId: sendAsset.id })
).id
receiveWalletAddress = await createWalletAddress(deps, {
receiveWalletAddress = await createWalletAddress(deps, tenantId, {
assetId: receiveAsset.id
})
})
Expand All @@ -60,12 +83,14 @@ describe('Combined Payment Service', (): void => {

async function setupPayments(deps: IocContract<AppServices>) {
const incomingPayment = await createIncomingPayment(deps, {
walletAddressId: receiveWalletAddress.id
walletAddressId: receiveWalletAddress.id,
tenantId: receiveWalletAddress.tenantId
})
const receiverUrl = incomingPayment.getUrl(receiveWalletAddress)

const outgoingPayment = await createOutgoingPayment(deps, {
walletAddressId: sendWalletAddressId,
tenantId: receiveWalletAddress.tenantId,
method: 'ilp',
receiver: receiverUrl,
debitAmount: {
Expand All @@ -84,7 +109,8 @@ describe('Combined Payment Service', (): void => {

describe('CombinedPayment Service', (): void => {
getPageTests({
createModel: () => createCombinedPayment(deps),
createModel: () =>
createCombinedPayment(deps, receiveWalletAddress.tenantId),
getPage: (pagination?: Pagination, sortOrder?: SortOrder) =>
combinedPaymentService.getPage({ pagination, sortOrder })
})
Expand Down
11 changes: 7 additions & 4 deletions packages/backend/src/tests/combinedPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,28 @@ export function toCombinedPayment(
* @returns A CombinedPayment object that represents the created payment.
*/
export async function createCombinedPayment(
deps: IocContract<AppServices>
deps: IocContract<AppServices>,
tenantId: string
): Promise<CombinedPayment> {
const sendAsset = await createAsset(deps)
const receiveAsset = await createAsset(deps)
const sendWalletAddressId = (
await createWalletAddress(deps, { assetId: sendAsset.id })
await createWalletAddress(deps, tenantId, { assetId: sendAsset.id })
).id
const receiveWalletAddress = await createWalletAddress(deps, {
const receiveWalletAddress = await createWalletAddress(deps, tenantId, {
assetId: receiveAsset.id
})

const type = Math.random() < 0.5 ? PaymentType.Incoming : PaymentType.Outgoing
const payment =
type === PaymentType.Incoming
? await createIncomingPayment(deps, {
walletAddressId: receiveWalletAddress.id
walletAddressId: receiveWalletAddress.id,
tenantId: receiveWalletAddress.tenantId
})
: await createOutgoingPayment(deps, {
walletAddressId: sendWalletAddressId,
tenantId,
method: 'ilp',
receiver: `${Config.openPaymentsUrl}/${uuid()}`,
validDestination: false
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 @@ -136,7 +136,7 @@ export async function createOutgoingPaymentWithReceiver(
walletAddressId: args.sendingWalletAddress.id,
method: args.method,
receiver: receiver.incomingPayment!.id!,
tenantId: args.sendingWalletAddress.tenantId,
tenantId: args.receivingWalletAddress.tenantId,
...args.quoteOptions
})

Expand Down

0 comments on commit 365734f

Please sign in to comment.