Merge pull request #13098 from guerler/history_refactor_000

Avoid imports of history provider internals
This commit is contained in:
Marius van den Beek
2022-01-14 15:23:58 +01:00
committed by GitHub
19 changed files with 14 additions and 127 deletions
@@ -9,8 +9,6 @@ import flushPromises from "flush-promises";
const localVue = getLocalVue();
jest.mock("components/providers/History/caching");
function buildWrapper(conversion_disable = false) {
return mount(DatasetAttributes, {
propsData: {
@@ -7,7 +7,6 @@ import datasetResponse from "./testData/datasetResponse";
import flushPromises from "flush-promises";
import moment from "moment";
jest.mock("components/providers/History/caching");
const HDA_ID = "FOO_HDA_ID";
const mockDatasetProvider = {
@@ -21,7 +20,7 @@ const mockDatasetProvider = {
const localVue = getLocalVue();
describe("DatasetInformation/DatasetInformation.vue", () => {
describe("DatasetInformation/DatasetInformation", () => {
let wrapper;
let datasetInfoTable;
let axiosMock;
@@ -5,8 +5,6 @@ import flushPromises from "flush-promises";
import datasetCollectionRaw from "components/providers/History/test/json/DatasetCollection.json";
import datasetCollectionContent from "components/providers/History/test/json/DatasetCollection.nested.json";
jest.mock("components/providers/History/caching");
describe("DatasetUIWrapper.vue with Dataset", () => {
let wrapper;
let propsData;
@@ -3,8 +3,6 @@ import DatasetUI from "components/History/ContentItem/Dataset/DatasetUI";
import { shallowMount } from "@vue/test-utils";
import raw from "components/providers/History/test/json/Dataset.json";
jest.mock("components/providers/History/caching");
describe("DatasetUIWrapper.vue with Dataset", () => {
let wrapper;
let propsData;
+13 -71
View File
@@ -109,9 +109,8 @@ export async function getHistoryById(id, since) {
/**
* Create new history
* @param {Object} props Optional history props
*/
export async function createNewHistory(props = {}) {
export async function createNewHistory() {
// TODO: adjust api, keep this for later
// const url = `/histories`;
// const data = Object.assign({ name: "New History" }, props);
@@ -158,16 +157,6 @@ export async function deleteHistoryById(id, purge = false) {
return doResponse(response);
}
/**
* Undelete a deleted (but not purged) history
* @param {String} id Encoded history id
*/
export async function undeleteHistoryById(id) {
const url = `/histories/deleted/${id}/undelete`;
const response = await api.post(url, null, { params: stdHistoryParams });
return doResponse(response);
}
/**
* Update specific fields in history
* @param {Object} history
@@ -199,10 +188,9 @@ export async function secureHistory(history) {
return await getHistoryById(id);
}
// #endregion
// #region "Current History"
/**
* Content Current History
*/
export async function getCurrentHistoryFromServer() {
const url = "/history/current_history_json";
const response = await api.get(url, {
@@ -223,31 +211,9 @@ export async function setCurrentHistoryOnServer(history_id) {
return doResponse(response);
}
// #endregion
// #region Content Queries
/**
* Loads specific fields for provided content object, handy for loading
* visualizations or any other field that's too unwieldy to reasonably include
* in the standard content caching cycle.
*
* @param {Object} content content object
* @param {Array} fields Array of fields to load
* Content Queries
*/
export async function loadContentFields(content, fields = []) {
if (fields.length) {
const { history_id, id, history_content_type: type } = content;
const url = `/histories/${history_id}/contents/${type}s/${id}`;
const params = { keys: fields.join(",") };
const response = await api.get(url, { params });
if (response.status != 200) {
throw new Error(response);
}
return response.data;
}
return null;
}
/**
* Generic content query function originally intended to help with bulk updates
@@ -307,27 +273,6 @@ export async function updateContentFields(content, newFields = {}) {
return doResponse(response);
}
/**
* Undeletes content flagged as deleted.
* @param {Object} content
*/
export async function undeleteContent(content) {
return await updateContentFields(content, {
deleted: false,
});
}
/**
* Marks as purged
* @param {*} history
* @param {*} content
*/
export async function purgeContent(history, content) {
const url = `/histories/${history.id}/contents/${content.id}?purge=True`;
const response = await api.delete(url);
return doResponse(response);
}
/**
* Bulk update endpoint (TODO: rewrite)
*
@@ -349,9 +294,9 @@ export async function bulkContentUpdate(history, type_ids = [], fields = {}) {
return doResponse(response);
}
// #endregion
// #region Collections
/**
* Collections
*/
export async function createDatasetCollection(history, inputs = {}) {
const defaults = {
@@ -377,14 +322,13 @@ export async function deleteDatasetCollection(collection, recursive = false, pur
return doResponse(response);
}
// #endregion
// #region Job Queries
/**
* Job Queries
*/
const jobStash = new Map();
const toolStash = new Map();
export async function loadJobById(jobId) {
async function loadJobById(jobId) {
if (!jobStash.has(jobId)) {
const url = `/jobs/${jobId}?full=false`;
const response = await api.get(url);
@@ -394,7 +338,7 @@ export async function loadJobById(jobId) {
return jobStash.get(jobId);
}
export async function loadToolForJob(job) {
async function loadToolForJob(job) {
const { tool_id, history_id } = job;
const key = `${tool_id}-${history_id}`;
if (!toolStash.has(key)) {
@@ -410,5 +354,3 @@ export async function loadToolFromJob(jobId) {
const job = await loadJobById(jobId);
return await loadToolForJob(job);
}
// #endregion
@@ -4,8 +4,6 @@ import { getLocalVue } from "jest/helpers";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
jest.mock("components/providers/History/caching");
const TEST_PLUGINS_URL = "/api/remote_files/plugins";
const localVue = getLocalVue();
@@ -12,7 +12,6 @@ const TEST_EXPORTS_URL = `/api/histories/${TEST_HISTORY_ID}/exports`;
const TEST_JOB_ID = "test1234job";
jest.mock("components/JobStates/wait");
jest.mock("components/providers/History/caching");
describe("ToLink.vue", () => {
let axiosMock;
@@ -12,7 +12,6 @@ const TEST_JOB_ID = "job123789";
const TEST_EXPORTS_URL = `/api/histories/${TEST_HISTORY_ID}/exports`;
jest.mock("components/JobStates/wait");
jest.mock("components/providers/History/caching");
describe("ToRemoteFile.vue", () => {
let axiosMock;
@@ -13,7 +13,6 @@ const TEST_SOURCE_URL = "http://galaxy.example/import";
const TEST_PLUGINS_URL = "/api/remote_files/plugins";
jest.mock("components/JobStates/wait");
jest.mock("components/providers/History/caching");
describe("HistoryImport.vue", () => {
let axiosMock;
@@ -11,7 +11,6 @@ import flushPromises from "flush-promises";
import createCache from "vuex-cache";
jest.mock("app");
jest.mock("components/providers/History/caching");
const JOB_ID = "test_id";
@@ -1,7 +1,6 @@
import JobOutputs from "./JobOutputs";
import { shallowMount } from "@vue/test-utils";
jest.mock("components/providers/History/caching");
jest.mock("components/providers/DatasetCollectionProvider");
describe("JobInformation/JobOutputs.vue", () => {
@@ -9,7 +9,6 @@ import raw from "components/providers/History/test/json/Dataset.json";
import { userStore } from "store/userStore";
import { configStore } from "store/configStore";
jest.mock("components/providers/History/caching");
const observe = jest.fn();
const unobserve = jest.fn();
@@ -8,7 +8,6 @@ import { loadWebhookMenuItems } from "./_webhooks";
jest.mock("app");
jest.mock("layout/menu");
jest.mock("./_webhooks");
jest.mock("components/providers/History/caching");
describe("Masthead.vue", () => {
let wrapper;
@@ -10,7 +10,6 @@ import MockCurrentUser from "../providers/MockCurrentUser";
import MockCurrentHistory from "components/providers/History/UserHistories/MockCurrentHistory";
jest.mock("app");
jest.mock("components/providers/History/caching");
const propsData = {
chunkUploadSize: 1024,
@@ -5,7 +5,6 @@ import flushPromises from "flush-promises";
import RecentInvocations from "./RecentInvocations.vue";
jest.mock("components/providers/History/caching");
jest.mock("./UserServices");
const localVue = getLocalVue();
@@ -4,8 +4,6 @@ import { getLocalVue } from "jest/helpers";
import invocationData from "./test/json/invocation.json";
import moment from "moment";
jest.mock("components/providers/History/caching");
const localVue = getLocalVue();
describe("Invocations.vue without invocation", () => {
@@ -3,8 +3,6 @@ import JobStep from "./JobStep";
import { mount } from "@vue/test-utils";
import jobs from "./test/json/jobs.json";
jest.mock("components/providers/History/caching");
import { createLocalVue } from "@vue/test-utils";
// create an extended `Vue` constructor
@@ -10,7 +10,6 @@ const invocationJobsSummaryById = {
states: {},
populated_state: "ok",
};
jest.mock("components/providers/History/caching");
const localVue = getLocalVue();
@@ -16,35 +16,3 @@ export {
} from "./CacheApi";
export { wipeDatabase, clearHistoryDateStore } from "./CacheApi";
// TODO: The above exports bypass the worker completely for now, swap back to below to use.
//import { toPromise, toOperator } from "./workerClient";
///**
// * monitor cache for changes
// */
//export const monitorContentQuery = toOperator("monitorContentQuery");
//export const monitorDscQuery = toOperator("monitorDscQuery");
//export const monitorHistoryContent = toOperator("monitorHistoryContent");
//export const monitorCollectionContent = toOperator("monitorCollectionContent");
//
///**
// * Loaders
// */
//export const loadHistoryContents = toOperator("loadHistoryContents");
//export const loadDscContent = toOperator("loadDscContent");
//
///**
// * Cache promise functions
// */
//export const cacheContent = toPromise("cacheContent");
//export const getCachedContent = toPromise("getCachedContent");
//export const uncacheContent = toPromise("uncacheContent");
//export const bulkCacheContent = toPromise("bulkCacheContent");
//export const cacheCollectionContent = toPromise("cacheCollectionContent");
//export const getCachedCollectionContent = toPromise("getCachedCollectionContent");
//export const bulkCacheDscContent = toPromise("bulkCacheDscContent");
//export const getContentByTypeId = toPromise("getContentByTypeId");
//
//// Debugging
//export const wipeDatabase = toPromise("wipeDatabase");
//export const clearHistoryDateStore = toPromise("clearHistoryDateStore");