Skip to content
Snippets Groups Projects
Commit e7439c31 authored by Winnie Hellmann's avatar Winnie Hellmann
Browse files

Pass commit when posting diff discussions

parent cfe48479
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -192,8 +192,9 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => {
});
};
 
export const saveDiffDiscussion = ({ dispatch }, { note, formData }) => {
export const saveDiffDiscussion = ({ state, dispatch }, { note, formData }) => {
const postData = getNoteFormData({
commit: state.commit,
note,
...formData,
});
Loading
Loading
Loading
Loading
@@ -27,6 +27,7 @@ export const getReversePosition = linePosition => {
 
export function getFormData(params) {
const {
commit,
note,
noteableType,
noteableData,
Loading
Loading
@@ -66,7 +67,7 @@ export function getFormData(params) {
position,
noteable_type: noteableType,
noteable_id: noteableData.id,
commit_id: '',
commit_id: commit && commit.id,
type:
diffFile.diff_refs.start_sha && diffFile.diff_refs.head_sha
? DIFF_NOTE_TYPE
Loading
Loading
---
title: Pass commit when posting diff discussions
merge_request: 23371
author:
type: fixed
Loading
Loading
@@ -29,6 +29,7 @@ import actions, {
} from '~/diffs/store/actions';
import * as types from '~/diffs/store/mutation_types';
import axios from '~/lib/utils/axios_utils';
import mockDiffFile from 'spec/diffs/mock_data/diff_file';
import testAction from '../../helpers/vuex_action_helper';
 
describe('DiffsStoreActions', () => {
Loading
Loading
@@ -607,11 +608,18 @@ describe('DiffsStoreActions', () => {
});
 
describe('saveDiffDiscussion', () => {
beforeEach(() => {
spyOnDependency(actions, 'getNoteFormData').and.returnValue('testData');
});
it('dispatches actions', done => {
const commitId = 'something';
const formData = {
diffFile: { ...mockDiffFile },
noteableData: {},
};
const note = {};
const state = {
commit: {
id: commitId,
},
};
const dispatch = jasmine.createSpy('dispatch').and.callFake(name => {
switch (name) {
case 'saveNote':
Loading
Loading
@@ -625,11 +633,19 @@ describe('DiffsStoreActions', () => {
}
});
 
saveDiffDiscussion({ dispatch }, { note: {}, formData: {} })
saveDiffDiscussion({ state, dispatch }, { note, formData })
.then(() => {
expect(dispatch.calls.argsFor(0)).toEqual(['saveNote', 'testData', { root: true }]);
expect(dispatch.calls.argsFor(1)).toEqual(['updateDiscussion', 'test', { root: true }]);
expect(dispatch.calls.argsFor(2)).toEqual(['assignDiscussionsToDiff', ['discussion']]);
const { calls } = dispatch;
expect(calls.count()).toBe(5);
expect(calls.argsFor(0)).toEqual(['saveNote', jasmine.any(Object), { root: true }]);
const postData = calls.argsFor(0)[1];
expect(postData.data.note.commit_id).toBe(commitId);
expect(calls.argsFor(1)).toEqual(['updateDiscussion', 'test', { root: true }]);
expect(calls.argsFor(2)).toEqual(['assignDiscussionsToDiff', ['discussion']]);
})
.then(done)
.catch(done.fail);
Loading
Loading
Loading
Loading
@@ -150,7 +150,7 @@ describe('DiffsStoreUtils', () => {
note: {
noteable_type: options.noteableType,
noteable_id: options.noteableData.id,
commit_id: '',
commit_id: undefined,
type: DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.line_code,
note: options.note,
Loading
Loading
@@ -209,7 +209,7 @@ describe('DiffsStoreUtils', () => {
note: {
noteable_type: options.noteableType,
noteable_id: options.noteableData.id,
commit_id: '',
commit_id: undefined,
type: LEGACY_DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.line_code,
note: options.note,
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment