From 7a7ddbe62980d85d1474cadc735b6ea9d7e3f765 Mon Sep 17 00:00:00 2001
From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
Date: Mon, 2 Nov 2020 23:46:23 +0100
Subject: [PATCH] Fix old MBQL syntax in tests (#13647)

* Fix obsolete MBQL syntax in `localization.cy.spec.js` [ci skip]

Introduced in: https://github.com/metabase/metabase/commit/6b5765718daff384a1831cd7383401369b8c1725.

* Fix obsolete MBQL syntax in `dashboard.cy.spec.js` [ci skip]

Introduced in: https://github.com/metabase/metabase/commit/2958b836cc73c16b74b6e6e8fd96a6dabd12f60e.

* Fix obsolete MBQL syntax in `nested.cy.spec.js` [ci skip]

Introduced in: https://github.com/metabase/metabase/commit/ab762e1ffb8cd79fedc050709c059e8c8b87ef9b.

* Fix obsolete MBQL syntax in `dashboard-drill.cy.spec.js` [ci skip]

Introduced in: https://github.com/metabase/metabase/commit/cb4371e9fcc45ec242d106c4a01c4a0d68d4c324.

* Fix obsolete MBQL syntax in `nulls.cy.spec.js`

Introduced in: https://github.com/metabase/metabase/commit/854f5317df724abc0a6026b06bfa539d15d34fa6.

* Add positive assertion for repro for #13571
---
 .../admin/settings/localization.cy.spec.js    |   6 +-
 .../dashboard/dashboard-drill.cy.spec.js      | 136 +++++++++---------
 .../scenarios/dashboard/dashboard.cy.spec.js  |  18 ++-
 .../scenarios/question/nested.cy.spec.js      |   4 +-
 .../scenarios/question/nulls.cy.spec.js       |   7 +-
 5 files changed, 92 insertions(+), 79 deletions(-)

diff --git a/frontend/test/metabase/scenarios/admin/settings/localization.cy.spec.js b/frontend/test/metabase/scenarios/admin/settings/localization.cy.spec.js
index 04f74fe4de8..8676b48ce58 100644
--- a/frontend/test/metabase/scenarios/admin/settings/localization.cy.spec.js
+++ b/frontend/test/metabase/scenarios/admin/settings/localization.cy.spec.js
@@ -23,8 +23,10 @@ describe("scenarios > admin > permissions", () => {
           query: {
             "source-table": 2,
             aggregation: [["count"]],
-            breakout: [["datetime-field", ORDERS.CREATED_AT, "week"]],
-            filter: ["<", ORDERS.CREATED_AT, "2016-06-01"],
+            breakout: [
+              ["datetime-field", ["field-id", ORDERS.CREATED_AT], "week"],
+            ],
+            filter: ["<", ["field-id", ORDERS.CREATED_AT], "2016-06-01"],
           },
           type: "query",
         },
diff --git a/frontend/test/metabase/scenarios/dashboard/dashboard-drill.cy.spec.js b/frontend/test/metabase/scenarios/dashboard/dashboard-drill.cy.spec.js
index 01cd4e93067..dee14477547 100644
--- a/frontend/test/metabase/scenarios/dashboard/dashboard-drill.cy.spec.js
+++ b/frontend/test/metabase/scenarios/dashboard/dashboard-drill.cy.spec.js
@@ -178,85 +178,85 @@ describe("scenarios > dashboard > dashboard drill", () => {
       cy.request("PUT", `/api/field/${REVIEWS.RATING}`, {
         special_type: "type/Category",
       });
-    });
-    // 2. create a question based on Reviews
-    cy.request("POST", `/api/card`, {
-      name: "13062Q",
-      dataset_query: {
-        database: 1,
-        query: {
-          "source-table": 4,
+      // 2. create a question based on Reviews
+      cy.request("POST", `/api/card`, {
+        name: "13062Q",
+        dataset_query: {
+          database: 1,
+          query: {
+            "source-table": 4,
+          },
+          type: "query",
         },
-        type: "query",
-      },
-      display: "table",
-      visualization_settings: {},
-    }).then(({ body: { id: questionId } }) => {
-      // 3. create a dashboard
-      cy.request("POST", "/api/dashboard", {
-        name: "13062D",
-      }).then(({ body: { id: dashboardId } }) => {
-        // add filter to the dashboard
-        cy.request("PUT", `/api/dashboard/${dashboardId}`, {
-          parameters: [
-            {
-              id: "18024e69",
-              name: "Category",
-              slug: "category",
-              type: "category",
-            },
-          ],
-        });
-
-        // add previously created question to the dashboard
-        cy.request("POST", `/api/dashboard/${dashboardId}/cards`, {
-          cardId: questionId,
-        }).then(({ body: { id: dashCardId } }) => {
-          // connect filter to that question
-          cy.request("PUT", `/api/dashboard/${dashboardId}/cards`, {
-            cards: [
+        display: "table",
+        visualization_settings: {},
+      }).then(({ body: { id: questionId } }) => {
+        // 3. create a dashboard
+        cy.request("POST", "/api/dashboard", {
+          name: "13062D",
+        }).then(({ body: { id: dashboardId } }) => {
+          // add filter to the dashboard
+          cy.request("PUT", `/api/dashboard/${dashboardId}`, {
+            parameters: [
               {
-                id: dashCardId,
-                card_id: questionId,
-                row: 0,
-                col: 0,
-                sizeX: 8,
-                sizeY: 6,
-                parameter_mappings: [
-                  {
-                    parameter_id: "18024e69",
-                    card_id: questionId,
-                    target: ["dimension", ["field-id", 31]], // 31 = REVIEWS.RATING
-                  },
-                ],
+                id: "18024e69",
+                name: "Category",
+                slug: "category",
+                type: "category",
               },
             ],
           });
-        });
 
-        // NOTE: The actual "Assertion" phase begins here
-        cy.log("**Reported failing on Metabase 1.34.3 and 0.36.2**");
+          // add previously created question to the dashboard
+          cy.request("POST", `/api/dashboard/${dashboardId}/cards`, {
+            cardId: questionId,
+          }).then(({ body: { id: dashCardId } }) => {
+            // connect filter to that question
+            cy.request("PUT", `/api/dashboard/${dashboardId}/cards`, {
+              cards: [
+                {
+                  id: dashCardId,
+                  card_id: questionId,
+                  row: 0,
+                  col: 0,
+                  sizeX: 8,
+                  sizeY: 6,
+                  parameter_mappings: [
+                    {
+                      parameter_id: "18024e69",
+                      card_id: questionId,
+                      target: ["dimension", ["field-id", REVIEWS.RATING]],
+                    },
+                  ],
+                },
+              ],
+            });
+          });
 
-        cy.log("**The first case**");
-        // set filter values (ratings 5 and 4) directly through the URL
-        cy.visit(`/dashboard/${dashboardId}?category=5&category=4`);
+          // NOTE: The actual "Assertion" phase begins here
+          cy.log("**Reported failing on Metabase 1.34.3 and 0.36.2**");
 
-        // drill-through
-        cy.findByText("xavier").click();
-        cy.findByText("=").click();
+          cy.log("**The first case**");
+          // set filter values (ratings 5 and 4) directly through the URL
+          cy.visit(`/dashboard/${dashboardId}?category=5&category=4`);
 
-        cy.findByText("Reviewer is xavier");
-        cy.findByText("Rating is equal to 2 selections");
-        cy.contains("Reprehenderit non error"); // xavier's review
+          // drill-through
+          cy.findByText("xavier").click();
+          cy.findByText("=").click();
 
-        cy.log("**The second case**");
-        // go back to the dashboard
-        cy.visit(`/dashboard/${dashboardId}?category=5&category=4`);
-        cy.findByText("2 selections");
+          cy.findByText("Reviewer is xavier");
+          cy.findByText("Rating is equal to 2 selections");
+          cy.contains("Reprehenderit non error"); // xavier's review
 
-        cy.findByText("13062Q").click(); // the card title
-        cy.findByText("Rating is equal to 2 selections");
-        cy.contains("Ad perspiciatis quis et consectetur."); // 5 star review
+          cy.log("**The second case**");
+          // go back to the dashboard
+          cy.visit(`/dashboard/${dashboardId}?category=5&category=4`);
+          cy.findByText("2 selections");
+
+          cy.findByText("13062Q").click(); // the card title
+          cy.findByText("Rating is equal to 2 selections");
+          cy.contains("Ad perspiciatis quis et consectetur."); // 5 star review
+        });
       });
     });
   });
diff --git a/frontend/test/metabase/scenarios/dashboard/dashboard.cy.spec.js b/frontend/test/metabase/scenarios/dashboard/dashboard.cy.spec.js
index dece99dfc9c..f6d68403089 100644
--- a/frontend/test/metabase/scenarios/dashboard/dashboard.cy.spec.js
+++ b/frontend/test/metabase/scenarios/dashboard/dashboard.cy.spec.js
@@ -116,13 +116,21 @@ describe("scenarios > dashboard", () => {
           filter: [">", ["field-literal", "sum", "type/Float"], 100],
           query: {
             "source-table": 2,
-            aggregation: [["sum", ORDERS.TOTAL]],
+            aggregation: [["sum", ["field-id", ORDERS.TOTAL]]],
             breakout: [
-              ["datetime-field", ORDERS.CREATED_AT, "day"],
-              ["fk->", ORDERS.PRODUCT_ID, PRODUCTS.ID],
-              ["fk->", ORDERS.PRODUCT_ID, PRODUCTS.CATEGORY],
+              ["datetime-field", ["field-id", ORDERS.CREATED_AT], "day"],
+              [
+                "fk->",
+                ["field-id", ORDERS.PRODUCT_ID],
+                ["field-id", PRODUCTS.ID],
+              ],
+              [
+                "fk->",
+                ["field-id", ORDERS.PRODUCT_ID],
+                ["field-id", PRODUCTS.CATEGORY],
+              ],
             ],
-            filter: ["=", ORDERS.USER_ID, 1],
+            filter: ["=", ["field-id", ORDERS.USER_ID], 1],
           },
           type: "query",
         },
diff --git a/frontend/test/metabase/scenarios/question/nested.cy.spec.js b/frontend/test/metabase/scenarios/question/nested.cy.spec.js
index 5a414ab1bb0..8d05e892de8 100644
--- a/frontend/test/metabase/scenarios/question/nested.cy.spec.js
+++ b/frontend/test/metabase/scenarios/question/nested.cy.spec.js
@@ -14,7 +14,9 @@ describe("scenarios > question > nested (metabase#12568)", () => {
           query: {
             "source-table": 2,
             aggregation: [["count"]],
-            breakout: [["datetime-field", ORDERS.CREATED_AT, "week"]],
+            breakout: [
+              ["datetime-field", ["field-id", ORDERS.CREATED_AT], "week"],
+            ],
           },
           type: "query",
         },
diff --git a/frontend/test/metabase/scenarios/question/nulls.cy.spec.js b/frontend/test/metabase/scenarios/question/nulls.cy.spec.js
index 66fb337a856..894b36096a9 100644
--- a/frontend/test/metabase/scenarios/question/nulls.cy.spec.js
+++ b/frontend/test/metabase/scenarios/question/nulls.cy.spec.js
@@ -18,8 +18,8 @@ describe("scenarios > question > null", () => {
           database: 1,
           query: {
             "source-table": 2,
-            fields: [ORDERS.DISCOUNT],
-            filter: ["=", ORDERS.ID, 1],
+            fields: [["field-id", ORDERS.DISCOUNT]],
+            filter: ["=", ["field-id", ORDERS.ID], 1],
           },
           type: "query",
         },
@@ -32,7 +32,8 @@ describe("scenarios > question > null", () => {
       cy.findByText("13571").click();
 
       cy.log("**'No Results since at least v0.34.3**");
-      cy.findByText("No results!").should("not.exist");
+      cy.findByText("Discount");
+      cy.findByText("Empty");
     });
   });
 
-- 
GitLab