Skip to content

Commit

Permalink
feat: make body, interact_ref optional on client grant continue (#436)
Browse files Browse the repository at this point in the history
* feat: make body, interact_ref optional on client grant continue

* chore: changeset
  • Loading branch information
BlairCurrey authored Mar 14, 2024
1 parent 2e318b0 commit b3a5d3b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-eagles-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@interledger/open-payments': patch
---

Makes body and interact_ref optional on continuation route
70 changes: 54 additions & 16 deletions packages/open-payments/src/client/grant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,68 @@ describe('grant', (): void => {
})

describe('continue', () => {
test('calls post method with correct validator', async (): Promise<void> => {
describe('calls post method with correct validator', (): void => {
const mockResponseValidator = ({ path, method }) =>
path === '/continue/{id}' && method === HttpMethod.POST

jest
.spyOn(openApi, 'createResponseValidator')
.mockImplementation(mockResponseValidator as any)
test('with interact_ref', async (): Promise<void> => {
jest
.spyOn(openApi, 'createResponseValidator')
.mockImplementation(mockResponseValidator as any)

const postSpy = jest.spyOn(requestors, 'post')
const interact_ref = uuid()

await createGrantRoutes({ openApi, client, ...deps }).continue(
{
url,
accessToken
},
{ interact_ref }
)

expect(postSpy).toHaveBeenCalledWith(
deps,
{ url, accessToken, body: { interact_ref } },
true
)
})
test('without interact_ref', async (): Promise<void> => {
jest
.spyOn(openApi, 'createResponseValidator')
.mockImplementation(mockResponseValidator as any)

const postSpy = jest.spyOn(requestors, 'post')
const body = {}

await createGrantRoutes({ openApi, client, ...deps }).continue(
{
url,
accessToken
},
body
)

expect(postSpy).toHaveBeenCalledWith(
deps,
{ url, accessToken, body },
true
)
})
test('without body', async (): Promise<void> => {
jest
.spyOn(openApi, 'createResponseValidator')
.mockImplementation(mockResponseValidator as any)

const postSpy = jest.spyOn(requestors, 'post')
const interact_ref = uuid()
const postSpy = jest.spyOn(requestors, 'post')

await createGrantRoutes({ openApi, client, ...deps }).continue(
{
await createGrantRoutes({ openApi, client, ...deps }).continue({
url,
accessToken
},
{ interact_ref }
)
})

expect(postSpy).toHaveBeenCalledWith(
deps,
{ url, accessToken, body: { interact_ref } },
true
)
expect(postSpy).toHaveBeenCalledWith(deps, { url, accessToken }, true)
})
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/open-payments/src/client/grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface GrantRoutes {
): Promise<PendingGrant | Grant>
continue(
postArgs: GrantOrTokenRequestArgs,
args: GrantContinuationRequest
args?: GrantContinuationRequest
): Promise<Grant | GrantContinuation>
cancel(postArgs: GrantOrTokenRequestArgs): Promise<void>
}
Expand Down
2 changes: 1 addition & 1 deletion packages/open-payments/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type GrantRequest = {
interact?: ASOperations['post-request']['requestBody']['content']['application/json']['interact']
}
export type GrantContinuationRequest = {
interact_ref: ASOperations['post-continue']['requestBody']['content']['application/json']['interact_ref']
interact_ref?: ASOperations['post-continue']['requestBody']['content']['application/json']['interact_ref']
}
export type PendingGrant = {
interact: ASComponents['schemas']['interact-response']
Expand Down

0 comments on commit b3a5d3b

Please sign in to comment.