Skip to content
Snippets Groups Projects
Unverified Commit 20c6fccc authored by Uladzimir Havenchyk's avatar Uladzimir Havenchyk Committed by GitHub
Browse files

[jest] Add global catch for unmocked http requests (#34277)

parent b0cd79de
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,10 @@ import {
import { setupEnterpriseTest } from "__support__/enterprise";
import { mockSettings } from "__support__/settings";
import type { CollectionEndpoints } from "__support__/server-mocks";
import { setupCollectionsEndpoints } from "__support__/server-mocks";
import {
setupCollectionsEndpoints,
setupCollectionByIdEndpoint,
} from "__support__/server-mocks";
import {
createMockQueryBuilderState,
createMockState,
......@@ -35,27 +38,24 @@ const metadata = createMockMetadata({
databases: [createSampleDatabase()],
});
const TEST_COLLECTIONS = [
{
can_write: false,
effective_ancestors: [],
effective_location: null,
id: "root",
name: "Our analytics",
parent_id: null,
},
{
archived: false,
can_write: true,
description: null,
id: 1,
location: "/",
name: "Bobby Tables's Personal Collection",
namespace: null,
personal_owner_id: 100,
slug: "bobby_tables_s_personal_collection",
},
];
const BOBBY_TEST_COLLECTION = createMockCollection({
archived: false,
can_write: true,
description: null,
id: 1,
location: "/",
name: "Bobby Tables's Personal Collection",
personal_owner_id: 100,
});
const ROOT_TEST_COLLECTION = createMockCollection({
...ROOT_COLLECTION,
can_write: false,
effective_ancestors: [],
id: "root",
});
const TEST_COLLECTIONS = [ROOT_TEST_COLLECTION, BOBBY_TEST_COLLECTION];
const setup = async (
question: Question,
......@@ -76,7 +76,8 @@ const setup = async (
setupCollectionsEndpoints(collectionEndpoints);
} else {
fetchMock.get("path:/api/collection", TEST_COLLECTIONS);
fetchMock.get("path:/api/collection/root", TEST_COLLECTIONS);
fetchMock.get("path:/api/collection/root", ROOT_TEST_COLLECTION);
setupCollectionByIdEndpoint({ collections: [BOBBY_TEST_COLLECTION] });
}
const settings = mockSettings({ "enable-query-caching": isCachingEnabled });
......@@ -714,6 +715,7 @@ describe("SaveQuestionModal", () => {
rootCollection: COLLECTION.ROOT,
},
});
setupCollectionByIdEndpoint({ collections: [COLLECTION.PARENT] });
});
it("should create collection inside nested folder", async () => {
......
......@@ -111,7 +111,9 @@ function ModelDetailPage({
const card = model.card();
const isModel = model.isDataset();
if (isModel) {
loadMetadataForCard(card);
if (model.database()) {
loadMetadataForCard(card);
}
} else {
onChangeLocation(Urls.question(card));
}
......
......@@ -2,4 +2,12 @@ import fetchMock from "fetch-mock";
beforeEach(() => {
fetchMock.restore();
fetchMock.catch((url, request) => {
const errorMessage = `Caught unmocked ${request.method} request to: ${url}`;
Promise.reject(errorMessage);
// consider all not mocked requests are broken
return 500;
});
});
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