diff --git a/packages/backend/src/open_payments/payment/combined/service.test.ts b/packages/backend/src/open_payments/payment/combined/service.test.ts index fddb5efd43..158704f506 100644 --- a/packages/backend/src/open_payments/payment/combined/service.test.ts +++ b/packages/backend/src/open_payments/payment/combined/service.test.ts @@ -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 '../../..' @@ -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 @@ -42,10 +48,27 @@ describe('Combined Payment Service', (): void => { beforeEach(async (): Promise => { 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 }) }) @@ -60,12 +83,14 @@ describe('Combined Payment Service', (): void => { async function setupPayments(deps: IocContract) { 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: { @@ -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 }) }) diff --git a/packages/backend/src/tests/combinedPayment.ts b/packages/backend/src/tests/combinedPayment.ts index 504aceeb97..f9386a2e27 100644 --- a/packages/backend/src/tests/combinedPayment.ts +++ b/packages/backend/src/tests/combinedPayment.ts @@ -35,14 +35,15 @@ export function toCombinedPayment( * @returns A CombinedPayment object that represents the created payment. */ export async function createCombinedPayment( - deps: IocContract + deps: IocContract, + tenantId: string ): Promise { 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 }) @@ -50,10 +51,12 @@ export async function createCombinedPayment( 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 diff --git a/packages/backend/src/tests/outgoingPayment.ts b/packages/backend/src/tests/outgoingPayment.ts index bde9acabb1..e54abfadd0 100644 --- a/packages/backend/src/tests/outgoingPayment.ts +++ b/packages/backend/src/tests/outgoingPayment.ts @@ -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 })