Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(open-payments): add list incoming payments #851

Merged
merged 7 commits into from
Jan 9, 2023
Merged

Conversation

raducristianpopa
Copy link
Member

@raducristianpopa raducristianpopa commented Dec 15, 2022

Changes proposed in this pull request

  • add list incoming payments to OP Client

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass

Comment on lines +390 to +394
describe('backward pagination', (): void => {
test.each`
last | cursor
${undefined} | ${uuid()}
${5} | ${uuid()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is setup correctly, but in general makes me confused about the backward pagination parameters.

If we only provide a cursor, like (backwards-pagination allows) then by default we will end up forwards paginating, based on this code in the backend:

export function parsePaginationQueryParameters({
first,
last,
cursor
}: PageQueryParams): Pagination {
return {
first,
last,
before: last ? cursor : undefined,
after: cursor && !last ? cursor : undefined
}
}

would this mean that we should make last required as well in Open Payments API? Only cursor is required:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mkurapov mkurapov Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favour of not supporting both parameters (for now) to make the Open Payments pagination type simple & similar to what you describe in comment:

after + count || before + count || count (default forward pagination)


for (const incomingPayment of incomingPayments.result) {
try {
validateIncomingPayment(incomingPayment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For list responses, we could validate that pagination.hasPreviousPage is false if cursor was not specified (which should be forward pagination from the start).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly agree, but I'm not sure it's worth failing the whole request over it, however.

mkurapov
mkurapov previously approved these changes Dec 15, 2022
@@ -74,6 +77,21 @@ describe('incoming-payment', (): void => {
method: HttpMethod.POST
})
})

test('creates listIncomingPaymentsOpenApiValidator', async (): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raducristianpopa can we try testing that the list route calls the proper validator, similar to this test? https://github.com/interledger/rafiki/pull/848/files#diff-4f318c2a374cc145f8825fecf95d77b29a728927b5a64ce393897b01becb2b93R37-R38

If it takes too long, I'm going to approve the PR anyway so we can merge it later and working on these route tests at a separate time


for (const incomingPayment of incomingPayments.result) {
try {
validateIncomingPayment(incomingPayment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly agree, but I'm not sure it's worth failing the whole request over it, however.

wilsonianb
wilsonianb previously approved these changes Dec 16, 2022
return {
// https://jestjs.io/docs/jest-object#jestmockmodulename-factory-options
__esModule: true,
...jest.requireActual('./requests')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can mock out the get here, so we don't need to .mockResolvedValueOnce(incomingPaymentPaginationResult) on the getSpy below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we can remove __esModule: true, because we aren't using a default export

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can mock out the get here, so we don't need to .mockResolvedValueOnce(incomingPaymentPaginationResult) on the getSpy below

If we mock the get, all the tests that are using it will fail:

Test Suites: 1 failed, 1 total
Tests:       8 failed, 26 passed, 34 total

image


I also think we can remove __esModule: true, because we aren't using a default export

When __esModule: true is not specified, we get the following error:

incoming-payment › routes › list › calls get method with correct validator

    Error when making Open Payments GET request: Nock: No match for request {
      "method": "GET",
      "url": "http://localhost:1000/.well-known/pay/incoming-payments",
      "headers": {
        "accept": "application/json, text/plain, */*",
        "content-type": "application/json",
        "authorization": "GNAP accessToken",
        "signature": "sig1=:VYmcFqf6cSzLN10+dG/TnXQI23FxWY/n2/wVbNW4oX+U4rCBHpbT75AaMZOe3qzoUDiQUxZg0fpXjSBxHkNpDw==:",
        "signature-input": "sig1=(\"@method\" \"@target-uri\" \"authorization\");created=1671199508;keyid=\"default-key-id\";alg=\"ed25519\"",
        "user-agent": "axios/1.1.2",
        "accept-encoding": "gzip, deflate, br"
      }
    }

mkurapov
mkurapov previously approved these changes Dec 20, 2022
Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can merge in once the conflict is resolved

@mkurapov mkurapov merged commit 6192d20 into main Jan 9, 2023
@mkurapov mkurapov deleted the radup--816 branch January 9, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(open-payments): list incoming payments
3 participants