Skip to content

Commit

Permalink
feat(backend): add method to quote create paths
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Oct 20, 2023
1 parent 8396970 commit 6f3e16e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 39 deletions.
6 changes: 4 additions & 2 deletions packages/backend/src/graphql/resolvers/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Quote Resolvers', (): void => {
assetCode: asset.code,
assetScale: asset.scale
},
method: 'ilp',
validDestination: false
})
}
Expand Down Expand Up @@ -217,7 +218,8 @@ describe('Quote Resolvers', (): void => {
})
.then((query): QuoteResponse => query.data?.createQuote)

expect(createSpy).toHaveBeenCalledWith(input)
console.log(createSpy.mock.calls[0])
expect(createSpy).toHaveBeenCalledWith({ ...input, method: 'ilp' })
expect(query.code).toBe('200')
expect(query.success).toBe(true)
expect(query.quote?.id).toBe(quote?.id)
Expand Down Expand Up @@ -271,7 +273,7 @@ describe('Quote Resolvers', (): void => {
variables: { input }
})
.then((query): QuoteResponse => query.data?.createQuote)
expect(createSpy).toHaveBeenCalledWith(input)
expect(createSpy).toHaveBeenCalledWith({ ...input, method: 'ilp' })
expect(query.code).toBe('500')
expect(query.success).toBe(false)
expect(query.message).toBe('Error trying to create quote')
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/graphql/resolvers/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const createQuote: MutationResolvers<ApolloContext>['createQuote'] =
const quoteService = await ctx.container.use('quoteService')
const options: CreateQuoteOptions = {
walletAddressId: args.input.walletAddressId,
receiver: args.input.receiver
receiver: args.input.receiver,
method: 'ilp'
}
if (args.input.debitAmount) options.debitAmount = args.input.debitAmount
if (args.input.receiveAmount)
Expand Down
54 changes: 36 additions & 18 deletions packages/backend/src/open_payments/payment/outgoing/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ describe('OutgoingPaymentService', (): void => {
const quote = await createQuote(deps, {
walletAddressId,
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
const options = {
walletAddressId,
Expand Down Expand Up @@ -400,7 +401,8 @@ describe('OutgoingPaymentService', (): void => {
walletAddressId,
receiver,
debitAmount,
validDestination: false
validDestination: false,
method: 'ilp'
})
await expect(
outgoingPaymentService.create({
Expand Down Expand Up @@ -438,7 +440,8 @@ describe('OutgoingPaymentService', (): void => {
walletAddressId,
receiver,
debitAmount,
validDestination: false
validDestination: false,
method: 'ilp'
})
await expect(
outgoingPaymentService.create({
Expand All @@ -453,7 +456,8 @@ describe('OutgoingPaymentService', (): void => {
walletAddressId,
receiver,
debitAmount,
validDestination: false
validDestination: false,
method: 'ilp'
})
await quote.$query(knex).patch({
expiresAt: new Date()
Expand All @@ -475,7 +479,8 @@ describe('OutgoingPaymentService', (): void => {
const quote = await createQuote(deps, {
walletAddressId,
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
await incomingPayment.$query(knex).patch({
state,
Expand All @@ -496,7 +501,8 @@ describe('OutgoingPaymentService', (): void => {
walletAddressId,
receiver,
debitAmount,
validDestination: false
validDestination: false,
method: 'ilp'
})
const walletAddress = await createWalletAddress(deps)
const walletAddressUpdated = await WalletAddress.query(
Expand All @@ -523,7 +529,8 @@ describe('OutgoingPaymentService', (): void => {
return await createQuote(deps, {
walletAddressId,
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
})
)
Expand Down Expand Up @@ -571,7 +578,8 @@ describe('OutgoingPaymentService', (): void => {
quote = await createQuote(deps, {
walletAddressId,
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
options = {
walletAddressId,
Expand Down Expand Up @@ -831,7 +839,8 @@ describe('OutgoingPaymentService', (): void => {
const paymentId = await setup({
receiver,
debitAmount,
receiveAmount
receiveAmount,
method: 'ilp'
})

const payment = await processNext(
Expand Down Expand Up @@ -860,7 +869,8 @@ describe('OutgoingPaymentService', (): void => {
assert.ok(incomingPayment.walletAddress)
const paymentId = await setup({
receiver: incomingPayment.getUrl(incomingPayment.walletAddress),
receiveAmount
receiveAmount,
method: 'ilp'
})

const payment = await processNext(
Expand All @@ -881,7 +891,8 @@ describe('OutgoingPaymentService', (): void => {
const paymentId = await setup(
{
receiver,
receiveAmount
receiveAmount,
method: 'ilp'
},
receiveAmount
)
Expand Down Expand Up @@ -924,7 +935,8 @@ describe('OutgoingPaymentService', (): void => {

const paymentId = await setup({
receiver,
debitAmount
debitAmount,
method: 'ilp'
})

for (let i = 0; i < 4; i++) {
Expand Down Expand Up @@ -966,7 +978,8 @@ describe('OutgoingPaymentService', (): void => {
)
const paymentId = await setup({
receiver,
debitAmount
debitAmount,
method: 'ilp'
})

const payment = await processNext(
Expand All @@ -992,7 +1005,8 @@ describe('OutgoingPaymentService', (): void => {
)
const paymentId = await setup({
receiver,
receiveAmount
receiveAmount,
method: 'ilp'
})

const payment = await processNext(paymentId, OutgoingPaymentState.Sending)
Expand Down Expand Up @@ -1022,7 +1036,8 @@ describe('OutgoingPaymentService', (): void => {
const paymentId = await setup(
{
receiver,
receiveAmount
receiveAmount,
method: 'ilp'
},
receiveAmount
)
Expand All @@ -1048,7 +1063,8 @@ describe('OutgoingPaymentService', (): void => {
const paymentId = await setup(
{
receiver,
receiveAmount
receiveAmount,
method: 'ilp'
},
receiveAmount
)
Expand All @@ -1071,7 +1087,8 @@ describe('OutgoingPaymentService', (): void => {
it('FAILED (source asset changed)', async (): Promise<void> => {
const paymentId = await setup({
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
const { id: assetId } = await createAsset(deps, {
code: asset.code,
Expand All @@ -1091,7 +1108,8 @@ describe('OutgoingPaymentService', (): void => {
it('FAILED (destination asset changed)', async (): Promise<void> => {
const paymentId = await setup({
receiver,
debitAmount
debitAmount,
method: 'ilp'
})
// Pretend that the destination asset was initially different.
await OutgoingPayment.relatedQuery('quote')
Expand Down
16 changes: 11 additions & 5 deletions packages/backend/src/open_payments/quote/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Quote Routes', (): void => {
assetCode: asset.code,
assetScale: asset.scale
},
method: 'ilp',
client,
validDestination: false
})
Expand Down Expand Up @@ -137,7 +138,8 @@ describe('Quote Routes', (): void => {
...debitAmount,
value: debitAmount.value.toString(),
assetScale: debitAmount.assetScale + 1
}
},
method: 'ilp'
}
const ctx = setup({})
await expect(quoteRoutes.create(ctx)).rejects.toMatchObject({
Expand Down Expand Up @@ -170,7 +172,8 @@ describe('Quote Routes', (): void => {
'$description',
async ({ debitAmount, receiveAmount }): Promise<void> => {
options = {
receiver
receiver,
method: 'ilp'
}
if (debitAmount)
options.debitAmount = {
Expand Down Expand Up @@ -208,7 +211,8 @@ describe('Quote Routes', (): void => {
...options.receiveAmount,
value: BigInt(options.receiveAmount.value)
},
client
client,
method: 'ilp'
})
expect(ctx.response).toSatisfyApiSpec()
const quoteId = (
Expand Down Expand Up @@ -238,7 +242,8 @@ describe('Quote Routes', (): void => {

test('receiver.incomingAmount', async (): Promise<void> => {
options = {
receiver
receiver,
method: 'ilp'
}
const ctx = setup({ client })
let quote: Quote | undefined
Expand All @@ -256,7 +261,8 @@ describe('Quote Routes', (): void => {
expect(quoteSpy).toHaveBeenCalledWith({
walletAddressId: walletAddress.id,
receiver,
client
client,
method: 'ilp'
})
expect(ctx.response).toSatisfyApiSpec()
const quoteId = (
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/open_payments/quote/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async function getQuote(

interface CreateBodyBase {
receiver: string
method: 'ilp'
}

interface CreateBodyWithDebitAmount extends CreateBodyBase {
Expand All @@ -68,7 +69,8 @@ async function createQuote(
const options: CreateQuoteOptions = {
walletAddressId: ctx.walletAddress.id,
receiver: body.receiver,
client: ctx.client
client: ctx.client,
method: body.method
}
if (body.debitAmount) options.debitAmount = parseAmount(body.debitAmount)
if (body.receiveAmount)
Expand Down
27 changes: 18 additions & 9 deletions packages/backend/src/open_payments/quote/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ describe('QuoteService', (): void => {
},
client,
validDestination: false,
withFee: true
withFee: true,
method: 'ilp'
}),
get: (options) => quoteService.get(options),
list: (options) => quoteService.getWalletAddressPage(options)
Expand Down Expand Up @@ -148,7 +149,8 @@ describe('QuoteService', (): void => {
})
options = {
walletAddressId: sendingWalletAddress.id,
receiver: incomingPayment.getUrl(receivingWalletAddress)
receiver: incomingPayment.getUrl(receivingWalletAddress),
method: 'ilp'
}
if (debitAmount) options.debitAmount = debitAmount
if (receiveAmount) options.receiveAmount = receiveAmount
Expand Down Expand Up @@ -342,7 +344,8 @@ describe('QuoteService', (): void => {
const options: CreateQuoteOptions = {
walletAddressId: sendingWalletAddress.id,
receiver: incomingPayment.getUrl(receivingWalletAddress),
receiveAmount
receiveAmount,
method: 'ilp'
}

const mockedQuote = mockQuote({
Expand Down Expand Up @@ -383,7 +386,8 @@ describe('QuoteService', (): void => {
quoteService.create({
walletAddressId: uuid(),
receiver: `${receivingWalletAddress.url}/incoming-payments/${uuid()}`,
debitAmount
debitAmount,
method: 'ilp'
})
).resolves.toEqual(QuoteError.UnknownWalletAddress)
})
Expand All @@ -398,7 +402,8 @@ describe('QuoteService', (): void => {
quoteService.create({
walletAddressId: walletAddress.id,
receiver: `${receivingWalletAddress.url}/incoming-payments/${uuid()}`,
debitAmount
debitAmount,
method: 'ilp'
})
).resolves.toEqual(QuoteError.InactiveWalletAddress)
})
Expand All @@ -408,7 +413,8 @@ describe('QuoteService', (): void => {
quoteService.create({
walletAddressId: sendingWalletAddress.id,
receiver: `${receivingWalletAddress.url}/incoming-payments/${uuid()}`,
debitAmount
debitAmount,
method: 'ilp'
})
).resolves.toEqual(QuoteError.InvalidReceiver)
})
Expand All @@ -430,7 +436,8 @@ describe('QuoteService', (): void => {
})
const options: CreateQuoteOptions = {
walletAddressId: sendingWalletAddress.id,
receiver: incomingPayment.getUrl(receivingWalletAddress)
receiver: incomingPayment.getUrl(receivingWalletAddress),
method: 'ilp'
}
if (debitAmount) options.debitAmount = debitAmount
if (receiveAmount) options.receiveAmount = receiveAmount
Expand Down Expand Up @@ -499,7 +506,8 @@ describe('QuoteService', (): void => {

const quote = await quoteService.create({
walletAddressId: sendingWalletAddress.id,
receiver: receiver.incomingPayment!.id
receiver: receiver.incomingPayment!.id,
method: 'ilp'
})
assert.ok(!isQuoteError(quote))

Expand Down Expand Up @@ -576,7 +584,8 @@ describe('QuoteService', (): void => {
value: debitAmountValue,
assetCode: sendAsset.code,
assetScale: sendAsset.scale
}
},
method: 'ilp'
})
assert.ok(!isQuoteError(quote))

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/open_payments/quote/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function getQuote(
interface QuoteOptionsBase {
walletAddressId: string
receiver: string
method: 'ilp'
client?: string
}

Expand Down
Loading

0 comments on commit 6f3e16e

Please sign in to comment.