Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
mailys-ds committed Sep 21, 2023
1 parent f1de0e6 commit 1835f4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions src/4.3_to_5.0/_cleanupDescendants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const cube = dataModelsForTests.sandbox.catalogs[0].cubes[0];

describe("_cleanupDescendants", () => {
it("replaces a Descendants function by its input set if the shallowest level expressed in the set is the same as the target one or above", () => {
const mdx: MdxSelect = parse(`
const mdx = parse<MdxSelect>(`
SELECT
NON EMPTY Hierarchize(
Descendants(
Expand All @@ -31,7 +31,7 @@ describe("_cleanupDescendants", () => {
});

it("replaces a useless Descendants function called on a set from a multilevel hierarchy", () => {
const mdx: MdxSelect = parse(`
const mdx = parse<MdxSelect>(`
SELECT
NON EMPTY Hierarchize(
Descendants(
Expand All @@ -55,7 +55,7 @@ describe("_cleanupDescendants", () => {
});

it("replaces a useless Descendants function when the second argument is a level index", () => {
const mdx: MdxSelect = parse(`
const mdx = parse<MdxSelect>(`
SELECT
NON EMPTY Hierarchize(
Descendants(
Expand All @@ -79,7 +79,7 @@ describe("_cleanupDescendants", () => {
});

it("replaces a useless Descendants function called on a set with members from the leaf level, without a second argument", () => {
const mdx: MdxSelect = parse(`
const mdx = parse<MdxSelect>(`
SELECT
NON EMPTY Hierarchize(
Descendants(
Expand All @@ -102,13 +102,9 @@ describe("_cleanupDescendants", () => {
});

it("does not cleanup the descendants of a hierarchy's current member", () => {
const mdx: MdxSelect = parse(
`WITH Member [Measures].[City] AS Count(Descendants([Geography].[City].CurrentMember, [Geography].[City].[City]), EXCLUDEEMPTY), FORMAT_STRING = \"#,###.##\" SELECT NON EMPTY {[Measures].[City]} ON COLUMNS, NON EMPTY [Geography].[City].[City].Members ON ROWS FROM [EquityDerivativesCube] CELL PROPERTIES BACK_COLOR, FONT_FLAGS, FORE_COLOR, FORMATTED_VALUE, VALUE`,
);
const cleanMdx = _cleanupDescendants(mdx, cube);
expect(stringify(cleanMdx, { indent: true })).toMatchInlineSnapshot(`
"WITH
Member [Measures].[City] AS Count(
const mdxString = `
WITH
Member [Measures].[City] AS Count(
Descendants(
[Geography].[City].CurrentMember,
[Geography].[City].[City]
Expand All @@ -121,7 +117,10 @@ describe("_cleanupDescendants", () => {
} ON COLUMNS,
NON EMPTY [Geography].[City].[City].Members ON ROWS
FROM [EquityDerivativesCube]
CELL PROPERTIES BACK_COLOR, FONT_FLAGS, FORE_COLOR, FORMATTED_VALUE, VALUE"
`);
CELL PROPERTIES BACK_COLOR, FONT_FLAGS, FORE_COLOR, FORMATTED_VALUE, VALUE
`;
const mdx = parse<MdxSelect>(mdxString);
const cleanMdx = _cleanupDescendants(mdx, cube);
expect(cleanMdx).toStrictEqual(mdx);
});
});
2 changes: 1 addition & 1 deletion src/4.3_to_5.0/_cleanupDescendants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const canDescendantsBeReplacedByItsFirstArgument = (
const [set, downToLevel] = descendantsNode.arguments;
const levelsInSet = getLevels(set, { cube });

// If no levels are found in the input set, for instance, in case of a .CurrentMember as a level, the `descendants` function should not be removed.
// If no levels are found in the input set, for instance when it consists only in the `CurrentMember` of a hierarchy (which could be on any level), the `Descendants` function should not be removed.
if (levelsInSet.length === 0) {
return false;
}
Expand Down

0 comments on commit 1835f4a

Please sign in to comment.