Skip to content

Commit

Permalink
Fix test and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Nov 1, 2024
1 parent 95ce2a2 commit 5eec1fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/server/services/run/updateRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) => ({
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/public/logs/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5eec1fb

Please sign in to comment.