Repository navigation
feat(core): expose card approval and setup link helpers [SAP-4058] #1251
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
Open
ynadge
wants to merge
1
commit into
card-allowances
Choose a base branch
from
card-approval-controls
base: card-allowances
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
| import { SapiomClient } from "./SapiomClient"; | ||
| import type { | ||
| CardPurchaseApprovalSettings, | ||
| CreateCardSetupLinkInput, | ||
| } from "../types/payment-card"; | ||
|
|
||
| describe("Saved-card purchase approval through the public SDK", () => { | ||
| const cardId = "11111111-1111-4111-8111-111111111111"; | ||
| const originalFetch = global.fetch; | ||
| let fetchMock: jest.Mock; | ||
| let client: SapiomClient; | ||
| beforeEach(() => { | ||
| fetchMock = jest.fn(); | ||
| global.fetch = fetchMock; | ||
| client = new SapiomClient({ | ||
| apiKey: "fixture-management-key", | ||
| baseURL: "https://api.test", | ||
| backgroundRefresh: false, | ||
| }); | ||
| }); | ||
| afterEach(() => { | ||
| global.fetch = originalFetch; | ||
| }); | ||
| const json = (body: unknown, status = 200) => | ||
| new Response(JSON.stringify(body), { | ||
| status, | ||
| headers: { "content-type": "application/json" }, | ||
| }); | ||
|
|
||
| it("reads and updates the saved setting, retaining its concurrency version", async () => { | ||
| fetchMock.mockResolvedValueOnce(json({ enabled: false, version: 0 })); | ||
| expect(await client.paymentCards.getPurchaseApproval(cardId)).toEqual({ | ||
| enabled: false, | ||
| version: 0, | ||
| }); | ||
| const setting: CardPurchaseApprovalSettings = { enabled: true, version: 0 }; | ||
| fetchMock.mockResolvedValueOnce(json({ enabled: true, version: 1 })); | ||
| expect( | ||
| await client.paymentCards.setPurchaseApproval(cardId, setting), | ||
| ).toEqual({ enabled: true, version: 1 }); | ||
| const [url, request] = fetchMock.mock.calls[1]; | ||
| expect(String(url)).toBe( | ||
| `https://api.test/v1/payment-cards/${cardId}/purchase-approval`, | ||
| ); | ||
| expect(request.method).toBe("PUT"); | ||
| expect(JSON.parse(request.body)).toEqual(setting); | ||
| expect(request.headers["x-api-key"]).toBe("fixture-management-key"); | ||
| }); | ||
|
|
||
| it("passes the bounded approval grant to hosted setup and retrieves the resulting card", async () => { | ||
| const input: CreateCardSetupLinkInput = { | ||
| returnUrl: "https://buyer.example/cards", | ||
| purchaseApproval: { enabled: false, allowChanges: true }, | ||
| }; | ||
| fetchMock.mockResolvedValueOnce( | ||
| json({ | ||
| id: "link", | ||
| status: "open", | ||
| url: "https://app.test/add-card#private-code", | ||
| purchaseApproval: input.purchaseApproval, | ||
| }), | ||
| ); | ||
| const link = await client.paymentCards.createSetupLink(input); | ||
| expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual(input); | ||
| fetchMock.mockResolvedValueOnce( | ||
| json({ | ||
| id: "link", | ||
| status: "completed", | ||
| cardId, | ||
| purchaseApproval: { enabled: true, allowChanges: false }, | ||
| }), | ||
| ); | ||
| expect((await client.paymentCards.getSetupLink(link.id)).cardId).toBe( | ||
| cardId, | ||
| ); | ||
| expect(String(fetchMock.mock.calls[1][0])).toBe( | ||
| "https://api.test/v1/payment-cards/setup-links/link", | ||
| ); | ||
| }); | ||
|
|
||
| it("surfaces conflicts without retrying a policy overwrite", async () => { | ||
| fetchMock.mockResolvedValue(json({ code: "RULE_VERSION_CONFLICT" }, 409)); | ||
| await expect( | ||
| client.paymentCards.setPurchaseApproval(cardId, { | ||
| enabled: false, | ||
| version: 1, | ||
| }), | ||
| ).rejects.toThrow(/409.*RULE_VERSION_CONFLICT/); | ||
| expect(fetchMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Card approval release note omitted
When
paymentCardsgains these methods, no new Changeset records their release note. The pending core Changeset covers spending limits only, so the generated release omits the new helpers.Learn more
Published packages use Changesets to generate their version updates and release notes. The existing core Changeset predates this feature and describes only spending-limit management. This PR adds public card approval and setup-link methods but adds no corresponding Changeset, so the generated release note does not describe them.
Example: When the pending core Changeset produces the next minor release, its generated entry mentions spending limits but not
getPurchaseApprovalorcreateSetupLink.Recommended fix: Add a Changeset for
@sapiom/coredescribing the new methods and backend rollout requirement; keep the manual unreleased changelog entry only if that is also part of the project's release process.Was this helpful? React with 👍 or 👎 to provide feedback.