From dec51914911c10b66b43ebe95f77b0af63e2d03e Mon Sep 17 00:00:00 2001 From: YuryShkoda Date: Tue, 14 Jul 2026 11:32:01 +0300 Subject: [PATCH] fix(api): isolate drive.spec.ts's files folder from the real drive drive.spec.ts already isolates itself into a unique, timestamped tmpFolder for getSasjsRootFolder()/getUploadsFolder(), cleaned up via afterAll(() => deleteFolder(tmpFolder)). But getFilesFolder() - what nearly every test in this file actually writes to - resolves through a separate, unmocked function (getSasjsDriveFolder()/process.driveLoc), so every run left real files/folders (e.g. 'level1', 'my/path/...') behind in the shared api/sasjs_root/drive/files, causing later runs to fail: folder-listing tests saw stale entries, and file-creation tests got 409 Conflict against files a previous run already created. Mock getFilesFolder() the same way getUploadsFolder() already is, so it resolves inside the same isolated tmpFolder and gets cleaned up by the existing afterAll. Verified by running the suite twice in a row from a clean slate: both runs pass, and the real sasjs_root/drive is never touched. --- api/src/routes/api/spec/drive.spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/src/routes/api/spec/drive.spec.ts b/api/src/routes/api/spec/drive.spec.ts index c4c28ce..c6bfd9d 100644 --- a/api/src/routes/api/spec/drive.spec.ts +++ b/api/src/routes/api/spec/drive.spec.ts @@ -28,6 +28,15 @@ jest .spyOn(fileUtilModules, 'getUploadsFolder') .mockImplementation(() => path.join(tmpFolder, 'uploads')) +// getFilesFolder() resolves via getSasjsDriveFolder()/process.driveLoc, a +// separate root from getSasjsRootFolder()/process.sasjsRoot above - without +// this, every test in this file that creates content under the drive (e.g. +// 'level1', 'my/path/...') writes into the real, shared sasjs_root/drive +// instead of this run's isolated tmpFolder, leaking state into later runs. +jest + .spyOn(fileUtilModules, 'getFilesFolder') + .mockImplementation(() => path.join(tmpFolder, 'drive', 'files')) + import appPromise from '../../../app' import { UserController,