Skip to content

Commit

Permalink
fix: assets, shared service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Sep 16, 2024
1 parent bcb4204 commit 9f6bb0d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
22 changes: 22 additions & 0 deletions packages/backend/src/asset/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { WalletAddressService } from '../open_payments/wallet_address/service'
import { isWalletAddressError } from '../open_payments/wallet_address/errors'
import { PeerService } from '../payment-method/ilp/peer/service'
import { isPeerError } from '../payment-method/ilp/peer/errors'
import { createTenant } from '../tests/tenant'
import { EndpointType } from '../tenant/endpoints/model'

describe('Asset Service', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -271,9 +273,29 @@ describe('Asset Service', (): void => {
assert.ok(!isAssetError(newAsset))
const newAssetId = newAsset.id

const nock = (global as unknown as { nock: typeof import('nock') }).nock
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

// make sure there is at least 1 wallet address using asset
const walletAddress = walletAddressService.create({
url: 'https://alice.me/.well-known/pay',
tenantId,
assetId: newAssetId
})
assert.ok(!isWalletAddressError(walletAddress))
Expand Down
49 changes: 45 additions & 4 deletions packages/backend/src/shared/pagination.test.ts
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 { createTestApp, TestContainer } from '../tests/app'
import { Amount } from '../open_payments/amount'
Expand All @@ -18,6 +20,10 @@ import { getPageInfo, parsePaginationQueryParameters } from './pagination'
import { AssetService } from '../asset/service'
import { PeerService } from '../payment-method/ilp/peer/service'
import { createPeer } from '../tests/peer'
import { createTenant } from '../tests/tenant'
import { EndpointType } from '../tenant/endpoints/model'

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

describe('Pagination', (): void => {
let deps: IocContract<AppServices>
Expand Down Expand Up @@ -46,7 +52,23 @@ describe('Pagination', (): void => {

beforeEach(async (): Promise<void> => {
const asset = await createAsset(deps)
walletAddress = await createWalletAddress(deps, {
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
walletAddress = await createWalletAddress(deps, tenantId, {
assetId: asset.id
})
})
Expand Down Expand Up @@ -83,10 +105,26 @@ describe('Pagination', (): void => {
quoteService = await deps.use('quoteService')

const asset = await createAsset(deps)
defaultWalletAddress = await createWalletAddress(deps, {
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
defaultWalletAddress = await createWalletAddress(deps, tenantId, {
assetId: asset.id
})
secondaryWalletAddress = await createWalletAddress(deps, {
secondaryWalletAddress = await createWalletAddress(deps, tenantId, {
assetId: asset.id
})
debitAmount = {
Expand Down Expand Up @@ -118,7 +156,8 @@ describe('Pagination', (): void => {
const paymentIds: string[] = []
for (let i = 0; i < num; i++) {
const payment = await createIncomingPayment(deps, {
walletAddressId: defaultWalletAddress.id
walletAddressId: defaultWalletAddress.id,
tenantId: defaultWalletAddress.tenantId
})
paymentIds.push(payment.id)
}
Expand Down Expand Up @@ -172,6 +211,7 @@ describe('Pagination', (): void => {
for (let i = 0; i < num; i++) {
const payment = await createOutgoingPayment(deps, {
walletAddressId: defaultWalletAddress.id,
tenantId: defaultWalletAddress.tenantId,
receiver: secondaryWalletAddress.url,
method: 'ilp',
debitAmount,
Expand Down Expand Up @@ -229,6 +269,7 @@ describe('Pagination', (): void => {
for (let i = 0; i < num; i++) {
const quote = await createQuote(deps, {
walletAddressId: defaultWalletAddress.id,
tenantId: defaultWalletAddress.tenantId,
receiver: secondaryWalletAddress.url,
debitAmount,
validDestination: false,
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { isValidHttpUrl, poll, requestWithTimeout, sleep } from './utils'
import { AppServices, AppContext } from '../app'
import { TestContainer, createTestApp } from '../tests/app'
import { initIocContainer } from '..'
import { verifyApiSignature } from './utils'
import { generateApiSignature } from '../tests/apiSignature'
import { verifyApiSignature, generateApiSignature } from './utils'
import { Config } from '../config/app'
import { createContext } from '../tests/context'

Expand Down

0 comments on commit 9f6bb0d

Please sign in to comment.