Commit 742c15b7 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '23400-fix-duplicate-replies' into 'master'

Fix race condition causing duplicate replies

See merge request gitlab-org/gitlab!17255
parents 34eba8a8 b8c9b1c6
......@@ -33,10 +33,11 @@ export default {
},
[types.ADD_NEW_REPLY_TO_DISCUSSION](state, note) {
const noteObj = utils.findNoteObjectById(state.discussions, note.discussion_id);
const discussion = utils.findNoteObjectById(state.discussions, note.discussion_id);
const existingNote = discussion && utils.findNoteObjectById(discussion.notes, note.id);
if (noteObj) {
noteObj.notes.push(note);
if (discussion && !existingNote) {
discussion.notes.push(note);
}
},
......
---
title: Fix new discussion replies sometimes showing up twice
merge_request: 17255
author:
type: fixed
......@@ -48,9 +48,22 @@ describe('Notes Store mutations', () => {
});
describe('ADD_NEW_REPLY_TO_DISCUSSION', () => {
const newReply = Object.assign({}, note, { discussion_id: discussionMock.id });
let state;
beforeEach(() => {
state = { discussions: [{ ...discussionMock }] };
});
it('should add a reply to a specific discussion', () => {
const state = { discussions: [discussionMock] };
const newReply = Object.assign({}, note, { discussion_id: discussionMock.id });
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
expect(state.discussions[0].notes.length).toEqual(4);
});
it('should not add the note if it already exists in the discussion', () => {
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
mutations.ADD_NEW_REPLY_TO_DISCUSSION(state, newReply);
expect(state.discussions[0].notes.length).toEqual(4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment