Skip to content

Commit

Permalink
Update previously added tests to utilize the new test resource function
Browse files Browse the repository at this point in the history
  • Loading branch information
NZepeda committed Aug 14, 2024
1 parent 53e4964 commit 22b5547
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions src/migrateContentServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 { addLegacyBookmarkToUIFolder } from "./4.3_to_5.0/addLegacyBookmarkToUIFolder";
import { emptyLegacyUIFolder } from "./4.3_to_5.0/__test_resources__/emptyLegacyUIFolder";

Expand All @@ -20,6 +19,54 @@ jest.mock(`./4.3_to_5.0/generateId`, () => {
};
});

/**
* 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.
*/
const bookmarkContentWithInvalidWidgets = {
"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,
},
},
};

describe("migrateContentServer", () => {
it("migrates calculated measures from the /pivot folder to the /ui folder when migrating from 4.3 to 5.0", async () => {
const contentServer: ContentRecord = {
Expand Down Expand Up @@ -237,9 +284,14 @@ 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 legacyUIFolderWithInvalidWidgets = addLegacyBookmarkToUIFolder(
emptyLegacyUIFolder,
bookmarkContentWithInvalidWidgets,
);

const contentServer: ContentRecord = {
children: {
ui: smallLegacyUIFolderWithInvalidWidget,
ui: legacyUIFolderWithInvalidWidgets,
pivot: smallLegacyPivotFolder,
},
entry: {
Expand Down Expand Up @@ -287,9 +339,14 @@ 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 legacyUIFolderWithInvalidWidgets = addLegacyBookmarkToUIFolder(
emptyLegacyUIFolder,
bookmarkContentWithInvalidWidgets,
);

const contentServer: ContentRecord = {
children: {
ui: smallLegacyUIFolderWithInvalidWidget,
ui: legacyUIFolderWithInvalidWidgets,
pivot: smallLegacyPivotFolder,
},
entry: {
Expand Down

0 comments on commit 22b5547

Please sign in to comment.