fix/collection export import (#2601)

* pr review changes

* collection root object in export json

* import environment updates

* tests run execution order fix for collection runs

* headers schema update, export only required parts of request

* update auth in object spread

* docs not present in folder level settings

* docs not present in folder level settings

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
lohit 2024-07-10 11:21:58 +05:30 committed by GitHub
parent e5425299a2
commit 58c8085a64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 101 additions and 30 deletions

View File

@ -383,17 +383,51 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
if (si.type == 'folder' && si?.root) {
di.root = {
request: {
headers: si?.root?.request?.headers,
script: si?.root?.request?.script,
vars: si?.root?.request?.vars,
tests: si?.root?.request?.tests
},
docs: si?.root?.request?.docs,
meta: {
name: si?.root?.meta?.name
}
request: {}
};
let { request, meta } = si?.root || {};
let { headers, script, vars, tests } = request || {};
// folder level headers
if (headers?.length) {
di.root.request.headers = headers;
}
// folder level script
if (Object.keys(script)?.length) {
di.root.request.script = {};
if (script?.req?.length) {
di.root.request.script.req = script?.req;
}
if (script?.res?.length) {
di.root.request.script.res = script?.res;
}
}
// folder level vars
if (Object.keys(vars)?.length) {
di.root.request.vars = {};
if (vars?.req?.length) {
di.root.request.vars.req = vars?.req;
}
if (vars?.res?.length) {
di.root.request.vars.res = vars?.res;
}
}
// folder level tests
if (tests?.length) {
di.root.request.tests = tests;
}
if (meta?.name) {
di.root.meta = {};
di.root.meta.name = meta?.name;
}
if (!Object.keys(di.root.request)?.length) {
delete di.root.request;
}
if (!Object.keys(di.root)?.length) {
delete di.root;
}
}
if (si.type === 'js') {
@ -418,24 +452,59 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
collectionToSave.items = [];
collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid;
collectionToSave.environments = collection.environments || [];
collectionToSave.root = {
request: {
auth: collection?.root?.request?.auth,
headers: collection?.root?.request?.headers,
script: collection?.root?.request?.script,
vars: collection?.root?.request?.vars,
tests: collection?.root?.request?.tests
},
docs: collection?.root?.request?.docs,
meta: {
name: collection?.root?.meta?.name || collection?.name
}
request: {}
};
if (!collection?.root?.request?.auth?.mode) {
collectionToSave.root.request.auth = {
mode: 'none'
};
let { request, docs, meta } = collection?.root || {};
let { auth, headers, script, vars, tests } = request || {};
// collection level auth
if (auth?.mode) {
collectionToSave.root.request.auth = auth;
}
// collection level headers
if (headers?.length) {
collectionToSave.root.request.headers = headers;
}
// collection level script
if (Object.keys(script)?.length) {
collectionToSave.root.request.script = {};
if (script?.req?.length) {
collectionToSave.root.request.script.req = script?.req;
}
if (script?.res?.length) {
collectionToSave.root.request.script.res = script?.res;
}
}
// collection level vars
if (Object.keys(vars)?.length) {
collectionToSave.root.request.vars = {};
if (vars?.req?.length) {
collectionToSave.root.request.vars.req = vars?.req;
}
if (vars?.res?.length) {
collectionToSave.root.request.vars.res = vars?.res;
}
}
// collection level tests
if (tests?.length) {
collectionToSave.root.request.tests = tests;
}
// collection level docs
if (docs?.length) {
collectionToSave.root.docs = docs;
}
if (meta?.name) {
collectionToSave.root.meta = {};
collectionToSave.root.meta.name = meta?.name;
}
if (!Object.keys(collectionToSave.root.request)?.length) {
delete collectionToSave.root.request;
}
if (!Object.keys(collectionToSave.root)?.length) {
delete collectionToSave.root;
}
collectionToSave.brunoConfig = cloneDeep(collection?.brunoConfig);

View File

@ -1030,8 +1030,8 @@ const registerNetworkIpc = (mainWindow) => {
// run tests
const testFile = compact([
get(collectionRoot, 'request.tests'),
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests')
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
get(collectionRoot, 'request.tests')
]).join(os.EOL);
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();

View File

@ -188,7 +188,8 @@ const authSchema = Yup.object({
oauth2: oauth2Schema.nullable()
})
.noUnknown(true)
.strict();
.strict()
.nullable();
const requestParamsSchema = Yup.object({
uid: uidSchema,
@ -233,14 +234,15 @@ const requestSchema = Yup.object({
const folderRootSchema = Yup.object({
request: Yup.object({
headers: Yup.array().of(keyValueSchema),
headers: Yup.array().of(keyValueSchema).nullable(),
auth: authSchema,
script: Yup.object({
req: Yup.string().nullable(),
res: Yup.string().nullable()
})
.noUnknown(true)
.strict(),
.strict()
.nullable(),
vars: Yup.object({
req: Yup.array().of(varsSchema).nullable(),
res: Yup.array().of(varsSchema).nullable()