Skip to content

Commit

Permalink
Add test for usage of the keep-last-successful-version behaviorOnErro…
Browse files Browse the repository at this point in the history
…r flag
  • Loading branch information
NZepeda committed Jul 29, 2024
1 parent 4b9f062 commit 882272c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ export const smallLegacyUIFolderWithInvalidWidget = {
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:
Expand Down Expand Up @@ -120,6 +133,17 @@ export const smallLegacyUIFolderWithInvalidWidget = {
canWrite: true,
},
},
"1231": {
entry: {
isDirectory: true,
owners: ["admin"],
readers: ["admin"],
timestamp: 1607879735685,
lastEditor: "admin",
canRead: true,
canWrite: true,
},
},
"777": {
entry: {
isDirectory: true,
Expand Down
42 changes: 42 additions & 0 deletions src/migrateContentServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,46 @@ describe("migrateContentServer", () => {
savedWidgetContentAfterMigration,
);
});

it("keeps 5.0 version of the widget, when the there is an error when attempting to migrate it from 5.0 to 5.1 when the `behaviorOnError` flag is set to `keep-last-successful-version`.", async () => {
const contentServer: ContentRecord = {
children: {
ui: smallLegacyUIFolderWithInvalidWidget,
pivot: smallLegacyPivotFolder,
},
entry: {
owners: [],
readers: [],
isDirectory: true,
canRead: true,
canWrite: false,
lastEditor: "Freddie Mercury",
timestamp: 0xbeef,
},
};

await migrateContentServer({
contentServer,
servers,
fromVersion: "4.3",
toVersion: "5.1",
keysOfWidgetPluginsToRemove: [],
doesReportIncludeStacks: false,
shouldUpdateFiltersMdx: true,
behaviorOnError: "keep-last-successful-version",
});

const savedWidgetContentAfterMigration = JSON.parse(
contentServer?.children?.ui?.children?.widgets?.children?.content
?.children?.["1231"].entry.content,
);

expect(savedWidgetContentAfterMigration.filters).toBeDefined();
expect(savedWidgetContentAfterMigration.filters).not.toHaveLength(0);

const migratedWidgetFilter = savedWidgetContentAfterMigration.filters[0];

// The filters in 5.0 are represented as strings.
expect(typeof migratedWidgetFilter.mdx).toBe("string");
});
});

0 comments on commit 882272c

Please sign in to comment.