From 5eec1fbd1c5a6a7ff13bd082e13d6f718cb0aeea Mon Sep 17 00:00:00 2001 From: martinboulais <31805063+martinboulais@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:03:52 +0100 Subject: [PATCH] Fix test and refactor --- lib/server/services/run/updateRun.js | 10 ++++++---- test/public/logs/create.test.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/server/services/run/updateRun.js b/lib/server/services/run/updateRun.js index 71938b8184..2e8b50048c 100644 --- a/lib/server/services/run/updateRun.js +++ b/lib/server/services/run/updateRun.js @@ -108,7 +108,8 @@ exports.updateRun = async (identifier, payload, transaction) => { if (tags) { const previousTagsTexts = runModel.tags.map(({ text }) => text); - let existingTagsToLogIfDeleted = previousTagsTexts.filter((tag) => TAGS_TO_LOG.includes(tag)); + // Store the list of tags currently applied to the runs, that needs logging if deleted + let deletedTagsThatNeedsLogging = previousTagsTexts.filter((tag) => TAGS_TO_LOG.includes(tag)); let shouldLogTags = false; @@ -125,10 +126,11 @@ exports.updateRun = async (identifier, payload, transaction) => { shouldLogTags = shouldLogTags || TAGS_TO_LOG.includes(text); } - existingTagsToLogIfDeleted = existingTagsToLogIfDeleted.filter((tag) => tag !== text); + // Remove the current tag from the list of deleted tags + deletedTagsThatNeedsLogging = deletedTagsThatNeedsLogging.filter((tag) => tag !== text); } - shouldLogTags = shouldLogTags || existingTagsToLogIfDeleted.length > 0; + shouldLogTags = shouldLogTags || deletedTagsThatNeedsLogging.length > 0; // Remove existing tags of the run and insert new ones await RunTagsRepository.removeById(runId).then(() => RunTagsRepository.insertMany(tags.map((tag) => ({ @@ -142,7 +144,7 @@ exports.updateRun = async (identifier, payload, transaction) => { previousTagsTexts, tags.map(({ text }) => text), [ - ...existingTagsToLogIfDeleted, + ...deletedTagsThatNeedsLogging, ...tags.map(({ text }) => text).filter((text) => TAGS_TO_LOG.includes(text)), ], user, diff --git a/test/public/logs/create.test.js b/test/public/logs/create.test.js index 7ca426a32f..5218bcc9d8 100644 --- a/test/public/logs/create.test.js +++ b/test/public/logs/create.test.js @@ -191,7 +191,7 @@ module.exports = () => { (await page.waitForFunction(() => { const options = document.querySelectorAll('.tag-option'); - if (options.length === 9) { + if (options.length === 10) { for (const option of options) { if (!option.innerText.toUpperCase().includes('P')) { return false;