Skip to content

Commit

Permalink
fix(backend): do not import (nonexistent) test code (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb authored and omertoast committed Oct 28, 2022
1 parent 512244e commit d095f7b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@koa/cors": "^3.1.0",
"@koa/router": "^12.0.0",
"@poppinss/file-generator": "^1.0.2",
"@shopify/jest-koa-mocks": "^5.0.1",
"@types/bcrypt": "^5.0.0",
"add": "^2.0.6",
"ajv": "^8.11.0",
Expand Down
38 changes: 16 additions & 22 deletions packages/backend/src/open_payments/client/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Counter, ResolvedPayment } from '@interledger/pay'
import { createMockContext } from '@shopify/jest-koa-mocks'
import axios, { AxiosRequestHeaders, AxiosResponse } from 'axios'
import base64url from 'base64url'
import { OpenAPI, HttpMethod, ValidateFunction } from 'openapi'
Expand All @@ -13,10 +14,6 @@ import { PaymentPointerService } from '../payment_pointer/service'
import { ReadContext } from '../../app'
import { AssetOptions } from '../../asset/service'
import { BaseService } from '../../shared/baseService'
// TODO: move out of *.tests
import { setup } from '../../shared/routes.test'
// TODO: move out of /tests
import { createContext } from '../../tests/context'

const REQUEST_TIMEOUT = 5_000 // millseconds

Expand Down Expand Up @@ -179,22 +176,25 @@ async function getResource({
})
}

const createReadContext = (params: { id: string }): ReadContext =>
createMockContext({
headers: { Accept: 'application/json' },
method: 'GET',
customProperties: {
params
}
}) as ReadContext

async function getConnection(
deps: ServiceDependencies,
url: string
): Promise<ConnectionJSON | undefined> {
try {
// Check if this is a local incoming payment connection
if (url.startsWith(`${deps.openPaymentsUrl}/connections/`)) {
const ctx = createContext<ReadContext>(
{
headers: { Accept: 'application/json' },
method: 'GET'
},
{
id: url.slice(-36)
}
)
const ctx = createReadContext({
id: url.slice(-36)
})
await deps.connectionRoutes.get(ctx)
return ctx.body as ConnectionJSON
}
Expand Down Expand Up @@ -232,16 +232,10 @@ async function getIncomingPayment(
match.paymentPointerUrl
)
if (paymentPointer) {
const ctx = setup<ReadContext>({
reqOpts: {
headers: { Accept: 'application/json' },
method: 'GET'
},
params: {
id: match.id
},
paymentPointer
const ctx = createReadContext({
id: match.id
})
ctx.paymentPointer = paymentPointer
await deps.incomingPaymentRoutes.get(ctx)
return ctx.body as IncomingPaymentJSON
}
Expand Down
42 changes: 33 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d095f7b

Please sign in to comment.