diff --git a/src/4.3_to_5.0/__test_resources__/addLegacyBookmarkToUIFolder.ts b/src/4.3_to_5.0/__test_resources__/addLegacyBookmarkToUIFolder.ts new file mode 100644 index 0000000..464db15 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/addLegacyBookmarkToUIFolder.ts @@ -0,0 +1,62 @@ +import { ContentRecord } from "@activeviam/activeui-sdk-5.1"; +import { produce } from "immer"; + +/** + * Returns a new `legacyUIFolder` with the given `legacyBookmarksToAdd` added. + * Useful for creating legacyUIFolders for tests. + * Does not mutate `legacyUIFolder`. + */ +export function addLegacyBookmarkToUIFolder( + legacyUIFolder: ContentRecord, + legacyBookmarksToAdd: { [id: string]: any }, +): ContentRecord { + const content = legacyUIFolder.children?.bookmarks.children?.content; + const structure = legacyUIFolder.children?.bookmarks.children?.structure; + + if (!content || !structure) { + throw new Error( + "Expected `legacyUIFolder` to contain the `content` and `structure` properties. Please ensure these properties exist", + ); + } + + return produce(legacyUIFolder, (draftFolder) => { + const existingBookmarks = + draftFolder.children!.bookmarks.children!.content!.children || {}; + + // Add the bookmark content + draftFolder.children!.bookmarks.children!.content!.children = { + ...existingBookmarks, + ...legacyBookmarksToAdd, + }; + + const keysOfBookmarksToAdd = Object.keys(legacyBookmarksToAdd); + + const bookmarkStructureToAdd = keysOfBookmarksToAdd.reduce( + (acc: { [key: string]: ContentRecord }, key: string) => { + const bookmarkEntry = legacyBookmarksToAdd[key].entry; + acc[key] = { + entry: { + isDirectory: true, + owners: bookmarkEntry.owners, + readers: bookmarkEntry.readers, + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }; + return acc; + }, + {}, + ); + + const existingStructure = + draftFolder.children!.bookmarks.children!.structure!.children || {}; + + // Add the bookmark structure + draftFolder.children!.bookmarks.children!.structure!.children = { + ...existingStructure, + ...bookmarkStructureToAdd, + }; + }); +} diff --git a/src/4.3_to_5.0/__test_resources__/emptyLegacyUIFolder.ts b/src/4.3_to_5.0/__test_resources__/emptyLegacyUIFolder.ts new file mode 100644 index 0000000..5243ecd --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/emptyLegacyUIFolder.ts @@ -0,0 +1,214 @@ +/** + * Contains an empty /ui folder of a Content Server, useful for injecting content to be used in unit tests. + */ +export const emptyLegacyUIFolder = { + entry: { + isDirectory: true, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879725132, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + bookmarks: { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + content: { + entry: { + isDirectory: true, + owners: ["ROLE_USER"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: {}, + }, + i18n: { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + "en-US": { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + "fr-FR": { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + }, + }, + structure: { + entry: { + isDirectory: true, + owners: ["ROLE_USER"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: {}, + }, + }, + }, + settings: { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + default: { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + preferences: { + entry: { + content: '{\n "allow": [],\n "deny": [],\n "map": {}\n}', + isDirectory: false, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + }, + }, + roles: { + entry: { + isDirectory: true, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + users: { + entry: { + isDirectory: true, + owners: ["ROLE_USER"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + user1: { + entry: { + isDirectory: true, + owners: ["user1"], + readers: ["user1"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + preferences: { + entry: { + content: + '{\n "map": {\n "defaultPermissions": {\n "owners": [\n "user2"\n ],\n "readers": [\n "user2"\n ]\n }\n }\n}', + isDirectory: false, + owners: ["user1"], + readers: ["user1"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + }, + }, + admin: { + entry: { + isDirectory: true, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + children: { + preferences: { + entry: { + content: + '{\n "map": {\n "tree.search.maxResults": 10,\n "global.theme": "dark-activeviam",\n "userFilters.enabled": true,\n "showLegacyCharts": true,\n "showLegacyMaps": true,\n "widgets.Tabular.drillthrough.selectedColumns": {\n "https://activepivot-ranch.activeviam.com:5900": {\n "EquityDerivativesCube": [\n {\n "functionName": "MemberValue",\n "columnName": "delta"\n },\n {\n "functionName": "Caption",\n "columnName": "delta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "gamma"\n },\n {\n "functionName": "Caption",\n "columnName": "gamma"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlVega"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlVega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Desk"\n },\n {\n "functionName": "Caption",\n "columnName": "Desk"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Currency"\n },\n {\n "functionName": "Caption",\n "columnName": "Currency"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Date"\n },\n {\n "functionName": "Caption",\n "columnName": "Date"\n },\n {\n "columnName": "HostName",\n "functionName": "MemberValue"\n },\n {\n "columnName": "HostName",\n "functionName": "Caption"\n }\n ],\n "EquityDerivativesCubeDist": [\n {\n "functionName": "MemberValue",\n "columnName": "BumpedMtmDown"\n },\n {\n "functionName": "Caption",\n "columnName": "BumpedMtmDown"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "vega"\n },\n {\n "functionName": "Caption",\n "columnName": "vega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "rho"\n },\n {\n "functionName": "Caption",\n "columnName": "rho"\n },\n {\n "functionName": "MemberValue",\n "columnName": "productId"\n },\n {\n "functionName": "Caption",\n "columnName": "productId"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlVega"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlVega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlDelta"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlDelta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnl"\n },\n {\n "functionName": "Caption",\n "columnName": "pnl"\n },\n {\n "functionName": "MemberValue",\n "columnName": "gamma"\n },\n {\n "functionName": "Caption",\n "columnName": "gamma"\n },\n {\n "functionName": "MemberValue",\n "columnName": "delta"\n },\n {\n "functionName": "Caption",\n "columnName": "delta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "TradeId"\n },\n {\n "functionName": "Caption",\n "columnName": "TradeId"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductBaseMtm"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductBaseMtm"\n },\n {\n "columnName": "ProductQtyMultiplier",\n "functionName": "MemberValue"\n },\n {\n "columnName": "ProductQtyMultiplier",\n "functionName": "Caption"\n }\n ]\n }\n },\n "defaultPermissions": {\n "owners": [\n "admin"\n ],\n "readers": [\n "admin"\n ]\n },\n "project.content-editor.configuration": {\n "autoSwitchToFieldsOnEmptyWidget": true,\n "advancedModeDropdownHidden": false,\n "hideFieldsControls": false,\n "mdx-common": {\n "regularModeTab": "filters",\n "advancedModeEnabled": false,\n "advancedModeTab": "mdx"\n }\n },\n "user.contextValues": {\n "EquityDerivativesCube": {},\n "EquityDerivativesCubeDist": {}\n },\n "user.filters": {\n "EquityDerivativesCube": ["[Geography].[City].[ALL].[AllMember].[Berlin]"],\n "EquityDerivativesCubeDist": []\n },\n "filtering.hierarchyToFilterType.[Geography].[City]": "explicit",\n "filtering.hierarchyToFilterType.[Currency].[Currency]": "explicit",\n "filtering.hierarchyToFilterType.[Trades].[Trades]": "topcount",\n "servers.alias": {\n "https://activepivot-ranch.activeviam.com:5900": "http://localhost:8080"\n }\n }\n}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + }, + }, + }, + }, + }, + }, + version: { + entry: { + content: '{"package":"4.3.8","contentServerApi":"0.1.0"}', + isDirectory: false, + owners: ["ROLE_CS_ROOT"], + readers: ["ROLE_USER"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, + }, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/invalidLegacyWidgets.ts b/src/4.3_to_5.0/__test_resources__/invalidLegacyWidgets.ts new file mode 100644 index 0000000..4bf8dc8 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/invalidLegacyWidgets.ts @@ -0,0 +1,37 @@ +const widgetWithInvalidContainerKey = { + entry: { + content: + '{"description":"Widget with invalid container key","name":"Invalid widget","type":"container","value":{"style":{},"showTitleBar":false,"containerKey":"invalid-container-key","body":{"serverUrl":"","mdx":"SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[City].[ALL].[AllMember].[New York] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{},"updateMode":"once","ranges":{}}}}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; + +const widgetWithFilterOnInvalidHierarchy = { + entry: { + content: + '{"description":"Widget with filter on invalid hierarchy","name":"Invalid widget","type":"container","value":{"style":{},"showTitleBar":false,"containerKey":"pivot-table","body":{"serverUrl":"","mdx":"SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[InvalidHierarchy].[ALL].[AllMember].[Member] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{},"updateMode":"once","ranges":{}}}}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; + +/** + * Contains two legacy bookmark widgets. + * 1. Widget with an invalid container container key. + * 2. Widget with a filter on an invalid hierarchy. + */ +export const invalidLegacyWidgets = { + "158": widgetWithInvalidContainerKey, + "1231": widgetWithFilterOnInvalidHierarchy, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyDashboardBookmark.ts b/src/4.3_to_5.0/__test_resources__/legacyDashboardBookmark.ts new file mode 100644 index 0000000..03d601d --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyDashboardBookmark.ts @@ -0,0 +1,16 @@ +/** + * Content entry representing a legacy dashboard containing a single pivot table. + * Useful for unit tests. + */ +export const legacyDashboardBookmark = { + entry: { + content: `{"name":"hidden grand totals","type":"container","value":{"style":{},"showTitleBar":false,"body":{"pages":[{"content":[{"key":"1","bookmark":{"name":"Untitled Pivot Table","type":"container","value":{"style":{},"showTitleBar":true,"body":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Geography].[City].[ALL].[AllMember])), Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{"mdx.hiddengrandtotals":"1"},"updateMode":"once","ranges":{"row":{"chunkSize":2000,"thresholdPercentage":0.1},"column":{"chunkSize":50,"thresholdPercentage":0.2}},"configuration":{"tabular":{"pinnedHeaderSelector":"member","sortingMode":"non-breaking","addButtonFilter":"numeric","cellRenderers":["tree-layout"],"statisticsShown":true,"columnsGroups":[{"captionProducer":"firstColumn","cellFactory":"kpi-status","selector":"kpi-status"},{"captionProducer":"firstColumn","cellFactory":"lookup","selector":"lookup"},{"captionProducer":"expiry","cellFactory":"expiry","selector":"kpi-expiry"},{"captionProducer":"columnMerge","cellFactory":{"args":{},"key":"treeCells"},"selector":"member"}],"hideAddButton":true,"defaultOptions":{},"expansion":{"automaticExpansion":true}}}},"containerKey":"pivot-table"},"writable":true}},{"key":"2","bookmark":{"name":"Untitled Chart","type":"container","value":{"style":{},"showTitleBar":true,"body":{"configuration":{"type":"plotly-line-chart","mapping":{"xAxis":["[Currency].[Currency].[Currency]"],"values":["[Measures].[pnl.FOREX]"],"splitBy":["[Booking].[Desk].[LegalEntity]"],"horizontalSubplots":[],"verticalSubplots":[]},"switchedTo":"plotly-clustered-column-chart"},"query":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Currency].[Currency])), Hierarchize(DrilldownLevel([Booking].[Desk].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[pnl.FOREX] ON COLUMNS FROM [EquityDerivativesCube]","contextValues":{},"updateMode":"once"}},"containerKey":"chart"},"writable":true}}],"layout":{"children":{"0":{"ck":"2"},"1":{"ck":"1"}},"direction":"row"},"name":"Page 1","filters":{"EquityDerivativesCube":[]}}]},"containerKey":"dashboard"}}`, + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyInvalidDashboardBookmark.ts b/src/4.3_to_5.0/__test_resources__/legacyInvalidDashboardBookmark.ts new file mode 100644 index 0000000..c7f1a92 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyInvalidDashboardBookmark.ts @@ -0,0 +1,17 @@ +/** + * The content entry representing a bookmark of an invalid dashboard. + * Useful for unit tests. + */ +export const legacyInvalidDashboardBookmark = { + entry: { + content: + '{"name":"hidden grand totals","type":"container","value":{"style":{},"showTitleBar":false,"body":{"pages":[{"content":[{"key":"1","bookmark":{"name":"Untitled Pivot Table","type":"container","value":{"style":{},"showTitleBar":true,"body":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Geography].[City].[ALL].[AllMember])), Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [foo] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{"mdx.hiddengrandtotals":"1"},"updateMode":"once","ranges":{"row":{"chunkSize":2000,"thresholdPercentage":0.1},"column":{"chunkSize":50,"thresholdPercentage":0.2}},"configuration":{"tabular":{"pinnedHeaderSelector":"member","sortingMode":"non-breaking","addButtonFilter":"numeric","cellRenderers":["tree-layout"],"statisticsShown":true,"columnsGroups":[{"captionProducer":"firstColumn","cellFactory":"kpi-status","selector":"kpi-status"},{"captionProducer":"firstColumn","cellFactory":"lookup","selector":"lookup"},{"captionProducer":"expiry","cellFactory":"expiry","selector":"kpi-expiry"},{"captionProducer":"columnMerge","cellFactory":{"args":{},"key":"treeCells"},"selector":"member"}],"hideAddButton":true,"defaultOptions":{},"expansion":{"automaticExpansion":true}}}},"containerKey":"pivot-table"},"writable":true}},{"key":"2","bookmark":{"name":"Untitled Chart","type":"container","value":{"style":{},"showTitleBar":true,"body":{"configuration":{"type":"plotly-line-chart","mapping":{"xAxis":["[Currency].[Currency].[Currency]"],"values":["[Measures].[pnl.FOREX]"],"splitBy":["[Booking].[Desk].[LegalEntity]"],"horizontalSubplots":[],"verticalSubplots":[]},"switchedTo":"plotly-clustered-column-chart"},"query":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Currency].[Currency])), Hierarchize(DrilldownLevel([Booking].[Desk].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[pnl.FOREX] ON COLUMNS FROM [EquityDerivativesCube]","contextValues":{},"updateMode":"once"}},"containerKey":"chart"},"writable":true}}],"layout":{"children":{"0":{"ck":"2"},"1":{"ck":"1"}},"direction":"row"},"name":"Page 1","filters":{"EquityDerivativesCube":[]}}]},"containerKey":"dashboard"}}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyInvalidFilterBookmark.ts b/src/4.3_to_5.0/__test_resources__/legacyInvalidFilterBookmark.ts new file mode 100644 index 0000000..adbd6c7 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyInvalidFilterBookmark.ts @@ -0,0 +1,17 @@ +/** + * The content entry representing a legacy filter containing an invalid property. + * Useful for unit tests. + */ +export const legacyInvalidFilterBookmark = { + entry: { + content: + '{"name":"AUI4 filter","type":"mdx","invalidvalue":{"shouldReplace":true,"type":"filter","mdx":"{[Geography].[City].[ALL].[AllMember].[Berlin], [Geography].[City].[ALL].[AllMember].[London]}","cube":"EquityDerivativesCube"}}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyKpiWithInvalidTitle.ts b/src/4.3_to_5.0/__test_resources__/legacyKpiWithInvalidTitle.ts new file mode 100644 index 0000000..56a7eca --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyKpiWithInvalidTitle.ts @@ -0,0 +1,18 @@ +/** + * The content entry for a legacy bookmark representing a KPI widget. + * Useful for unit tests. + + */ +export const legacyKpiWithInvalidTitle = { + entry: { + content: + '{"description": "A KPI containing a custom title with an empty tupleKey","name":"KPI","type":"container","value": {"style": {},"showTitleBar": true,"body": {"serverUrl": "","mdx": "SELECT NON EMPTY Hierarchize(AddCalculatedMembers(Descendants({[Geography].[City].[ALL].[AllMember]},1,SELF_AND_BEFORE))) ON ROWS,NON EMPTY {[Measures].[contributors.COUNT]} ON COLUMNS FROM (SELECT[Geography].[City].[ALL].[AllMember].[New York] ON COLUMNS FROM [EquityDerivativesCube])","contextValues": {},"updateMode": "once","ranges": {"row": {},"column": {}},"configuration": {"featuredValues": {"locations":{"":{"title": "Title with empty tupleKey"},"[Measures].[contributors.COUNT]": {"title": "Custom title for contributors.COUNT"}}}}},"containerKey":"featured-values"},"writable": true}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyPivotTableBookmark.ts b/src/4.3_to_5.0/__test_resources__/legacyPivotTableBookmark.ts new file mode 100644 index 0000000..6c3f3a7 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyPivotTableBookmark.ts @@ -0,0 +1,16 @@ +/** + * The content entry for a legacy bookmark representing a pivot table. + */ +export const legacyPivotTableBookmark = { + entry: { + content: + '{"description": "Valid widget","name": "Valid widget","type": "container", "value": {"style": {},"showTitleBar": false,"containerKey": "pivot-table","body": {"serverUrl": "","mdx": "SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[City].[ALL].[AllMember].[New York] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues": {},"updateMode": "once", "ranges": {}}}}', + isDirectory: false, + owners: ["admin"], + readers: ["admin"], + timestamp: 1607879735685, + lastEditor: "admin", + canRead: true, + canWrite: true, + }, +}; diff --git a/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidKpi.ts b/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidKpi.ts new file mode 100644 index 0000000..ad5a89f --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidKpi.ts @@ -0,0 +1,14 @@ +import { addLegacyBookmarkToUIFolder } from "./addLegacyBookmarkToUIFolder"; +import { emptyLegacyUIFolder } from "./emptyLegacyUIFolder"; +import { legacyKpiWithInvalidTitle } from "./legacyKpiWithInvalidTitle"; + +/** + * A legacy UI folder containing a single KPI bookmark with an invalid KPI title. + * Useful for unit tests. + */ +export const legacyUIFolderWithInvalidKpiTitle = addLegacyBookmarkToUIFolder( + emptyLegacyUIFolder, + { + kpi: legacyKpiWithInvalidTitle, + }, +); diff --git a/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidWidgets.ts b/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidWidgets.ts new file mode 100644 index 0000000..17e4548 --- /dev/null +++ b/src/4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidWidgets.ts @@ -0,0 +1,15 @@ +import { addLegacyBookmarkToUIFolder } from "./addLegacyBookmarkToUIFolder"; +import { emptyLegacyUIFolder } from "./emptyLegacyUIFolder"; +import { invalidLegacyWidgets } from "./invalidLegacyWidgets"; +import { legacyPivotTableBookmark } from "./legacyPivotTableBookmark"; + +/** + * Contains three legacy bookmark widgets. + * 1. Widget with an invalid container container key. + * 2. Widget with a filter on an invalid hierarchy. + * 3. A valid widget. + */ +export const legacyUIFolderWithInvalidWidgets = addLegacyBookmarkToUIFolder( + emptyLegacyUIFolder, + { ...invalidLegacyWidgets, "777": legacyPivotTableBookmark }, +); diff --git a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolder.ts b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolder.ts index aeb3ad7..e00cc38 100644 --- a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolder.ts +++ b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolder.ts @@ -1,240 +1,11 @@ +import { addLegacyBookmarkToUIFolder } from "./addLegacyBookmarkToUIFolder"; +import { emptyLegacyUIFolder } from "./emptyLegacyUIFolder"; +import { legacyDashboardBookmark } from "./legacyDashboardBookmark"; + /** * The shortened version of the content of the /ui folder on a Content Server, useful for unit tests. */ -export const smallLegacyUIFolder = { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879725132, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - bookmarks: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - content: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - content: - '{"name":"hidden grand totals","type":"container","value":{"style":{},"showTitleBar":false,"body":{"pages":[{"content":[{"key":"1","bookmark":{"name":"Untitled Pivot Table","type":"container","value":{"style":{},"showTitleBar":true,"body":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Geography].[City].[ALL].[AllMember])), Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{"mdx.hiddengrandtotals":"1"},"updateMode":"once","ranges":{"row":{"chunkSize":2000,"thresholdPercentage":0.1},"column":{"chunkSize":50,"thresholdPercentage":0.2}},"configuration":{"tabular":{"pinnedHeaderSelector":"member","sortingMode":"non-breaking","addButtonFilter":"numeric","cellRenderers":["tree-layout"],"statisticsShown":true,"columnsGroups":[{"captionProducer":"firstColumn","cellFactory":"kpi-status","selector":"kpi-status"},{"captionProducer":"firstColumn","cellFactory":"lookup","selector":"lookup"},{"captionProducer":"expiry","cellFactory":"expiry","selector":"kpi-expiry"},{"captionProducer":"columnMerge","cellFactory":{"args":{},"key":"treeCells"},"selector":"member"}],"hideAddButton":true,"defaultOptions":{},"expansion":{"automaticExpansion":true}}}},"containerKey":"pivot-table"},"writable":true}},{"key":"2","bookmark":{"name":"Untitled Chart","type":"container","value":{"style":{},"showTitleBar":true,"body":{"configuration":{"type":"plotly-line-chart","mapping":{"xAxis":["[Currency].[Currency].[Currency]"],"values":["[Measures].[pnl.FOREX]"],"splitBy":["[Booking].[Desk].[LegalEntity]"],"horizontalSubplots":[],"verticalSubplots":[]},"switchedTo":"plotly-clustered-column-chart"},"query":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Currency].[Currency])), Hierarchize(DrilldownLevel([Booking].[Desk].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[pnl.FOREX] ON COLUMNS FROM [EquityDerivativesCube]","contextValues":{},"updateMode":"once"}},"containerKey":"chart"},"writable":true}}],"layout":{"children":{"0":{"ck":"2"},"1":{"ck":"1"}},"direction":"row"},"name":"Page 1","filters":{"EquityDerivativesCube":[]}}]},"containerKey":"dashboard"}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - i18n: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "en-US": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "fr-FR": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - structure: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - }, - }, - settings: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - default: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - preferences: { - entry: { - content: '{\n "allow": [],\n "deny": [],\n "map": {}\n}', - isDirectory: false, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - roles: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - users: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - user1: { - entry: { - isDirectory: true, - owners: ["user1"], - readers: ["user1"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - preferences: { - entry: { - content: - '{\n "map": {\n "defaultPermissions": {\n "owners": [\n "user2"\n ],\n "readers": [\n "user2"\n ]\n }\n }\n}', - isDirectory: false, - owners: ["user1"], - readers: ["user1"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - admin: { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - preferences: { - entry: { - content: - '{\n "map": {\n "tree.search.maxResults": 10,\n "global.theme": "dark-activeviam",\n "userFilters.enabled": true,\n "showLegacyCharts": true,\n "showLegacyMaps": true,\n "widgets.Tabular.drillthrough.selectedColumns": {\n "https://activepivot-ranch.activeviam.com:5900": {\n "EquityDerivativesCube": [\n {\n "functionName": "MemberValue",\n "columnName": "delta"\n },\n {\n "functionName": "Caption",\n "columnName": "delta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "gamma"\n },\n {\n "functionName": "Caption",\n "columnName": "gamma"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlVega"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlVega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Desk"\n },\n {\n "functionName": "Caption",\n "columnName": "Desk"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Currency"\n },\n {\n "functionName": "Caption",\n "columnName": "Currency"\n },\n {\n "functionName": "MemberValue",\n "columnName": "Date"\n },\n {\n "functionName": "Caption",\n "columnName": "Date"\n },\n {\n "columnName": "HostName",\n "functionName": "MemberValue"\n },\n {\n "columnName": "HostName",\n "functionName": "Caption"\n }\n ],\n "EquityDerivativesCubeDist": [\n {\n "functionName": "MemberValue",\n "columnName": "BumpedMtmDown"\n },\n {\n "functionName": "Caption",\n "columnName": "BumpedMtmDown"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "vega"\n },\n {\n "functionName": "Caption",\n "columnName": "vega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "rho"\n },\n {\n "functionName": "Caption",\n "columnName": "rho"\n },\n {\n "functionName": "MemberValue",\n "columnName": "productId"\n },\n {\n "functionName": "Caption",\n "columnName": "productId"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlVega"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlVega"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnlDelta"\n },\n {\n "functionName": "Caption",\n "columnName": "pnlDelta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "pnl"\n },\n {\n "functionName": "Caption",\n "columnName": "pnl"\n },\n {\n "functionName": "MemberValue",\n "columnName": "gamma"\n },\n {\n "functionName": "Caption",\n "columnName": "gamma"\n },\n {\n "functionName": "MemberValue",\n "columnName": "delta"\n },\n {\n "functionName": "Caption",\n "columnName": "delta"\n },\n {\n "functionName": "MemberValue",\n "columnName": "TradeId"\n },\n {\n "functionName": "Caption",\n "columnName": "TradeId"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductQtyMultiplier"\n },\n {\n "functionName": "MemberValue",\n "columnName": "ProductBaseMtm"\n },\n {\n "functionName": "Caption",\n "columnName": "ProductBaseMtm"\n },\n {\n "columnName": "ProductQtyMultiplier",\n "functionName": "MemberValue"\n },\n {\n "columnName": "ProductQtyMultiplier",\n "functionName": "Caption"\n }\n ]\n }\n },\n "defaultPermissions": {\n "owners": [\n "admin"\n ],\n "readers": [\n "admin"\n ]\n },\n "project.content-editor.configuration": {\n "autoSwitchToFieldsOnEmptyWidget": true,\n "advancedModeDropdownHidden": false,\n "hideFieldsControls": false,\n "mdx-common": {\n "regularModeTab": "filters",\n "advancedModeEnabled": false,\n "advancedModeTab": "mdx"\n }\n },\n "user.contextValues": {\n "EquityDerivativesCube": {},\n "EquityDerivativesCubeDist": {}\n },\n "user.filters": {\n "EquityDerivativesCube": ["[Geography].[City].[ALL].[AllMember].[Berlin]"],\n "EquityDerivativesCubeDist": []\n },\n "filtering.hierarchyToFilterType.[Geography].[City]": "explicit",\n "filtering.hierarchyToFilterType.[Currency].[Currency]": "explicit",\n "filtering.hierarchyToFilterType.[Trades].[Trades]": "topcount",\n "servers.alias": {\n "https://activepivot-ranch.activeviam.com:5900": "http://localhost:8080"\n }\n }\n}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - }, - }, - }, - }, - version: { - entry: { - content: '{"package":"4.3.8","contentServerApi":"0.1.0"}', - isDirectory: false, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, -}; +export const smallLegacyUIFolder = addLegacyBookmarkToUIFolder( + emptyLegacyUIFolder, + { "158": legacyDashboardBookmark }, +); diff --git a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidDashboard.ts b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidDashboard.ts index 713fbb9..e06eacf 100644 --- a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidDashboard.ts +++ b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidDashboard.ts @@ -1,138 +1,12 @@ +import { addLegacyBookmarkToUIFolder } from "./addLegacyBookmarkToUIFolder"; +import { emptyLegacyUIFolder } from "./emptyLegacyUIFolder"; +import { legacyInvalidDashboardBookmark } from "./legacyInvalidDashboardBookmark"; + /** * The shortened version of the content of the /ui folder on a Content Server, useful for unit tests. * Contains an invalid dashboard whose id is numerical. */ -export const smallLegacyUIFolderWithInvalidDashboard = { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879725132, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - bookmarks: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - content: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - content: - '{"name":"hidden grand totals","type":"container","value":{"style":{},"showTitleBar":false,"body":{"pages":[{"content":[{"key":"1","bookmark":{"name":"Untitled Pivot Table","type":"container","value":{"style":{},"showTitleBar":true,"body":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Geography].[City].[ALL].[AllMember])), Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [foo] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{"mdx.hiddengrandtotals":"1"},"updateMode":"once","ranges":{"row":{"chunkSize":2000,"thresholdPercentage":0.1},"column":{"chunkSize":50,"thresholdPercentage":0.2}},"configuration":{"tabular":{"pinnedHeaderSelector":"member","sortingMode":"non-breaking","addButtonFilter":"numeric","cellRenderers":["tree-layout"],"statisticsShown":true,"columnsGroups":[{"captionProducer":"firstColumn","cellFactory":"kpi-status","selector":"kpi-status"},{"captionProducer":"firstColumn","cellFactory":"lookup","selector":"lookup"},{"captionProducer":"expiry","cellFactory":"expiry","selector":"kpi-expiry"},{"captionProducer":"columnMerge","cellFactory":{"args":{},"key":"treeCells"},"selector":"member"}],"hideAddButton":true,"defaultOptions":{},"expansion":{"automaticExpansion":true}}}},"containerKey":"pivot-table"},"writable":true}},{"key":"2","bookmark":{"name":"Untitled Chart","type":"container","value":{"style":{},"showTitleBar":true,"body":{"configuration":{"type":"plotly-line-chart","mapping":{"xAxis":["[Currency].[Currency].[Currency]"],"values":["[Measures].[pnl.FOREX]"],"splitBy":["[Booking].[Desk].[LegalEntity]"],"horizontalSubplots":[],"verticalSubplots":[]},"switchedTo":"plotly-clustered-column-chart"},"query":{"serverUrl":"","mdx":"SELECT NON EMPTY Crossjoin(Hierarchize(DrilldownLevel([Currency].[Currency])), Hierarchize(DrilldownLevel([Booking].[Desk].[ALL].[AllMember]))) ON ROWS, NON EMPTY [Measures].[pnl.FOREX] ON COLUMNS FROM [EquityDerivativesCube]","contextValues":{},"updateMode":"once"}},"containerKey":"chart"},"writable":true}}],"layout":{"children":{"0":{"ck":"2"},"1":{"ck":"1"}},"direction":"row"},"name":"Page 1","filters":{"EquityDerivativesCube":[]}}]},"containerKey":"dashboard"}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - i18n: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "en-US": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "fr-FR": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - structure: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - }, - }, - settings: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - version: { - entry: { - content: '{"package":"4.3.8","contentServerApi":"0.1.0"}', - isDirectory: false, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, -}; +export const smallLegacyUIFolderWithInvalidDashboard = + addLegacyBookmarkToUIFolder(emptyLegacyUIFolder, { + "158": legacyInvalidDashboardBookmark, + }); diff --git a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidFilter.ts b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidFilter.ts index 7fee55e..87fff2c 100644 --- a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidFilter.ts +++ b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidFilter.ts @@ -1,139 +1,12 @@ +import { addLegacyBookmarkToUIFolder } from "./addLegacyBookmarkToUIFolder"; +import { emptyLegacyUIFolder } from "./emptyLegacyUIFolder"; +import { legacyInvalidFilterBookmark } from "./legacyInvalidFilterBookmark"; + /** * The shortened version of the content of the /ui folder on a Content Server, useful for unit tests. * Contains an invalid filter. */ -export const smallLegacyUIFolderWithInvalidFilter = { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879725132, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - bookmarks: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - content: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - content: - '{"name":"AUI4 filter","type":"mdx","invalidvalue":{"shouldReplace":true,"type":"filter","mdx":"{[Geography].[City].[ALL].[AllMember].[Berlin], [Geography].[City].[ALL].[AllMember].[London]}","cube":"EquityDerivativesCube"}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - i18n: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "en-US": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "fr-FR": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - structure: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - }, - }, - settings: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: {}, - }, - version: { - entry: { - content: '{"package":"4.3.8","contentServerApi":"0.1.0"}', - isDirectory: false, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, -}; +export const smallLegacyUIFolderWithInvalidFilter = addLegacyBookmarkToUIFolder( + emptyLegacyUIFolder, + { "158": legacyInvalidFilterBookmark }, +); diff --git a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidWidget.ts b/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidWidget.ts deleted file mode 100644 index 33948e4..0000000 --- a/src/4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidWidget.ts +++ /dev/null @@ -1,186 +0,0 @@ -/** - * The shortened version of the content of the /ui folder on a Content Server, useful for unit tests. - * Contains a valid widget, a widget whose `containerKey` is not valid, and another widget with a filter on a hierarchy that does not exist in the test cube. - */ -export const smallLegacyUIFolderWithInvalidWidget = { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879725132, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - bookmarks: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - content: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - content: - '{"description":"Widget with invalid container key","name":"Invalid widget","type":"container","value":{"style":{},"showTitleBar":false,"containerKey":"invalid-container-key","body":{"serverUrl":"","mdx":"SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[City].[ALL].[AllMember].[New York] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{},"updateMode":"once","ranges":{}}}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "1231": { - entry: { - content: - '{"description":"Widget with filter on invalid hierarchy","name":"Invalid widget","type":"container","value":{"style":{},"showTitleBar":false,"containerKey":"pivot-table","body":{"serverUrl":"","mdx":"SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[InvalidHierarchy].[ALL].[AllMember].[Member] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{},"updateMode":"once","ranges":{}}}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "777": { - entry: { - content: - '{"description": "Valid widget","name": "Valid widget","type": "container", "value": {"style": {},"showTitleBar": false,"containerKey": "pivot-table","body": {"serverUrl": "","mdx": "SELECT NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] WHERE [Geography].[City].[ALL].[AllMember].[New York] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues": {},"updateMode": "once", "ranges": {}}}}', - isDirectory: false, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - i18n: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "en-US": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "fr-FR": { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - structure: { - entry: { - isDirectory: true, - owners: ["ROLE_USER"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - children: { - "158": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "1231": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - "777": { - entry: { - isDirectory: true, - owners: ["admin"], - readers: ["admin"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, - }, - }, - }, - settings: { - entry: { - isDirectory: true, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - version: { - entry: { - content: '{"package":"4.3.8","contentServerApi":"0.1.0"}', - isDirectory: false, - owners: ["ROLE_CS_ROOT"], - readers: ["ROLE_USER"], - timestamp: 1607879735685, - lastEditor: "admin", - canRead: true, - canWrite: true, - }, - }, - }, -}; diff --git a/src/4.3_to_5.0/getMigratedKpiTitles.test.ts b/src/4.3_to_5.0/accumulateMigratedKpiTitles.test.ts similarity index 68% rename from src/4.3_to_5.0/getMigratedKpiTitles.test.ts rename to src/4.3_to_5.0/accumulateMigratedKpiTitles.test.ts index f720a44..fee405d 100644 --- a/src/4.3_to_5.0/getMigratedKpiTitles.test.ts +++ b/src/4.3_to_5.0/accumulateMigratedKpiTitles.test.ts @@ -1,13 +1,14 @@ import { dataModelsForTests } from "@activeviam/data-model-5.0"; -import { getMigratedKpiTitles } from "./getMigratedKpiTitles"; +import { accumulateMigratedKpiTitles } from "./accumulateMigratedKpiTitles"; import { legacyKpi } from "./__test_resources__/legacyKpi"; import { _getQueryInLegacyWidgetState } from "./_getQueryInLegacyWidgetState"; import { MdxSelect, parse } from "@activeviam/mdx-5.0"; +import { KpiWidgetState } from "@activeviam/activeui-sdk-5.0"; const cube = dataModelsForTests.sandbox.catalogs[0].cubes[0]; -describe("getMigratedKpiTitles", () => { - it("returns the migrated KPI titles corresponding to the legacy KPI state, ready to be used in Atoti UI 5.0", () => { +describe("accumulateMigratedKpiTitles", () => { + it("accumulates the migrated KPI titles corresponding to the legacy KPI state, ready to be used in Atoti UI 5.0", () => { const legacyQuery = _getQueryInLegacyWidgetState(legacyKpi); if (!legacyQuery || !legacyQuery.mdx) { @@ -15,7 +16,9 @@ describe("getMigratedKpiTitles", () => { } const legacyMdx = parse(legacyQuery.mdx); - const migratedKpiTitles = getMigratedKpiTitles(legacyKpi, { + const migratedTitles: KpiWidgetState["titles"] = {}; + accumulateMigratedKpiTitles(legacyKpi, { + migratedTitles, cube, legacyMdx, mapping: { @@ -31,7 +34,7 @@ describe("getMigratedKpiTitles", () => { ], }, }); - expect(migratedKpiTitles).toMatchInlineSnapshot(` + expect(migratedTitles).toMatchInlineSnapshot(` { "[Measures].[contributors.COUNT],[Currency].[Currency].[AllMember].[EUR, USD]": "Hello World", } diff --git a/src/4.3_to_5.0/getMigratedKpiTitles.ts b/src/4.3_to_5.0/accumulateMigratedKpiTitles.ts similarity index 54% rename from src/4.3_to_5.0/getMigratedKpiTitles.ts rename to src/4.3_to_5.0/accumulateMigratedKpiTitles.ts index 11b21eb..2abb7ab 100644 --- a/src/4.3_to_5.0/getMigratedKpiTitles.ts +++ b/src/4.3_to_5.0/accumulateMigratedKpiTitles.ts @@ -43,24 +43,27 @@ function _getLegacyKpiTitles( } = {}; const memberUniqueNames = tupleKey.split(/,(?![^\[]*\])/); for (const memberUniqueName of memberUniqueNames) { - const compoundIdentifier = - parse(memberUniqueName); - const specificCompoundIdentifier = getSpecificCompoundIdentifier( - compoundIdentifier, - { cube }, - ); - if (specificCompoundIdentifier.type === "measure") { - tuple[`[Measures].[Measures]`] = [ - specificCompoundIdentifier.measureName, - ]; - } else if (specificCompoundIdentifier.type === "member") { - const hierarchyUniqueName = quote( - specificCompoundIdentifier.dimensionName, - specificCompoundIdentifier.hierarchyName, + if (memberUniqueName) { + const compoundIdentifier = + parse(memberUniqueName); + const specificCompoundIdentifier = getSpecificCompoundIdentifier( + compoundIdentifier, + { cube }, ); - tuple[hierarchyUniqueName] = specificCompoundIdentifier.path; + if (specificCompoundIdentifier.type === "measure") { + tuple[`[Measures].[Measures]`] = [ + specificCompoundIdentifier.measureName, + ]; + } else if (specificCompoundIdentifier.type === "member") { + const hierarchyUniqueName = quote( + specificCompoundIdentifier.dimensionName, + specificCompoundIdentifier.hierarchyName, + ); + tuple[hierarchyUniqueName] = specificCompoundIdentifier.path; + } } } + legacyTitles.push({ title, tuple }); } @@ -68,24 +71,27 @@ function _getLegacyKpiTitles( } /** - * Returns the migrated KPI widget titles corresponding to legacyKpiState. + * Accumulates the migrated KPI widget titles corresponding to legacyKpiState. + * Mutates `migratedTitles`. */ -export function getMigratedKpiTitles( +export function accumulateMigratedKpiTitles( // Legacy widget states are not typed. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types legacyKpiState: any, { + migratedTitles = {}, legacyMdx, mapping, cube, }: { + migratedTitles: KpiWidgetState["titles"]; legacyMdx: MdxSelect; mapping: DataVisualizationWidgetMapping; cube: Cube; }, -): KpiWidgetState["titles"] { +): void { const legacyTitles = _getLegacyKpiTitles(legacyKpiState, { cube }); - const migratedTitles: KpiWidgetState["titles"] = {}; + const errors: Error[] = []; const numberOfColumnFields = mapping.columns?.length ?? 0; @@ -107,35 +113,44 @@ export function getMigratedKpiTitles( const ordinalFields = [...(mapping.columns ?? []), ...(mapping.rows ?? [])]; legacyTitles.forEach(({ title, tuple }) => { - const memberUniqueNames: string[] = []; + try { + const memberUniqueNames: string[] = []; - ordinalFields.forEach((field) => { - if (field.type === "hierarchy") { - const hierarchyUniqueName = quote( - field.dimensionName, - field.hierarchyName, - ); - const namePath = tuple[hierarchyUniqueName]; - if (namePath) { - memberUniqueNames.push( - `${hierarchyUniqueName}.${quote(...namePath)}`, + ordinalFields.forEach((field) => { + if (field.type === "hierarchy") { + const hierarchyUniqueName = quote( + field.dimensionName, + field.hierarchyName, ); + const namePath = tuple[hierarchyUniqueName]; + if (namePath) { + memberUniqueNames.push( + `${hierarchyUniqueName}.${quote(...namePath)}`, + ); + } } + }); + + if (measuresPositionInTuple > -1) { + const measureName = tuple[quote("Measures", "Measures")][0]; + memberUniqueNames.splice( + measuresPositionInTuple, + 0, + quote("Measures", measureName), + ); } - }); - - if (measuresPositionInTuple > -1) { - const measureName = tuple[quote("Measures", "Measures")][0]; - memberUniqueNames.splice( - measuresPositionInTuple, - 0, - quote("Measures", measureName), - ); - } - const tupleKey = memberUniqueNames.join(","); - migratedTitles[tupleKey] = title; + const tupleKey = memberUniqueNames.join(","); + migratedTitles[tupleKey] = title; + } catch (error) { + errors.push(error as Error); + } }); - return migratedTitles; + if (errors.length > 0) { + throw new Error( + `One or more errors occurred while migrating the titles for the kpi named ${legacyKpiState.name}: ` + + errors.map((e) => e.message).join(", "), + ); + } } diff --git a/src/4.3_to_5.0/migrateKpi.ts b/src/4.3_to_5.0/migrateKpi.ts index 96c799a..592389d 100644 --- a/src/4.3_to_5.0/migrateKpi.ts +++ b/src/4.3_to_5.0/migrateKpi.ts @@ -29,7 +29,7 @@ import { _getQueryInLegacyWidgetState } from "./_getQueryInLegacyWidgetState"; import { _getTargetCubeFromServerUrl } from "./_getTargetCubeFromServerUrl"; import { _migrateQuery } from "./_migrateQuery"; import { produce } from "immer"; -import { getMigratedKpiTitles } from "./getMigratedKpiTitles"; +import { accumulateMigratedKpiTitles } from "./accumulateMigratedKpiTitles"; import { PartialMigrationError } from "../PartialMigrationError"; const moveExpressionToWithClause = ( @@ -210,13 +210,15 @@ export function migrateKpi( }), }; + const migratedTitles: KpiWidgetState["titles"] = {}; try { if (legacyMdx) { // Migrate manually entered KPI titles. - const migratedTitles = getMigratedKpiTitles(legacyKpiState, { + accumulateMigratedKpiTitles(legacyKpiState, { cube, mapping, legacyMdx, + migratedTitles, }); if (migratedTitles && Object.keys(migratedTitles).length > 0) { migratedWidgetState.titles = migratedTitles; @@ -224,6 +226,11 @@ export function migrateKpi( } } catch (error) { // Migrating the KPI titles is a best effort. + // If there is an error while migrating one of the titles, the successfully migrated titles are still persisted. + if (migratedTitles && Object.keys(migratedTitles).length > 0) { + migratedWidgetState.titles = migratedTitles; + } + // The migration script should not fail if this part errors. throw new PartialMigrationError( `Could not migrate the titles of the featured values widget named "${legacyKpiState.name}"`, diff --git a/src/migrateContentServer.test.ts b/src/migrateContentServer.test.ts index bde990b..7ef13d2 100644 --- a/src/migrateContentServer.test.ts +++ b/src/migrateContentServer.test.ts @@ -4,7 +4,8 @@ import { smallLegacyPivotFolder } from "./4.3_to_5.0/__test_resources__/smallLeg import { smallLegacyUIFolder } from "./4.3_to_5.0/__test_resources__/smallLegacyUIFolder"; import { migrateContentServer } from "./migrateContentServer"; import _cloneDeep from "lodash/cloneDeep"; -import { smallLegacyUIFolderWithInvalidWidget } from "./4.3_to_5.0/__test_resources__/smallLegacyUIFolderWithInvalidWidget"; +import { legacyUIFolderWithInvalidWidgets } from "./4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidWidgets"; +import { legacyUIFolderWithInvalidKpiTitle } from "./4.3_to_5.0/__test_resources__/legacyUIFolderWithInvalidKpi"; jest.mock(`./4.3_to_5.0/generateId`, () => { let counter = 0; @@ -237,7 +238,7 @@ describe("migrateContentServer", () => { it("keeps the original item untouched, as before the whole migration when the item cannot be migrated due to an error and the `behaviorOnError` flag is set to `keep-original`.", async () => { const contentServer: ContentRecord = { children: { - ui: smallLegacyUIFolderWithInvalidWidget, + ui: legacyUIFolderWithInvalidWidgets, pivot: smallLegacyPivotFolder, }, entry: { @@ -287,7 +288,7 @@ describe("migrateContentServer", () => { it("keeps the 5.0 version of the widget, when migrating from 4.3 to 5.1 with `behaviorOnError` set to `keep-last-successful-version` and the 5.0 to 5.1 step fails", async () => { const contentServer: ContentRecord = { children: { - ui: smallLegacyUIFolderWithInvalidWidget, + ui: legacyUIFolderWithInvalidWidgets, pivot: smallLegacyPivotFolder, }, entry: { @@ -336,4 +337,68 @@ describe("migrateContentServer", () => { // The filters in 5.0 are represented as strings. expect(typeof migratedWidgetFilter.mdx).toBe("string"); }); + + it("migrates the KPI custom titles while dropping custom titles that could not be successfully migrated", async () => { + const contentServer: ContentRecord = { + children: { + ui: legacyUIFolderWithInvalidKpiTitle, + pivot: smallLegacyPivotFolder, + }, + entry: { + owners: [], + readers: [], + isDirectory: true, + canRead: true, + canWrite: false, + lastEditor: "Freddie Mercury", + timestamp: 0xbeef, + }, + }; + + const contentServerBeforeMigration = _cloneDeep(contentServer); + + await migrateContentServer({ + contentServer, + servers, + fromVersion: "4.3", + toVersion: "5.1", + keysOfWidgetPluginsToRemove: [], + doesReportIncludeStacks: false, + shouldUpdateFiltersMdx: true, + behaviorOnError: "keep-original", + }); + + const kpiContentBeforeMigration = JSON.parse( + contentServerBeforeMigration.children?.ui.children?.bookmarks.children + ?.content.children?.["kpi"].entry.content, + ); + + expect( + kpiContentBeforeMigration.value.body.configuration["featuredValues"] + .locations, + ).toMatchInlineSnapshot(` + { + "": { + "title": "Title with empty tupleKey", + }, + "[Measures].[contributors.COUNT]": { + "title": "Custom title for contributors.COUNT", + }, + } + `); + + // The widget with id "kpi" contains a custom title referenced with an empty `tupleKey`. + // Because this is not a valid `tupleKey`, the title is dropped. + const migratedKpiContent = JSON.parse( + contentServer.children?.ui.children?.widgets.children?.content.children?.[ + "kpi" + ].entry.content, + ); + + expect(migratedKpiContent?.titles).toMatchInlineSnapshot(` + { + "[Measures].[contributors.COUNT]": "Custom title for contributors.COUNT", + } + `); + }); });