-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
662/mk/use open payments types (#1024)
* feat(open-payments): export the different IncomingPayment types * feat(backend): use open-payment types for IncomingPayment * feat(backend): use open-payment types for Connection * feat(backend): use open-payment types for OutgoingPayment * feat(backend): use open-payment types for Quote * chore(backend): fix IncomingPayments.toOpenPaymentsType * chore(open-payments): update mocks * chore(backend): formatting * chore(backend): add better typing for incomingPayment.toOpenPaymentsType * chore(backend): remove QuoteJSON * chore(open-payments): fix mocks * chore(backend): fix IncomingPayment types * chore(open-payments): fix incoming payment types * chore(backend): fix incoming payment method * chore(backend): make toOpenPaymentsType async * chore(backend): getUrl for OutgoingPayment * chore(backend): fix tests with async toOpenPaymentsType * chore(backend): return undefined instead of null * chore(backend): add awaits where necessary * chore(open-payments): make getBody async * chore(backend): fix outgoingPayment model method * chore(backend): fix list tests * chore(backend): update receiver tests * chore(backend): make toOpenPaymentType sync (#1056) * chore(backend): make toOpenPaymentType sync * chore(backend): make quote.toOpenPaymentsType sync * chore(backend): convert tests to sync * chore(backend): update tests * chore(backend): remove $formatJson where applicable * chore(backend): remove $formatJson where applicable * chore(backend): add test for incomingPayment model * chore(backend): fix incomingPayment model test * chore(open-payments): use suggestion * chore(backend): fix test * chore(backend): use suggestion
- Loading branch information
Showing
28 changed files
with
487 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
packages/backend/src/open_payments/payment/incoming/model.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { IocContract } from '@adonisjs/fold' | ||
import { createTestApp, TestContainer } from '../../../tests/app' | ||
import { Config, IAppConfig } from '../../../config/app' | ||
import { initIocContainer } from '../../..' | ||
import { AppServices } from '../../../app' | ||
import { createIncomingPayment } from '../../../tests/incomingPayment' | ||
import { createPaymentPointer } from '../../../tests/paymentPointer' | ||
import { truncateTables } from '../../../tests/tableManager' | ||
import { Connection } from '../../connection/model' | ||
import { serializeAmount } from '../../amount' | ||
import { IlpAddress } from 'ilp-packet' | ||
import { IncomingPayment } from './model' | ||
|
||
describe('Incoming Payment Model', (): void => { | ||
let deps: IocContract<AppServices> | ||
let appContainer: TestContainer | ||
let config: IAppConfig | ||
|
||
beforeAll(async (): Promise<void> => { | ||
deps = initIocContainer(Config) | ||
appContainer = await createTestApp(deps) | ||
config = await deps.use('config') | ||
}) | ||
|
||
afterEach(async (): Promise<void> => { | ||
jest.useRealTimers() | ||
await truncateTables(appContainer.knex) | ||
}) | ||
|
||
afterAll(async (): Promise<void> => { | ||
await appContainer.shutdown() | ||
}) | ||
|
||
describe('toOpenPaymentsType', () => { | ||
test('returns incoming payment without connection provided', async () => { | ||
const paymentPointer = await createPaymentPointer(deps) | ||
const incomingPayment = await createIncomingPayment(deps, { | ||
paymentPointerId: paymentPointer.id, | ||
description: 'my payment' | ||
}) | ||
|
||
expect(incomingPayment.toOpenPaymentsType(paymentPointer)).toEqual({ | ||
id: `${paymentPointer.url}${IncomingPayment.urlPath}/${incomingPayment.id}`, | ||
paymentPointer: paymentPointer.url, | ||
completed: incomingPayment.completed, | ||
receivedAmount: serializeAmount(incomingPayment.receivedAmount), | ||
incomingAmount: incomingPayment.incomingAmount | ||
? serializeAmount(incomingPayment.incomingAmount) | ||
: undefined, | ||
expiresAt: incomingPayment.expiresAt.toISOString(), | ||
description: incomingPayment.description ?? undefined, | ||
externalRef: incomingPayment.externalRef ?? undefined, | ||
updatedAt: incomingPayment.updatedAt.toISOString(), | ||
createdAt: incomingPayment.createdAt.toISOString() | ||
}) | ||
}) | ||
|
||
test('returns incoming payment with connection as string', async () => { | ||
const paymentPointer = await createPaymentPointer(deps) | ||
const incomingPayment = await createIncomingPayment(deps, { | ||
paymentPointerId: paymentPointer.id, | ||
description: 'my payment' | ||
}) | ||
|
||
const connection = `${config.openPaymentsUrl}/connections/${incomingPayment.connectionId}` | ||
|
||
expect( | ||
incomingPayment.toOpenPaymentsType(paymentPointer, connection) | ||
).toEqual({ | ||
id: `${paymentPointer.url}${IncomingPayment.urlPath}/${incomingPayment.id}`, | ||
paymentPointer: paymentPointer.url, | ||
completed: incomingPayment.completed, | ||
receivedAmount: serializeAmount(incomingPayment.receivedAmount), | ||
incomingAmount: incomingPayment.incomingAmount | ||
? serializeAmount(incomingPayment.incomingAmount) | ||
: undefined, | ||
expiresAt: incomingPayment.expiresAt.toISOString(), | ||
description: incomingPayment.description ?? undefined, | ||
externalRef: incomingPayment.externalRef ?? undefined, | ||
updatedAt: incomingPayment.updatedAt.toISOString(), | ||
createdAt: incomingPayment.createdAt.toISOString(), | ||
ilpStreamConnection: connection | ||
}) | ||
}) | ||
|
||
test('returns incoming payment with connection as object', async () => { | ||
const paymentPointer = await createPaymentPointer(deps) | ||
const incomingPayment = await createIncomingPayment(deps, { | ||
paymentPointerId: paymentPointer.id, | ||
description: 'my payment' | ||
}) | ||
|
||
const connection = Connection.fromPayment({ | ||
payment: incomingPayment, | ||
openPaymentsUrl: config.openPaymentsUrl, | ||
credentials: { | ||
ilpAddress: 'test.ilp' as IlpAddress, | ||
sharedSecret: Buffer.from('') | ||
} | ||
}) | ||
|
||
expect( | ||
incomingPayment.toOpenPaymentsType(paymentPointer, connection) | ||
).toEqual({ | ||
id: `${paymentPointer.url}${IncomingPayment.urlPath}/${incomingPayment.id}`, | ||
paymentPointer: paymentPointer.url, | ||
completed: incomingPayment.completed, | ||
receivedAmount: serializeAmount(incomingPayment.receivedAmount), | ||
incomingAmount: incomingPayment.incomingAmount | ||
? serializeAmount(incomingPayment.incomingAmount) | ||
: undefined, | ||
expiresAt: incomingPayment.expiresAt.toISOString(), | ||
description: incomingPayment.description ?? undefined, | ||
externalRef: incomingPayment.externalRef ?? undefined, | ||
updatedAt: incomingPayment.updatedAt.toISOString(), | ||
createdAt: incomingPayment.createdAt.toISOString(), | ||
ilpStreamConnection: { | ||
id: `${config.openPaymentsUrl}/connections/${incomingPayment.connectionId}`, | ||
ilpAddress: 'test.ilp', | ||
sharedSecret: expect.any(String), | ||
assetCode: incomingPayment.asset.code, | ||
assetScale: incomingPayment.asset.scale | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.