forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add invoice pdf download on purchase lists #1022
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3aeb075
feat: add invoice pdf download on purchase lists
tomrndom 202cea9
fix: adjust aria labels, actions params
tomrndom 2af4f37
fix: adjust test mocks and fileMock directory
tomrndom c8f9285
fix: add normalize function on API order response before generate inv…
tomrndom 6c9d1eb
fix: update uicore version
tomrndom db013e2
fix: update uicore version
tomrndom 5e29991
fix: unify download action in redux, add catches and tests, guard dow…
tomrndom 5641d86
fix: split download pdf fucntion, rollback params, add tests, disable…
tomrndom b9d6248
fix: unify expand for order details, adjust params on sponsor purchas…
tomrndom 868090d
fix: update react-pdf/renderer version
tomrndom 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
115 changes: 115 additions & 0 deletions
115
src/actions/__tests__/sponsor-purchases-actions.test.js
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,115 @@ | ||
| /** | ||
| * Copyright 2024 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import configureStore from "redux-mock-store"; | ||
| import thunk from "redux-thunk"; | ||
| import flushPromises from "flush-promises"; | ||
| import { | ||
| getRequest, | ||
| snackbarErrorMsg | ||
| } from "openstack-uicore-foundation/lib/utils/actions"; | ||
| import { generateInvoicePDF } from "openstack-uicore-foundation/lib/components/order-invoice-pdf"; | ||
| import { downloadSponsorInvoice } from "../sponsor-purchases-actions"; | ||
| import * as methods from "../../utils/methods"; | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({ | ||
| __esModule: true, | ||
| ...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"), | ||
| getRequest: jest.fn(), | ||
| snackbarErrorMsg: jest.fn((payload) => ({ | ||
| type: "SNACKBAR_ERROR_MSG_MOCK", | ||
| payload | ||
| })) | ||
| })); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/order-invoice-pdf", | ||
| () => ({ | ||
| generateInvoicePDF: jest.fn(() => Promise.resolve()) | ||
| }) | ||
| ); | ||
|
|
||
| describe("downloadSponsorInvoice", () => { | ||
| const middlewares = [thunk]; | ||
| const mockStore = configureStore(middlewares); | ||
| let capturedUrl; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| capturedUrl = null; | ||
| window.PURCHASES_API_URL = "https://purchases.example.com"; | ||
| jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| delete window.PURCHASES_API_URL; | ||
| }); | ||
|
|
||
| const buildStore = () => | ||
| mockStore({ | ||
| currentSummitState: { currentSummit: { id: 1 } }, | ||
| currentSponsorState: { entity: { id: 123 } } | ||
| }); | ||
|
|
||
| it("fetches the order for the explicit sponsorId, generates the PDF with the raw order and currentSummit, and never touches the shared order-detail state", async () => { | ||
| const fetchedOrder = { id: 7, forms: [] }; | ||
| getRequest.mockImplementation((reqAC, recAC, url) => { | ||
| capturedUrl = url; | ||
| return () => () => Promise.resolve({ response: fetchedOrder }); | ||
| }); | ||
|
|
||
| const store = buildStore(); | ||
| await store.dispatch(downloadSponsorInvoice(7, 456)); | ||
| await flushPromises(); | ||
|
|
||
| expect(capturedUrl).toBe( | ||
| `${window.PURCHASES_API_URL}/api/v2/summits/1/sponsors/456/purchases/7` | ||
| ); | ||
| expect(generateInvoicePDF).toHaveBeenCalledWith( | ||
| fetchedOrder, | ||
| { id: 1 }, | ||
| expect.objectContaining({ logoSrc: expect.anything() }) | ||
| ); | ||
| expect(snackbarErrorMsg).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("swallows the order-fetch rejection silently since authErrorHandler already surfaced it", async () => { | ||
| getRequest.mockImplementation( | ||
| () => () => () => Promise.reject(new Error("Network error")) | ||
| ); | ||
|
|
||
| const store = buildStore(); | ||
| await store.dispatch(downloadSponsorInvoice(7, 456)); | ||
| await flushPromises(); | ||
|
|
||
| expect(generateInvoicePDF).not.toHaveBeenCalled(); | ||
| // No second, stacked error UI on top of authErrorHandler's own message. | ||
| expect(snackbarErrorMsg).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("shows an error message when PDF generation rejects", async () => { | ||
| getRequest.mockImplementation( | ||
| () => () => () => Promise.resolve({ response: { id: 7, forms: [] } }) | ||
| ); | ||
| generateInvoicePDF.mockRejectedValueOnce(new Error("PDF error")); | ||
|
|
||
| const store = buildStore(); | ||
| await store.dispatch(downloadSponsorInvoice(7, 456)); | ||
| await flushPromises(); | ||
|
|
||
| expect(snackbarErrorMsg).toHaveBeenCalledWith( | ||
| expect.objectContaining({ html: "errors.invoice_generation" }) | ||
| ); | ||
| }); | ||
| }); |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.