11import { IocContract } from '@adonisjs/fold'
2+ import { faker } from '@faker-js/faker'
3+ import { v4 as uuid } from 'uuid'
24import { AppServices } from '../../../app'
35import { TestContainer , createTestApp } from '../../../tests/app'
46import { initIocContainer } from '../../..'
@@ -21,6 +23,10 @@ import {
2123 createCombinedPayment ,
2224 toCombinedPayment
2325} from '../../../tests/combinedPayment'
26+ import { createTenant } from '../../../tests/tenant'
27+ import { EndpointType } from '../../../tenant/endpoints/model'
28+
29+ const nock = ( global as unknown as { nock : typeof import ( 'nock' ) } ) . nock
2430
2531describe ( 'Combined Payment Service' , ( ) : void => {
2632 let deps : IocContract < AppServices >
@@ -42,10 +48,27 @@ describe('Combined Payment Service', (): void => {
4248 beforeEach ( async ( ) : Promise < void > => {
4349 sendAsset = await createAsset ( deps )
4450 receiveAsset = await createAsset ( deps )
51+ const config = await deps . use ( 'config' )
52+ const tenantEmail = faker . internet . email ( )
53+ nock ( config . kratosAdminUrl )
54+ . get ( '/identities' )
55+ . query ( { credentials_identifier : tenantEmail } )
56+ . reply ( 200 , [ { id : uuid ( ) , metadata_public : { } } ] )
57+ . persist ( )
58+ const tenantId = (
59+ await createTenant ( deps , {
60+ email : tenantEmail ,
61+ idpSecret : 'testsecret' ,
62+ idpConsentEndpoint : faker . internet . url ( ) ,
63+ endpoints : [
64+ { type : EndpointType . WebhookBaseUrl , value : faker . internet . url ( ) }
65+ ]
66+ } )
67+ ) . id
4568 sendWalletAddressId = (
46- await createWalletAddress ( deps , { assetId : sendAsset . id } )
69+ await createWalletAddress ( deps , tenantId , { assetId : sendAsset . id } )
4770 ) . id
48- receiveWalletAddress = await createWalletAddress ( deps , {
71+ receiveWalletAddress = await createWalletAddress ( deps , tenantId , {
4972 assetId : receiveAsset . id
5073 } )
5174 } )
@@ -60,12 +83,14 @@ describe('Combined Payment Service', (): void => {
6083
6184 async function setupPayments ( deps : IocContract < AppServices > ) {
6285 const incomingPayment = await createIncomingPayment ( deps , {
63- walletAddressId : receiveWalletAddress . id
86+ walletAddressId : receiveWalletAddress . id ,
87+ tenantId : receiveWalletAddress . tenantId
6488 } )
6589 const receiverUrl = incomingPayment . getUrl ( receiveWalletAddress )
6690
6791 const outgoingPayment = await createOutgoingPayment ( deps , {
6892 walletAddressId : sendWalletAddressId ,
93+ tenantId : receiveWalletAddress . tenantId ,
6994 method : 'ilp' ,
7095 receiver : receiverUrl ,
7196 debitAmount : {
@@ -84,7 +109,8 @@ describe('Combined Payment Service', (): void => {
84109
85110 describe ( 'CombinedPayment Service' , ( ) : void => {
86111 getPageTests ( {
87- createModel : ( ) => createCombinedPayment ( deps ) ,
112+ createModel : ( ) =>
113+ createCombinedPayment ( deps , receiveWalletAddress . tenantId ) ,
88114 getPage : ( pagination ?: Pagination , sortOrder ?: SortOrder ) =>
89115 combinedPaymentService . getPage ( { pagination, sortOrder } )
90116 } )
0 commit comments