Commit e7439c31 authored by Winnie Hellmann's avatar Winnie Hellmann

Pass commit when posting diff discussions

parent cfe48479
...@@ -192,8 +192,9 @@ export const toggleFileDiscussions = ({ getters, dispatch }, diff) => { ...@@ -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({ const postData = getNoteFormData({
commit: state.commit,
note, note,
...formData, ...formData,
}); });
......
...@@ -27,6 +27,7 @@ export const getReversePosition = linePosition => { ...@@ -27,6 +27,7 @@ export const getReversePosition = linePosition => {
export function getFormData(params) { export function getFormData(params) {
const { const {
commit,
note, note,
noteableType, noteableType,
noteableData, noteableData,
...@@ -66,7 +67,7 @@ export function getFormData(params) { ...@@ -66,7 +67,7 @@ export function getFormData(params) {
position, position,
noteable_type: noteableType, noteable_type: noteableType,
noteable_id: noteableData.id, noteable_id: noteableData.id,
commit_id: '', commit_id: commit && commit.id,
type: type:
diffFile.diff_refs.start_sha && diffFile.diff_refs.head_sha diffFile.diff_refs.start_sha && diffFile.diff_refs.head_sha
? DIFF_NOTE_TYPE ? DIFF_NOTE_TYPE
......
---
title: Pass commit when posting diff discussions
merge_request: 23371
author:
type: fixed
...@@ -29,6 +29,7 @@ import actions, { ...@@ -29,6 +29,7 @@ import actions, {
} from '~/diffs/store/actions'; } from '~/diffs/store/actions';
import * as types from '~/diffs/store/mutation_types'; import * as types from '~/diffs/store/mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import mockDiffFile from 'spec/diffs/mock_data/diff_file';
import testAction from '../../helpers/vuex_action_helper'; import testAction from '../../helpers/vuex_action_helper';
describe('DiffsStoreActions', () => { describe('DiffsStoreActions', () => {
...@@ -607,11 +608,18 @@ describe('DiffsStoreActions', () => { ...@@ -607,11 +608,18 @@ describe('DiffsStoreActions', () => {
}); });
describe('saveDiffDiscussion', () => { describe('saveDiffDiscussion', () => {
beforeEach(() => {
spyOnDependency(actions, 'getNoteFormData').and.returnValue('testData');
});
it('dispatches actions', done => { 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 => { const dispatch = jasmine.createSpy('dispatch').and.callFake(name => {
switch (name) { switch (name) {
case 'saveNote': case 'saveNote':
...@@ -625,11 +633,19 @@ describe('DiffsStoreActions', () => { ...@@ -625,11 +633,19 @@ describe('DiffsStoreActions', () => {
} }
}); });
saveDiffDiscussion({ dispatch }, { note: {}, formData: {} }) saveDiffDiscussion({ state, dispatch }, { note, formData })
.then(() => { .then(() => {
expect(dispatch.calls.argsFor(0)).toEqual(['saveNote', 'testData', { root: true }]); const { calls } = dispatch;
expect(dispatch.calls.argsFor(1)).toEqual(['updateDiscussion', 'test', { root: true }]);
expect(dispatch.calls.argsFor(2)).toEqual(['assignDiscussionsToDiff', ['discussion']]); 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) .then(done)
.catch(done.fail); .catch(done.fail);
......
...@@ -150,7 +150,7 @@ describe('DiffsStoreUtils', () => { ...@@ -150,7 +150,7 @@ describe('DiffsStoreUtils', () => {
note: { note: {
noteable_type: options.noteableType, noteable_type: options.noteableType,
noteable_id: options.noteableData.id, noteable_id: options.noteableData.id,
commit_id: '', commit_id: undefined,
type: DIFF_NOTE_TYPE, type: DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.line_code, line_code: options.noteTargetLine.line_code,
note: options.note, note: options.note,
...@@ -209,7 +209,7 @@ describe('DiffsStoreUtils', () => { ...@@ -209,7 +209,7 @@ describe('DiffsStoreUtils', () => {
note: { note: {
noteable_type: options.noteableType, noteable_type: options.noteableType,
noteable_id: options.noteableData.id, noteable_id: options.noteableData.id,
commit_id: '', commit_id: undefined,
type: LEGACY_DIFF_NOTE_TYPE, type: LEGACY_DIFF_NOTE_TYPE,
line_code: options.noteTargetLine.line_code, line_code: options.noteTargetLine.line_code,
note: options.note, 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