diff --git a/e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts b/e2e-tests/001-sanity-tests/002-create-new-collection-and-new-request.spec.ts similarity index 100% rename from e2e-tests/001-sanity-tests/002-create-new-collection.spec.ts rename to e2e-tests/001-sanity-tests/002-create-new-collection-and-new-request.spec.ts diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 9367b2aa7..188f22b6d 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -59,13 +59,21 @@ const envHasSecrets = (environment = {}) => { return secrets && secrets.length > 0; }; -const validatePathIsInsideCollection = (path) => { +const validatePathIsInsideCollection = (filePath, lastOpenedCollections) => { const openCollectionPaths = collectionWatcher.getAllWatcherPaths(); - const isValid = openCollectionPaths.some((collectionPath) => { - return path.startsWith(collectionPath); + const lastOpenedPaths = lastOpenedCollections ? lastOpenedCollections.getAll() : []; + + // Combine both currently watched collections and last opened collections + // todo: remove the lastOpenedPaths from the list + // todo: have a proper way to validate the path without the active watcher logic + const allCollectionPaths = [...new Set([...openCollectionPaths, ...lastOpenedPaths])]; + + const isValid = allCollectionPaths.some((collectionPath) => { + return filePath.startsWith(collectionPath + path.sep) || filePath === collectionPath; }); + if (!isValid) { - throw new Error(`Path: ${path} should be inside a collection`); + throw new Error(`Path: ${filePath} should be inside a collection`); } } @@ -247,7 +255,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection if (!validateName(request?.filename)) { throw new Error(`${request.filename}.bru is not a valid filename`); } - validatePathIsInsideCollection(pathname); + validatePathIsInsideCollection(pathname, lastOpenedCollections); const content = await jsonToBruViaWorker(request); await writeFile(pathname, content); } catch (error) {