Commit 7c4e996c authored by Mike Greiling's avatar Mike Greiling

Merge branch 'winh-merge-request-diff-discussion-commit-id' into 'master'

Pass commit when posting diff discussions

See merge request gitlab-org/gitlab-ce!23371
parents a2e06ad3 e7439c31
......@@ -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,
});
......
......@@ -27,6 +27,7 @@ export const getReversePosition = linePosition => {
export function getFormData(params) {
const {
commit,
note,
noteableType,
noteableData,
......@@ -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
......
---
title: Pass commit when posting diff discussions
merge_request: 23371
author:
type: fixed
......@@ -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', () => {
......@@ -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':
......@@ -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);
......
......@@ -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,
......@@ -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,
......
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