diff --git a/frontend/test/__support__/integrated_tests.js b/frontend/test/__support__/integrated_tests.js index cf2519bc2329254e3705d0c9f39178e59c6155eb..04f9a7895e7f2b56dccd804f35174ae84135e2f4 100644 --- a/frontend/test/__support__/integrated_tests.js +++ b/frontend/test/__support__/integrated_tests.js @@ -581,24 +581,17 @@ export const eventually = async (assertion, timeout = 5000, period = 250) => { // }) // afterAll(cleanup); // -export const cleanup = async () => { +export const cleanup = () => { useSharedAdminLogin(); - try { - await Promise.all( - cleanup.actions.splice(0, cleanup.actions.length).map(action => action()), - ); - } catch (e) { - console.warn("CLEANUP FAILED", e); - throw e; - } + Promise.all( + cleanup.actions.splice(0, cleanup.actions.length).map(action => action()), + ); }; cleanup.actions = []; cleanup.fn = action => cleanup.actions.push(action); cleanup.metric = metric => cleanup.fn(() => deleteMetric(metric)); cleanup.segment = segment => cleanup.fn(() => deleteSegment(segment)); cleanup.question = question => cleanup.fn(() => deleteQuestion(question)); -cleanup.collection = collection => - cleanup.fn(() => deleteCollection(collection)); export const deleteQuestion = question => CardApi.delete({ cardId: getId(question) }); @@ -606,8 +599,6 @@ export const deleteSegment = segment => SegmentApi.delete({ segmentId: getId(segment), revision_message: "Please" }); export const deleteMetric = metric => MetricApi.delete({ metricId: getId(metric), revision_message: "Please" }); -export const deleteCollection = collection => - CollectionsApi.update({ id: getId(collection), archived: true }); const getId = o => typeof o === "object" && o != null diff --git a/frontend/test/alert/alert.integ.spec.js b/frontend/test/alert/alert.integ.spec.js index 46c636fa04c9d96a1d21bceabaee578e3b5e127b..583bf029b1457a2576e44c351625ab68676e9c5f 100644 --- a/frontend/test/alert/alert.integ.spec.js +++ b/frontend/test/alert/alert.integ.spec.js @@ -5,14 +5,19 @@ import { forBothAdminsAndNormalUsers, useSharedAdminLogin, useSharedNormalLogin, - cleanup, } from "__support__/integrated_tests"; import { click, clickButton } from "__support__/enzyme_utils"; import { fetchTableMetadata } from "metabase/redux/metadata"; import { mount } from "enzyme"; import { setIn } from "icepick"; -import { AlertApi, PulseApi, UserApi } from "metabase/services"; +import { + AlertApi, + CardApi, + PulseApi, + UserApi, + CollectionsApi, +} from "metabase/services"; import Question from "metabase-lib/lib/Question"; import * as Urls from "metabase/lib/urls"; import { INITIALIZE_QB, QUERY_COMPLETED } from "metabase/query_builder/actions"; @@ -83,6 +88,7 @@ const initQbWithAlertMenuItemClicked = async ( }; describe("Alerts", () => { + let collection = null; let rawDataQuestion = null; let timeSeriesQuestion = null; let timeSeriesWithGoalQuestion = null; @@ -95,7 +101,7 @@ describe("Alerts", () => { const store = await createTestStore(); // create a collection which all users have write permissions in - const collection = await createAllUsersWritableCollection(); + collection = await createAllUsersWritableCollection(); // table metadata is needed for `Question.alertType()` calls await store.dispatch(fetchTableMetadata(1)); @@ -109,7 +115,6 @@ describe("Alerts", () => { .setDisplayName("Just raw, untamed data") .setCollectionId(collection.id), ); - cleanup.question(rawDataQuestion); timeSeriesQuestion = await createSavedQuestion( Question.create({ databaseId: 1, tableId: 1, metadata }) @@ -125,7 +130,6 @@ describe("Alerts", () => { .setDisplayName("Time series line") .setCollectionId(collection.id), ); - cleanup.question(timeSeriesQuestion); timeSeriesWithGoalQuestion = await createSavedQuestion( Question.create({ databaseId: 1, tableId: 1, metadata }) @@ -143,7 +147,6 @@ describe("Alerts", () => { .setDisplayName("Time series line with goal") .setCollectionId(collection.id), ); - cleanup.question(timeSeriesWithGoalQuestion); timeMultiSeriesWithGoalQuestion = await createSavedQuestion( Question.create({ databaseId: 1, tableId: 1, metadata }) @@ -162,7 +165,6 @@ describe("Alerts", () => { .setDisplayName("Time multiseries line with goal") .setCollectionId(collection.id), ); - cleanup.question(timeMultiSeriesWithGoalQuestion); progressBarQuestion = await createSavedQuestion( Question.create({ databaseId: 1, tableId: 1, metadata }) @@ -174,12 +176,16 @@ describe("Alerts", () => { .setDisplayName("Progress bar question") .setCollectionId(collection.id), ); - cleanup.question(progressBarQuestion); - - cleanup.collection(collection); }); - afterAll(cleanup); + afterAll(async () => { + await CardApi.delete({ cardId: rawDataQuestion.id() }); + await CardApi.delete({ cardId: timeSeriesQuestion.id() }); + await CardApi.delete({ cardId: timeSeriesWithGoalQuestion.id() }); + await CardApi.delete({ cardId: timeMultiSeriesWithGoalQuestion.id() }); + await CardApi.delete({ cardId: progressBarQuestion.id() }); + await CollectionsApi.update({ id: collection.id, archived: true }); + }); describe("missing email/slack credentials", () => { forBothAdminsAndNormalUsers(() => {