Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved logic needed for tests to test files #225

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shuffleVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/testSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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":
Expand Down