-
Notifications
You must be signed in to change notification settings - Fork 4
fix: use denormalize function for modules for sponsor managed pages #940
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { normalizeSponsorManagedPageToCustomize } from "../sponsor-pages-actions"; | ||
| import { | ||
| PAGE_MODULES_DOWNLOAD, | ||
| PAGES_MODULE_KINDS | ||
| } from "../../utils/constants"; | ||
|
|
||
| jest.mock("moment-timezone", () => { | ||
| const mockMoment = { unix: jest.fn(() => 1700000000) }; | ||
| const moment = jest.fn(() => mockMoment); | ||
| moment.tz = jest.fn(() => mockMoment); | ||
| moment.utc = jest.fn(() => mockMoment); | ||
| return moment; | ||
| }); | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({ | ||
| createAction: jest.fn(), | ||
| getRequest: jest.fn(), | ||
| postRequest: jest.fn(), | ||
| putRequest: jest.fn(), | ||
| deleteRequest: jest.fn(), | ||
| startLoading: jest.fn(), | ||
| stopLoading: jest.fn(), | ||
| escapeFilterValue: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/security/actions", () => ({ | ||
| LOGOUT_USER: "LOGOUT_USER" | ||
| })); | ||
|
|
||
| jest.mock("../../utils/methods", () => ({ | ||
| getAccessTokenSafely: jest.fn(), | ||
| normalizeSelectAllField: jest.fn(() => ({ | ||
| apply_to_all_add_ons: false, | ||
| allowed_add_ons: [] | ||
| })) | ||
| })); | ||
|
|
||
| jest.mock("i18n-react/dist/i18n-react", () => ({ | ||
| __esModule: true, | ||
| default: { translate: (key) => key } | ||
| })); | ||
|
|
||
| const buildEntity = (modules = []) => ({ | ||
| id: 10, | ||
| code: "P1", | ||
| allowed_add_ons: [], | ||
| page_ptr_id: 99, | ||
| sponsorship_types: [1], | ||
| summit_id: 5, | ||
| template_id: 3, | ||
| modules_count: 2, | ||
| modules | ||
| }); | ||
|
|
||
| describe("normalizeSponsorManagedPageToCustomize", () => { | ||
| describe("DOCUMENT module — FILE type", () => { | ||
| it("includes the file when it is new (no id or file_id)", () => { | ||
| const newFile = { name: "contract.pdf" }; | ||
| const entity = buildEntity([ | ||
| { | ||
| kind: PAGES_MODULE_KINDS.DOCUMENT, | ||
| type: PAGE_MODULES_DOWNLOAD.FILE, | ||
| file: [newFile] | ||
| } | ||
| ]); | ||
|
|
||
| const result = normalizeSponsorManagedPageToCustomize(entity); | ||
|
|
||
| expect(result.modules[0].file).toEqual(newFile); | ||
| }); | ||
|
|
||
| it("omits the file when it already exists (id present) — isNewFile guard", () => { | ||
| const existingFile = { id: 42, name: "brief.pdf", file_id: 7 }; | ||
| const entity = buildEntity([ | ||
| { | ||
| kind: PAGES_MODULE_KINDS.DOCUMENT, | ||
| type: PAGE_MODULES_DOWNLOAD.FILE, | ||
| file: [existingFile] | ||
| } | ||
| ]); | ||
|
|
||
| const result = normalizeSponsorManagedPageToCustomize(entity); | ||
|
|
||
| expect(result.modules[0].file).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("DOCUMENT module — URL type", () => { | ||
| it("omits file and file_id from the payload", () => { | ||
| const entity = buildEntity([ | ||
| { | ||
| kind: PAGES_MODULE_KINDS.DOCUMENT, | ||
| type: PAGE_MODULES_DOWNLOAD.URL, | ||
| file: [{ id: 5 }], | ||
| file_id: 5, | ||
| external_url: "https://example.com" | ||
| } | ||
| ]); | ||
|
|
||
| const result = normalizeSponsorManagedPageToCustomize(entity); | ||
|
|
||
| expect(result.modules[0].file).toBeUndefined(); | ||
| expect(result.modules[0].file_id).toBeUndefined(); | ||
| expect(result.modules[0].external_url).toBe("https://example.com"); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| * */ | ||
|
|
||
| import { LOGOUT_USER } from "openstack-uicore-foundation/lib/security/actions"; | ||
| import { epochToMomentTimeZone } from "openstack-uicore-foundation/lib/utils/methods"; | ||
| import { | ||
| REQUEST_SPONSOR_MANAGED_PAGES, | ||
| RECEIVE_SPONSOR_MANAGED_PAGES, | ||
|
|
@@ -28,10 +27,8 @@ import { | |
| SET_CURRENT_SUMMIT, | ||
| RECEIVE_SUMMIT_SPONSORSHIP_TYPES | ||
| } from "../../actions/summit-actions"; | ||
| import { | ||
| PAGE_MODULES_DOWNLOAD, | ||
| PAGES_MODULE_KINDS | ||
| } from "../../utils/constants"; | ||
| import { PAGES_MODULE_KINDS } from "../../utils/constants"; | ||
| import { denormalizePageModules } from "../../utils/page-template"; | ||
|
|
||
| const DEFAULT_PAGE = { | ||
| code: "", | ||
|
|
@@ -182,54 +179,20 @@ const sponsorPagePagesListReducer = (state = DEFAULT_STATE, action) => { | |
| case RECEIVE_SPONSOR_MANAGED_PAGE: { | ||
| const editPage = payload.response; | ||
|
|
||
| const currentEditPage = { | ||
| ...editPage, | ||
| modules: editPage.modules.map((m) => ({ | ||
| ...m, | ||
| ...(m.upload_deadline | ||
| ? { | ||
| upload_deadline: epochToMomentTimeZone( | ||
| m.upload_deadline, | ||
| state.summitTZ || "UTC" | ||
| ) | ||
| } | ||
| : {}) | ||
| })) | ||
| }; | ||
| return { ...state, currentEditPage }; | ||
| const modules = denormalizePageModules( | ||
| editPage.modules, | ||
| state.summitTZ || "UTC" | ||
| ); | ||
|
|
||
| return { ...state, currentEditPage: { ...editPage, modules } }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing regression tests for this new delegation to Suggested test cases in
|
||
| } | ||
| case RECEIVE_SPONSOR_CUSTOMIZED_PAGE: { | ||
| const customizedPage = payload.response; | ||
|
|
||
| const modules = customizedPage.modules.map((module) => { | ||
| const tmpModule = { | ||
| ...module, | ||
| ...(module.upload_deadline | ||
| ? { | ||
| upload_deadline: epochToMomentTimeZone( | ||
| module.upload_deadline, | ||
| state.summitTZ || "UTC" | ||
| ) | ||
| } | ||
| : {}) | ||
| }; | ||
|
|
||
| if (module.kind === PAGES_MODULE_KINDS.DOCUMENT) { | ||
| if (module.file) { | ||
| tmpModule.file = [ | ||
| { | ||
| ...module.file, | ||
| file_path: module.file.storage_key, | ||
| public_url: module.file.file_url | ||
| } | ||
| ]; | ||
| tmpModule.type = PAGE_MODULES_DOWNLOAD.FILE; | ||
| } else { | ||
| tmpModule.type = PAGE_MODULES_DOWNLOAD.URL; | ||
| } | ||
| } | ||
| return tmpModule; | ||
| }); | ||
| const modules = denormalizePageModules( | ||
| customizedPage.modules, | ||
| state.summitTZ || "UTC" | ||
| ); | ||
|
|
||
| return { ...state, currentEditPage: { ...customizedPage, modules } }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing regression test for this new delegation to Suggested test case in
|
||
| } | ||
|
|
||
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.
normalizePageTemplateModulesis now shared with the customized-page flow. The old inline code sent every file unconditionally; this shared helper only sends a file if it lacks anid/file_id(the isNewFile guard) — a silent behavioral change for the managed-page PUT path.Missing regression tests for
normalizeSponsorManagedPageToCustomizeinsrc/actions/__tests__/:id/file_id) → verify file is included in the PUT payloadidpresent) → verify file is NOT included in the PUT payload (isNewFile guard fires)