From 88661f2152f466be0930338a4371bb4f11bed747 Mon Sep 17 00:00:00 2001 From: Nikkel Mollenhauer <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 11:55:35 +0100 Subject: [PATCH] Moved logic needed for tests to test files (#225) --- src/shuffleVideo.js | 2 +- test/testSetup.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shuffleVideo.js b/src/shuffleVideo.js index 0cd3201a..830560a6 100644 --- a/src/shuffleVideo.js +++ b/src/shuffleVideo.js @@ -183,7 +183,7 @@ async function tryGetPlaylistFromDB(playlistId, localPlaylistInfo = null) { }; // Some of the tests break if we do not create a deepCopy here, as the local and database object somehow get linked - let playlistInfo = JSON.parse(JSON.stringify(await chrome.runtime.sendMessage(msg))); + let playlistInfo = await chrome.runtime.sendMessage(msg); /* c8 ignore start - These are legacy conversions we don't want to test */ // In case the playlist is still in the old Array format (before v1.0.0) in the database, convert it to the new format diff --git a/test/testSetup.js b/test/testSetup.js index 8cbc863c..0b39e692 100644 --- a/test/testSetup.js +++ b/test/testSetup.js @@ -33,7 +33,7 @@ chrome.storage.local.get.callsFake(() => { return Promise.resolve(mockedLocalStorage); }); chrome.storage.local.set.callsFake((obj) => { - Object.assign(mockedLocalStorage, obj); + Object.assign(mockedLocalStorage, deepCopy(obj)); return Promise.resolve(); }); chrome.storage.local.clear.callsFake(() => { @@ -51,19 +51,19 @@ chrome.runtime.sendMessage.callsFake((request) => { case 'getPlaylistFromDB': // Return a playlist from the database - return Promise.resolve(mockedDatabase[request.data] ?? null); + return Promise.resolve(deepCopy(mockedDatabase[request.data] ?? null)); // With our mocked database, both commands have the same effect case 'updatePlaylistInfoInDB': - request.data.val.videos = { ...mockedDatabase[request.data.key]?.videos ?? {}, ...request.data.val.videos }; + request.data.val.videos = { ...mockedDatabase[request.data.key]?.videos ?? {}, ...deepCopy(request.data.val.videos) }; case 'overwritePlaylistInfoInDB': // Update/Overwrite a playlist in the database - mockedDatabase[request.data.key] = request.data.val; + mockedDatabase[request.data.key] = deepCopy(request.data.val); return "PlaylistInfo was sent to database."; // Only for the tests case "setKeyInDB": - mockedDatabase[request.data.key] = request.data.val; + mockedDatabase[request.data.key] = deepCopy(request.data.val); return "Key was set in the database (mocked for tests)."; case "getAPIKey":