Skip to content
Snippets Groups Projects
Unverified Commit 27fdb4aa authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

Custom Table E2E Tests 4: Allow reusable multi-dialect schema reset (#27987)

parent 1752daa3
No related branches found
No related tags found
No related merge requests found
import Knex from "knex";
import { WRITABLE_DB_CONFIG } from "./cypress_data";
import * as testTables from "./test_tables";
const dbClients = {};
......@@ -28,3 +30,9 @@ export async function connectAndQueryDB({ connectionConfig, query }) {
return result;
}
}
export async function resetTable({ type = "postgres", table = "testTable1" }) {
const dbClient = getDbClient(WRITABLE_DB_CONFIG[type]);
// eslint-disable-next-line import/namespace
return testTables?.[table]?.(dbClient);
}
......@@ -172,6 +172,10 @@ export function queryWritableDB(query, type = "postgres") {
});
}
export function resetTestTable({ type, table }) {
cy.task("resetTable", { type, table });
}
// will this work for multiple schemas?
export function getTableId({ databaseId = WRITABLE_DB_ID, name }) {
return cy
......
// define test schema such that they can be used in multiple SQL dialects using
// knex's schema builder https://knexjs.org/guide/schema-builder.html
// we cannot use knex to define multi-dialect schemas because we can only pass
// json-serializable data to cypress tasks (which run in node)
// https://docs.cypress.io/api/commands/task#Arguments
export const colors27745 = async dbClient => {
const tableName = "colors27745";
await dbClient.schema.dropTableIfExists(tableName);
await dbClient.schema.createTable(tableName, table => {
table.increments("id").primary();
table.string("name").unique().notNullable();
});
await dbClient(tableName).insert([
{ name: "red" },
{ name: "green" },
{ name: "blue" },
]);
return true;
};
......@@ -4,52 +4,25 @@ import {
enterCustomColumnDetails,
visualize,
popover,
queryQADB,
resetTestTable,
} from "__support__/e2e/helpers";
const createTableQueries = {
postgres: `
DROP TABLE IF EXISTS colors;
CREATE TABLE colors (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
color VARCHAR ( 255 ) UNIQUE NOT NULL
);
INSERT INTO colors (color) VALUES ('red'), ('green'), ('blue');
`,
mysql: `
DROP TABLE IF EXISTS colors;
CREATE TABLE colors (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
color VARCHAR ( 255 ) UNIQUE NOT NULL
);
INSERT INTO colors (color) VALUES ('red'), ('green'), ('blue');
`,
};
const snapshotMap = {
postgres: "postgres-12",
mysql: "mysql-8",
};
["postgres", "mysql"].forEach(dialect => {
describe.skip(`issue 27745 (${dialect})`, { tags: "@external" }, () => {
const tableName = "colors27745";
beforeEach(() => {
restore(snapshotMap[dialect]);
restore(`${dialect}-writable`);
cy.signInAsAdmin();
queryQADB(createTableQueries[dialect], dialect);
resetTestTable({ type: dialect, table: tableName });
cy.request("POST", "/api/database/2/sync_schema");
});
it("should display all summarize options if the only numeric field is a custom column (metabase#27745)", () => {
startNewQuestion();
cy.findByText(/QA/i).click();
cy.findByText("Colors").click();
cy.findByText(/Writable/i).click();
cy.findByText(/colors/i).click();
cy.icon("add_data").click();
enterCustomColumnDetails({
formula: "case([ID] > 1, 25, 5)",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment