Commit fcf798fe authored by Patrick Bajao's avatar Patrick Bajao Committed by Paul Slaughter

Support creating/publishing drafts with commit ID

Adds `commit_id` column to `draft_notes` table to store the
commit ID where the draft was created.
parent 24c21e47
......@@ -10,6 +10,8 @@ module DiffPositionableNote
serialize :original_position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize
serialize :position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize
serialize :change_position, Gitlab::Diff::Position # rubocop:disable Cop/ActiveRecordSerialize
validate :diff_refs_match_commit, if: :for_commit?
end
%i(original_position position change_position).each do |meth|
......@@ -71,4 +73,10 @@ module DiffPositionableNote
self.position = result[:position]
end
end
def diff_refs_match_commit
return if self.original_position.diff_refs == commit&.diff_refs
errors.add(:commit_id, 'does not match the diff refs')
end
end
......@@ -20,7 +20,6 @@ class DiffNote < Note
validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } }
validate :positions_complete
validate :verify_supported
validate :diff_refs_match_commit, if: :for_commit?
before_validation :set_line_code, if: :on_text?
after_save :keep_around_commits
......@@ -154,12 +153,6 @@ class DiffNote < Note
errors.add(:position, "is invalid")
end
def diff_refs_match_commit
return if self.original_position.diff_refs == self.commit.diff_refs
errors.add(:commit_id, 'does not match the diff refs')
end
def keep_around_commits
shas = [
self.original_position.base_sha,
......
# frozen_string_literal: true
class AddCommitIdToDraftNotes < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :draft_notes, :commit_id, :binary
end
end
......@@ -1136,6 +1136,7 @@ ActiveRecord::Schema.define(version: 2019_07_31_084415) do
t.text "position"
t.text "original_position"
t.text "change_position"
t.binary "commit_id"
t.index ["author_id"], name: "index_draft_notes_on_author_id"
t.index ["discussion_id"], name: "index_draft_notes_on_discussion_id"
t.index ["merge_request_id"], name: "index_draft_notes_on_merge_request_id"
......
......@@ -14,6 +14,7 @@ export default {
}),
...mapGetters('diffs', ['getDiffFileByHash']),
...mapGetters('batchComments', ['shouldRenderDraftRowInDiscussion', 'draftForDiscussion']),
...mapState('diffs', ['commit']),
},
methods: {
...mapActions('diffs', ['cancelCommentForm']),
......@@ -61,6 +62,11 @@ export default {
...this.diffFileCommentForm,
});
const diffFileHeadSha =
this.commit && this.diffFile && this.diffFile.diff_refs && this.diffFile.diff_refs.head_sha;
postData.data.note.commit_id = diffFileHeadSha || null;
return this.saveDraft(postData)
.then(() => {
if (positionType === IMAGE_DIFF_POSITION_TYPE) {
......
......@@ -83,10 +83,16 @@ class Projects::MergeRequests::DraftsController < Projects::MergeRequests::Appli
def draft_note_params
params.require(:draft_note).permit(
:commit_id,
:note,
:position,
:resolve_discussion
)
).tap do |h|
# Old FE version will still be sending `draft_note[commit_id]` as 'undefined'.
# That can result to having a note linked to a commit with 'undefined' ID
# which is non-existent.
h[:commit_id] = nil if h[:commit_id] == 'undefined'
end
end
def prepare_notes_for_rendering(notes)
......
......@@ -3,9 +3,12 @@ class DraftNote < ApplicationRecord
include DiffPositionableNote
include Gitlab::Utils::StrongMemoize
include Sortable
include ShaAttribute
PUBLISH_ATTRS = %i(noteable_id noteable_type type note).freeze
DIFF_ATTRS = %i(position original_position change_position).freeze
DIFF_ATTRS = %i(position original_position change_position commit_id).freeze
sha_attribute :commit_id
# Attribute used to store quick actions changes and users referenced.
attr_accessor :commands_changes
......@@ -44,7 +47,7 @@ class DraftNote < ApplicationRecord
end
def for_commit?
false
commit_id.present?
end
def resolvable?
......@@ -112,4 +115,8 @@ class DraftNote < ApplicationRecord
file
end
end
def commit
@commit ||= project.commit(commit_id) if commit_id.present?
end
end
---
title: Support creating/publishing drafts with commit ID
merge_request: 14520
author:
type: fixed
......@@ -2,6 +2,8 @@
require 'spec_helper'
describe Projects::MergeRequests::DraftsController do
include RepoHelpers
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:user) { project.owner }
......@@ -62,7 +64,7 @@ describe Projects::MergeRequests::DraftsController do
end
it 'creates draft note with position' do
diff_refs = project.commit(RepoHelpers.sample_commit.id).try(:diff_refs)
diff_refs = project.commit(sample_commit.id).try(:diff_refs)
position = Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
......@@ -135,6 +137,40 @@ describe Projects::MergeRequests::DraftsController do
end.to change { DraftNote.count }.by(0)
end
end
context 'commit_id is present' do
let(:commit) { project.commit(sample_commit.id) }
let(:position) do
Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: commit.diff_refs
)
end
before do
create_draft_note(draft_overrides: { commit_id: commit_id, position: position.to_json })
end
context 'value is a commit sha' do
let(:commit_id) { commit.id }
it 'creates the draft note with commit ID' do
expect(DraftNote.last.commit_id).to eq(commit_id)
end
end
context 'value is "undefined"' do
let(:commit_id) { 'undefined' }
it 'creates the draft note with nil commit ID' do
expect(DraftNote.last.commit_id).to be_nil
end
end
end
end
describe 'PUT #update' do
......@@ -211,7 +247,7 @@ describe Projects::MergeRequests::DraftsController do
end
it 'publishes draft notes with position' do
diff_refs = project.commit(RepoHelpers.sample_commit.id).try(:diff_refs)
diff_refs = project.commit(sample_commit.id).try(:diff_refs)
position = Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
import NoteForm from '~/notes/components/note_form.vue';
import diffFileMockData from '../mock_data/diff_file';
import note from '../../notes/mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('EE DiffLineNoteForm', () => {
let storeOptions;
let saveDraft;
let wrapper;
const createStoreOptions = headSha => {
const state = {
notes: {
notesData: { draftsPath: null },
noteableData: {},
},
};
const getters = {
getUserData: jest.fn(),
isLoggedIn: jest.fn(),
noteableType: jest.fn(),
};
return {
state,
getters,
modules: {
diffs: {
namespaced: true,
state: { commit: headSha || null },
getters: {
getDiffFileByHash: jest.fn().mockReturnValue(() => ({
diff_refs: {
head_sha: headSha || null,
},
})),
},
},
batchComments: {
namespaced: true,
actions: { saveDraft },
},
},
};
};
const createComponent = (props = {}) => {
const store = new Vuex.Store(storeOptions);
// deep clone the mock data
const diffFile = JSON.parse(JSON.stringify(diffFileMockData));
const diffLines = diffFile.highlighted_diff_lines;
wrapper = shallowMount(DiffLineNoteForm, {
propsData: {
diffFileHash: diffFile.file_hash,
diffLines,
line: diffLines[0],
noteTargetLine: diffLines[0],
...props,
},
store,
sync: false,
localVue,
});
};
beforeEach(() => {
saveDraft = jest.fn();
storeOptions = createStoreOptions();
});
afterEach(() => {
wrapper.destroy();
});
const submitNoteAddToReview = () =>
wrapper.find(NoteForm).vm.$emit('handleFormUpdateAddToReview', note);
const saveDraftCommitId = () => saveDraft.mock.calls[0][1].data.note.commit_id;
describe('when user submits note to review', () => {
it('should call saveDraft action with commit_id === null when store has no commit', () => {
createComponent();
submitNoteAddToReview();
expect(saveDraft).toHaveBeenCalledTimes(1);
expect(saveDraftCommitId()).toBe(null);
});
it('should call saveDraft action with commit_id when store has commit', () => {
const HEAD_SHA = 'abc123';
storeOptions = createStoreOptions(HEAD_SHA);
createComponent();
submitNoteAddToReview();
expect(saveDraft).toHaveBeenCalledTimes(1);
expect(saveDraftCommitId()).toBe(HEAD_SHA);
});
});
});
// Copied from spec/javasripts/diffs/mock_data/diff_file.js
export default {
submodule: false,
submodule_link: null,
blob: {
id: '9e10516ca50788acf18c518a231914a21e5f16f7',
path: 'CHANGELOG',
name: 'CHANGELOG',
mode: '100644',
readable_text: true,
icon: 'file-text-o',
},
blob_path: 'CHANGELOG',
blob_name: 'CHANGELOG',
blob_icon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>',
file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
file_path: 'CHANGELOG',
new_file: false,
deleted_file: false,
renamed_file: false,
old_path: 'CHANGELOG',
new_path: 'CHANGELOG',
mode_changed: false,
a_mode: '100644',
b_mode: '100644',
text: true,
viewer: {
name: 'text',
error: null,
collapsed: false,
},
added_lines: 2,
removed_lines: 0,
diff_refs: {
base_sha: 'e63f41fe459e62e1228fcef60d7189127aeba95a',
start_sha: 'd9eaefe5a676b820c57ff18cf5b68316025f7962',
head_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13',
},
content_sha: 'c48ee0d1bf3b30453f5b32250ce03134beaa6d13',
stored_externally: null,
external_storage: null,
old_path_html: 'CHANGELOG',
new_path_html: 'CHANGELOG',
edit_path: '/gitlab-org/gitlab-test/edit/spooky-stuff/CHANGELOG',
view_path: '/gitlab-org/gitlab-test/blob/spooky-stuff/CHANGELOG',
replaced_view_path: null,
collapsed: false,
renderIt: false,
too_large: false,
context_lines_path:
'/gitlab-org/gitlab-test/blob/c48ee0d1bf3b30453f5b32250ce03134beaa6d13/CHANGELOG/diff',
highlighted_diff_lines: [
{
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1',
type: 'new',
old_line: null,
new_line: 1,
discussions: [],
text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
rich_text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
meta_data: null,
},
{
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2',
type: 'new',
old_line: null,
new_line: 2,
discussions: [],
text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
rich_text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
meta_data: null,
},
{
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null,
old_line: 1,
new_line: 3,
discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
rich_text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
meta_data: null,
},
{
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null,
old_line: 2,
new_line: 4,
discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
rich_text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
meta_data: null,
},
{
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null,
old_line: 3,
new_line: 5,
discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
rich_text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
meta_data: null,
},
{
line_code: null,
type: 'match',
old_line: null,
new_line: null,
discussions: [],
text: '',
rich_text: '',
meta_data: {
old_pos: 3,
new_pos: 5,
},
},
],
parallel_diff_lines: [
{
left: {
type: 'empty-cell',
},
right: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1',
type: 'new',
old_line: null,
new_line: 1,
discussions: [],
text: '+<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
rich_text: '<span id="LC1" class="line" lang="plaintext"> - Bad dates</span>\n',
meta_data: null,
},
},
{
left: {
type: 'empty-cell',
},
right: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2',
type: 'new',
old_line: null,
new_line: 2,
discussions: [],
text: '+<span id="LC2" class="line" lang="plaintext"></span>\n',
rich_text: '<span id="LC2" class="line" lang="plaintext"></span>\n',
meta_data: null,
},
},
{
left: {
line_Code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null,
old_line: 1,
new_line: 3,
discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
meta_data: null,
},
right: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_3',
type: null,
old_line: 1,
new_line: 3,
discussions: [],
text: ' <span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
rich_text: '<span id="LC3" class="line" lang="plaintext">v6.8.0</span>\n',
meta_data: null,
},
},
{
left: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null,
old_line: 2,
new_line: 4,
discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n',
meta_data: null,
},
right: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_2_4',
type: null,
old_line: 2,
new_line: 4,
discussions: [],
text: ' <span id="LC4" class="line" lang="plaintext"></span>\n',
rich_text: '<span id="LC4" class="line" lang="plaintext"></span>\n',
meta_data: null,
},
},
{
left: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null,
old_line: 3,
new_line: 5,
discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
meta_data: null,
},
right: {
line_code: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_3_5',
type: null,
old_line: 3,
new_line: 5,
discussions: [],
text: ' <span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
rich_text: '<span id="LC5" class="line" lang="plaintext">v6.7.0</span>\n',
meta_data: null,
},
},
{
left: {
line_code: null,
type: 'match',
old_line: null,
new_line: null,
discussions: [],
text: '',
rich_text: '',
meta_data: {
old_pos: 3,
new_pos: 5,
},
},
right: {
line_code: null,
type: 'match',
old_line: null,
new_line: null,
discussions: [],
text: '',
rich_text: '',
meta_data: {
old_pos: 3,
new_pos: 5,
},
},
},
],
discussions: [],
renderingLines: false,
};
// Copied from spec/javascripts/notes/mock_data.js
export const notesDataMock = {
discussionsPath: '/gitlab-org/gitlab-ce/issues/26/discussions.json',
lastFetchedAt: 1501862675,
markdownDocsPath: '/help/user/markdown',
newSessionPath: '/users/sign_in?redirect_to_referer=yes',
notesPath: '/gitlab-org/gitlab-ce/noteable/issue/98/notes',
quickActionsDocsPath: '/help/user/project/quick_actions',
registerPath: '/users/sign_in?redirect_to_referer=yes#register-pane',
totalNotes: 1,
closePath: '/twitter/flight/issues/9.json?issue%5Bstate_event%5D=close',
reopenPath: '/twitter/flight/issues/9.json?issue%5Bstate_event%5D=reopen',
canAwardEmoji: true,
};
export const userDataMock = {
avatar_url: 'mock_path',
id: 1,
name: 'Root',
path: '/root',
state: 'active',
username: 'root',
};
export const noteableDataMock = {
assignees: [],
author_id: 1,
branch_name: null,
confidential: false,
create_note_path: '/gitlab-org/gitlab-ce/notes?target_id=98&target_type=issue',
created_at: '2017-02-07T10:11:18.395Z',
current_user: {
can_create_note: true,
can_update: true,
can_award_emoji: true,
},
description: '',
due_date: null,
human_time_estimate: null,
human_total_time_spent: null,
id: 98,
iid: 26,
labels: [],
lock_version: null,
milestone: null,
milestone_id: null,
moved_to_id: null,
preview_note_path: '/gitlab-org/gitlab-ce/preview_markdown?target_id=98&target_type=Issue',
project_id: 2,
state: 'opened',
time_estimate: 0,
title: '14',
total_time_spent: 0,
noteable_note_url: '/group/project/merge_requests/1#note_1',
updated_at: '2017-08-04T09:53:01.226Z',
updated_by_id: 1,
web_url: '/gitlab-org/gitlab-ce/issues/26',
noteableType: 'issue',
};
export const lastFetchedAt = '1501862675';
export const individualNote = {
expanded: true,
id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
individual_note: true,
notes: [
{
id: '1390',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: 'test',
path: '/root',
},
created_at: '2017-08-01T17: 09: 33.762Z',
updated_at: '2017-08-01T17: 09: 33.762Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: null,
human_access: 'Owner',
note: 'sdfdsaf',
note_html: "<p dir='auto'>sdfdsaf</p>",
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
emoji_awardable: true,
award_emoji: [
{ name: 'baseball', user: { id: 1, name: 'Root', username: 'root' } },
{ name: 'art', user: { id: 1, name: 'Root', username: 'root' } },
],
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1390/toggle_award_emoji',
noteable_note_url: '/group/project/merge_requests/1#note_1',
note_url: '/group/project/merge_requests/1#note_1',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1390&user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1390',
},
],
reply_id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
};
export const note = {
id: '546',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2017-08-10T15:24:03.087Z',
updated_at: '2017-08-10T15:24:03.087Z',
system: false,
noteable_id: 67,
noteable_type: 'Issue',
noteable_iid: 7,
type: null,
human_access: 'Owner',
note: 'Vel id placeat reprehenderit sit numquam.',
note_html: '<p dir="auto">Vel id placeat reprehenderit sit numquam.</p>',
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: 'd3842a451b7f3d9a5dfce329515127b2d29a4cd0',
emoji_awardable: true,
award_emoji: [
{
name: 'baseball',
user: {
id: 1,
name: 'Administrator',
username: 'root',
},
},
{
name: 'bath_tone3',
user: {
id: 1,
name: 'Administrator',
username: 'root',
},
},
],
toggle_award_path: '/gitlab-org/gitlab-ce/notes/546/toggle_award_emoji',
note_url: '/group/project/merge_requests/1#note_1',
noteable_note_url: '/group/project/merge_requests/1#note_1',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F7%23note_546&user_id=1',
path: '/gitlab-org/gitlab-ce/notes/546',
};
export const discussionMock = {
id: '9e3bd2f71a01de45fd166e6719eb380ad9f270b1',
reply_id: '9e3bd2f71a01de45fd166e6719eb380ad9f270b1',
expanded: true,
notes: [
{
id: '1395',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-02T10:51:58.559Z',
updated_at: '2017-08-02T10:51:58.559Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: 'DiscussionNote',
human_access: 'Owner',
note: 'THIS IS A DICUSSSION!',
note_html: "<p dir='auto'>THIS IS A DICUSSSION!</p>",
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '9e3bd2f71a01de45fd166e6719eb380ad9f270b1',
emoji_awardable: true,
award_emoji: [],
noteable_note_url: '/group/project/merge_requests/1#note_1',
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1395/toggle_award_emoji',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1395&user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1395',
},
{
id: '1396',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-02T10:56:50.980Z',
updated_at: '2017-08-03T14:19:35.691Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: 'DiscussionNote',
human_access: 'Owner',
note: 'sadfasdsdgdsf',
note_html: "<p dir='auto'>sadfasdsdgdsf</p>",
last_edited_at: '2017-08-03T14:19:35.691Z',
last_edited_by: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '9e3bd2f71a01de45fd166e6719eb380ad9f270b1',
emoji_awardable: true,
award_emoji: [],
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1396/toggle_award_emoji',
noteable_note_url: '/group/project/merge_requests/1#note_1',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1396&user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1396',
},
{
id: '1437',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-03T18:11:18.780Z',
updated_at: '2017-08-04T09:52:31.062Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: 'DiscussionNote',
human_access: 'Owner',
note: 'adsfasf Should disappear',
note_html: "<p dir='auto'>adsfasf Should disappear</p>",
last_edited_at: '2017-08-04T09:52:31.062Z',
last_edited_by: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '9e3bd2f71a01de45fd166e6719eb380ad9f270b1',
emoji_awardable: true,
award_emoji: [],
noteable_note_url: '/group/project/merge_requests/1#note_1',
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1437/toggle_award_emoji',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1437&user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1437',
},
],
individual_note: false,
resolvable: true,
active: true,
};
export const loggedOutnoteableData = {
id: '98',
iid: 26,
author_id: 1,
description: '',
lock_version: 1,
milestone_id: null,
state: 'opened',
title: 'asdsa',
updated_by_id: 1,
created_at: '2017-02-07T10:11:18.395Z',
updated_at: '2017-08-08T10:22:51.564Z',
time_estimate: 0,
total_time_spent: 0,
human_time_estimate: null,
human_total_time_spent: null,
milestone: null,
labels: [],
branch_name: null,
confidential: false,
assignees: [
{
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
web_url: 'http://localhost:3000/root',
},
],
due_date: null,
moved_to_id: null,
project_id: 2,
web_url: '/gitlab-org/gitlab-ce/issues/26',
current_user: {
can_create_note: false,
can_update: false,
},
noteable_note_url: '/group/project/merge_requests/1#note_1',
create_note_path: '/gitlab-org/gitlab-ce/notes?target_id=98&target_type=issue',
preview_note_path: '/gitlab-org/gitlab-ce/preview_markdown?target_id=98&target_type=Issue',
};
export const collapseNotesMock = [
{
expanded: true,
id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
individual_note: true,
notes: [
{
id: '1390',
attachment: null,
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: 'test',
path: '/root',
},
created_at: '2018-02-26T18:07:41.071Z',
updated_at: '2018-02-26T18:07:41.071Z',
system: true,
system_note_icon_name: 'pencil',
noteable_id: 98,
noteable_type: 'Issue',
type: null,
human_access: 'Owner',
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false },
discussion_id: 'b97fb7bda470a65b3e009377a9032edec0a4dd05',
emoji_awardable: false,
path: '/h5bp/html5-boilerplate/notes/1057',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fh5bp%2Fhtml5-boilerplate%2Fissues%2F10%23note_1057&user_id=1',
},
],
},
{
expanded: true,
id: 'ffde43f25984ad7f2b4275135e0e2846875336c0',
individual_note: true,
notes: [
{
id: '1391',
attachment: null,
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: 'test',
path: '/root',
},
created_at: '2018-02-26T18:13:24.071Z',
updated_at: '2018-02-26T18:13:24.071Z',
system: true,
system_note_icon_name: 'pencil',
noteable_id: 99,
noteable_type: 'Issue',
type: null,
human_access: 'Owner',
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false },
discussion_id: '3eb958b4d81dec207ec3537a2f3bd8b9f271bb34',
emoji_awardable: false,
path: '/h5bp/html5-boilerplate/notes/1057',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fh5bp%2Fhtml5-boilerplate%2Fissues%2F10%23note_1057&user_id=1',
},
],
},
];
export const INDIVIDUAL_NOTE_RESPONSE_MAP = {
GET: {
'/gitlab-org/gitlab-ce/issues/26/discussions.json': [
{
id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
reply_id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
expanded: true,
notes: [
{
id: '1390',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-01T17:09:33.762Z',
updated_at: '2017-08-01T17:09:33.762Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: null,
human_access: 'Owner',
note: 'sdfdsaf',
note_html: '\u003cp dir="auto"\u003esdfdsaf\u003c/p\u003e',
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '0fb4e0e3f9276e55ff32eb4195add694aece4edd',
emoji_awardable: true,
award_emoji: [
{
name: 'baseball',
user: {
id: 1,
name: 'Root',
username: 'root',
},
},
{
name: 'art',
user: {
id: 1,
name: 'Root',
username: 'root',
},
},
],
noteable_note_url: '/group/project/merge_requests/1#note_1',
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1390/toggle_award_emoji',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1390\u0026user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1390',
},
],
individual_note: true,
},
{
id: '70d5c92a4039a36c70100c6691c18c27e4b0a790',
reply_id: '70d5c92a4039a36c70100c6691c18c27e4b0a790',
expanded: true,
notes: [
{
id: '1391',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-02T10:51:38.685Z',
updated_at: '2017-08-02T10:51:38.685Z',
system: false,
noteable_id: 98,
noteable_type: 'Issue',
type: null,
human_access: 'Owner',
note: 'New note!',
note_html: '\u003cp dir="auto"\u003eNew note!\u003c/p\u003e',
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: '70d5c92a4039a36c70100c6691c18c27e4b0a790',
emoji_awardable: true,
award_emoji: [],
noteable_note_url: '/group/project/merge_requests/1#note_1',
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1391/toggle_award_emoji',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F26%23note_1391\u0026user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1391',
},
],
individual_note: true,
},
],
'/gitlab-org/gitlab-ce/noteable/issue/98/notes': {
last_fetched_at: 1512900838,
notes: [],
},
},
PUT: {
'/gitlab-org/gitlab-ce/notes/1471': {
commands_changes: null,
valid: true,
id: '1471',
attachment: null,
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-08T16:53:00.666Z',
updated_at: '2017-12-10T11:03:21.876Z',
system: false,
noteable_id: 124,
noteable_type: 'Issue',
noteable_iid: 29,
type: 'DiscussionNote',
human_access: 'Owner',
note: 'Adding a comment',
note_html: '\u003cp dir="auto"\u003eAdding a comment\u003c/p\u003e',
last_edited_at: '2017-12-10T11:03:21.876Z',
last_edited_by: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: 'a3ed36e29b1957efb3b68c53e2d7a2b24b1df052',
emoji_awardable: true,
award_emoji: [],
noteable_note_url: '/group/project/merge_requests/1#note_1',
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1471/toggle_award_emoji',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F29%23note_1471\u0026user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1471',
},
},
};
export const DISCUSSION_NOTE_RESPONSE_MAP = {
...INDIVIDUAL_NOTE_RESPONSE_MAP,
GET: {
...INDIVIDUAL_NOTE_RESPONSE_MAP.GET,
'/gitlab-org/gitlab-ce/issues/26/discussions.json': [
{
id: 'a3ed36e29b1957efb3b68c53e2d7a2b24b1df052',
reply_id: 'a3ed36e29b1957efb3b68c53e2d7a2b24b1df052',
expanded: true,
notes: [
{
id: '1471',
attachment: {
url: null,
filename: null,
image: false,
},
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: null,
path: '/root',
},
created_at: '2017-08-08T16:53:00.666Z',
updated_at: '2017-08-08T16:53:00.666Z',
system: false,
noteable_id: 124,
noteable_type: 'Issue',
noteable_iid: 29,
type: 'DiscussionNote',
human_access: 'Owner',
note: 'Adding a comment',
note_html: '\u003cp dir="auto"\u003eAdding a comment\u003c/p\u003e',
current_user: {
can_edit: true,
can_award_emoji: true,
},
discussion_id: 'a3ed36e29b1957efb3b68c53e2d7a2b24b1df052',
emoji_awardable: true,
award_emoji: [],
toggle_award_path: '/gitlab-org/gitlab-ce/notes/1471/toggle_award_emoji',
noteable_note_url: '/group/project/merge_requests/1#note_1',
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F29%23note_1471\u0026user_id=1',
path: '/gitlab-org/gitlab-ce/notes/1471',
},
],
individual_note: false,
},
],
},
};
export function individualNoteInterceptor(request, next) {
const body = INDIVIDUAL_NOTE_RESPONSE_MAP[request.method.toUpperCase()][request.url];
next(
request.respondWith(JSON.stringify(body), {
status: 200,
}),
);
}
export function discussionNoteInterceptor(request, next) {
const body = DISCUSSION_NOTE_RESPONSE_MAP[request.method.toUpperCase()][request.url];
next(
request.respondWith(JSON.stringify(body), {
status: 200,
}),
);
}
export const notesWithDescriptionChanges = [
{
id: '39b271c2033e9ed43d8edb393702f65f7a830459',
reply_id: '39b271c2033e9ed43d8edb393702f65f7a830459',
expanded: true,
notes: [
{
id: '901',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:05:36.117Z',
updated_at: '2018-05-29T12:05:36.117Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
note_html:
'<p dir="auto">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '39b271c2033e9ed43d8edb393702f65f7a830459',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_901&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/901/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/901',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
reply_id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
expanded: true,
notes: [
{
id: '902',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:05:58.694Z',
updated_at: '2018-05-29T12:05:58.694Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note:
'Varius vel pharetra vel turpis nunc eget lorem. Ipsum dolor sit amet consectetur adipiscing.',
note_html:
'<p dir="auto">Varius vel pharetra vel turpis nunc eget lorem. Ipsum dolor sit amet consectetur adipiscing.</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_902&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/902/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/902',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '7f1feda384083eb31763366e6392399fde6f3f31',
reply_id: '7f1feda384083eb31763366e6392399fde6f3f31',
expanded: true,
notes: [
{
id: '903',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:06:05.772Z',
updated_at: '2018-05-29T12:06:05.772Z',
system: true,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false, can_award_emoji: true },
resolved: false,
resolved_by: null,
system_note_icon_name: 'pencil-square',
discussion_id: '7f1feda384083eb31763366e6392399fde6f3f31',
emoji_awardable: false,
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_903&user_id=1',
human_access: 'Owner',
path: '/gitlab-org/gitlab-shell/notes/903',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
reply_id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
expanded: true,
notes: [
{
id: '904',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:06:16.112Z',
updated_at: '2018-05-29T12:06:16.112Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'Ullamcorper eget nulla facilisi etiam',
note_html: '<p dir="auto">Ullamcorper eget nulla facilisi etiam</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_904&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/904/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/904',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
reply_id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
expanded: true,
notes: [
{
id: '905',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:06:28.851Z',
updated_at: '2018-05-29T12:06:28.851Z',
system: true,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false, can_award_emoji: true },
resolved: false,
resolved_by: null,
system_note_icon_name: 'pencil-square',
discussion_id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
emoji_awardable: false,
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_905&user_id=1',
human_access: 'Owner',
path: '/gitlab-org/gitlab-shell/notes/905',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '70411b08cdfc01f24187a06d77daa33464cb2620',
reply_id: '70411b08cdfc01f24187a06d77daa33464cb2620',
expanded: true,
notes: [
{
id: '906',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:20:02.925Z',
updated_at: '2018-05-29T12:20:02.925Z',
system: true,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false, can_award_emoji: true },
resolved: false,
resolved_by: null,
system_note_icon_name: 'pencil-square',
discussion_id: '70411b08cdfc01f24187a06d77daa33464cb2620',
emoji_awardable: false,
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_906&user_id=1',
human_access: 'Owner',
path: '/gitlab-org/gitlab-shell/notes/906',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
];
export const collapsedSystemNotes = [
{
id: '39b271c2033e9ed43d8edb393702f65f7a830459',
reply_id: '39b271c2033e9ed43d8edb393702f65f7a830459',
expanded: true,
notes: [
{
id: '901',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:05:36.117Z',
updated_at: '2018-05-29T12:05:36.117Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
note_html:
'<p dir="auto">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '39b271c2033e9ed43d8edb393702f65f7a830459',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_901&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/901/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/901',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
reply_id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
expanded: true,
notes: [
{
id: '902',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:05:58.694Z',
updated_at: '2018-05-29T12:05:58.694Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note:
'Varius vel pharetra vel turpis nunc eget lorem. Ipsum dolor sit amet consectetur adipiscing.',
note_html:
'<p dir="auto">Varius vel pharetra vel turpis nunc eget lorem. Ipsum dolor sit amet consectetur adipiscing.</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '4852335d7dc40b9ceb8fde1a2bb9c1b67e4c7795',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_902&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/902/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/902',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
reply_id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
expanded: true,
notes: [
{
id: '904',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:06:16.112Z',
updated_at: '2018-05-29T12:06:16.112Z',
system: false,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'Ullamcorper eget nulla facilisi etiam',
note_html: '<p dir="auto">Ullamcorper eget nulla facilisi etiam</p>',
current_user: { can_edit: true, can_award_emoji: true },
resolved: false,
resolved_by: null,
discussion_id: '091865fe3ae20f0045234a3d103e3b15e73405b5',
emoji_awardable: true,
award_emoji: [],
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_904&user_id=1',
human_access: 'Owner',
toggle_award_path: '/gitlab-org/gitlab-shell/notes/904/toggle_award_emoji',
path: '/gitlab-org/gitlab-shell/notes/904',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
reply_id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
expanded: true,
notes: [
{
id: '905',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:06:28.851Z',
updated_at: '2018-05-29T12:06:28.851Z',
system: true,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'changed the description',
note_html: ' <p dir="auto">changed the description 2 times within 1 minute </p>',
current_user: { can_edit: false, can_award_emoji: true },
resolved: false,
resolved_by: null,
system_note_icon_name: 'pencil-square',
discussion_id: 'a21cf2e804acc3c60d07e37d75e395f5a9a4d044',
emoji_awardable: false,
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_905&user_id=1',
human_access: 'Owner',
path: '/gitlab-org/gitlab-shell/notes/905',
times_updated: 2,
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
{
id: '70411b08cdfc01f24187a06d77daa33464cb2620',
reply_id: '70411b08cdfc01f24187a06d77daa33464cb2620',
expanded: true,
notes: [
{
id: '906',
type: null,
attachment: null,
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
path: '/root',
},
created_at: '2018-05-29T12:20:02.925Z',
updated_at: '2018-05-29T12:20:02.925Z',
system: true,
noteable_id: 182,
noteable_type: 'Issue',
resolvable: false,
noteable_iid: 12,
note: 'changed the description',
note_html: '<p dir="auto">changed the description</p>',
current_user: { can_edit: false, can_award_emoji: true },
resolved: false,
resolved_by: null,
system_note_icon_name: 'pencil-square',
discussion_id: '70411b08cdfc01f24187a06d77daa33464cb2620',
emoji_awardable: false,
report_abuse_path:
'/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-shell%2Fissues%2F12%23note_906&user_id=1',
human_access: 'Owner',
path: '/gitlab-org/gitlab-shell/notes/906',
},
],
individual_note: true,
resolvable: false,
resolved: false,
diff_discussion: false,
},
];
export const discussion1 = {
id: 'abc1',
resolvable: true,
resolved: false,
active: true,
diff_file: {
file_path: 'about.md',
},
position: {
new_line: 50,
old_line: null,
},
notes: [
{
created_at: '2018-07-04T16:25:41.749Z',
},
],
};
export const resolvedDiscussion1 = {
id: 'abc1',
resolvable: true,
resolved: true,
diff_file: {
file_path: 'about.md',
},
position: {
new_line: 50,
old_line: null,
},
notes: [
{
created_at: '2018-07-04T16:25:41.749Z',
},
],
};
export const discussion2 = {
id: 'abc2',
resolvable: true,
resolved: false,
active: true,
diff_file: {
file_path: 'README.md',
},
position: {
new_line: null,
old_line: 20,
},
notes: [
{
created_at: '2018-07-04T12:05:41.749Z',
},
],
};
export const discussion3 = {
id: 'abc3',
resolvable: true,
active: true,
resolved: false,
diff_file: {
file_path: 'README.md',
},
position: {
new_line: 21,
old_line: null,
},
notes: [
{
created_at: '2018-07-05T17:25:41.749Z',
},
],
};
export const unresolvableDiscussion = {
resolvable: false,
};
export const discussionFiltersMock = [
{
title: 'Show all activity',
value: 0,
},
{
title: 'Show comments only',
value: 1,
},
{
title: 'Show system notes only',
value: 2,
},
];
# frozen_string_literal: true
require 'spec_helper'
describe DraftNote do
include RepoHelpers
describe 'validations' do
it_behaves_like 'a valid diff positionable note', :draft_note
end
end
......@@ -2,16 +2,30 @@
require 'spec_helper'
describe DraftNotes::PublishService do
include RepoHelpers
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.target_project }
let(:user) { merge_request.author }
let(:commit) { project.commit(sample_commit.id) }
let(:position) do
Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: commit.diff_refs
)
end
def publish(draft: nil)
DraftNotes::PublishService.new(merge_request, user).execute(draft)
end
context 'single draft note' do
let!(:drafts) { create_list(:draft_note, 2, merge_request: merge_request, author: user) }
let(:commit_id) { nil }
let!(:drafts) { create_list(:draft_note, 2, merge_request: merge_request, author: user, commit_id: commit_id, position: position) }
it 'publishes' do
expect { publish(draft: drafts.first) }.to change { DraftNote.count }.by(-1).and change { Note.count }.by(1)
......@@ -28,12 +42,25 @@ describe DraftNotes::PublishService do
expect(result[:status]).to eq(:success)
end
context 'commit_id is set' do
let(:commit_id) { commit.id }
it 'creates note from draft with commit_id' do
result = publish(draft: drafts.first)
expect(result[:status]).to eq(:success)
expect(merge_request.notes.first.commit_id).to eq(commit_id)
end
end
end
context 'multiple draft notes' do
let(:commit_id) { nil }
before do
create(:draft_note, merge_request: merge_request, author: user, note: 'first note')
create(:draft_note, merge_request: merge_request, author: user, note: 'second note')
create(:draft_note, merge_request: merge_request, author: user, note: 'first note', commit_id: commit_id, position: position)
create(:draft_note, merge_request: merge_request, author: user, note: 'second note', commit_id: commit_id, position: position)
end
context 'when review fails to create' do
......@@ -77,6 +104,20 @@ describe DraftNotes::PublishService do
publish
end
context 'commit_id is set' do
let(:commit_id) { commit.id }
it 'creates note from draft with commit_id' do
result = publish
expect(result[:status]).to eq(:success)
merge_request.notes.each do |note|
expect(note.commit_id).to eq(commit_id)
end
end
end
end
context 'draft notes with suggestions' do
......
......@@ -29,7 +29,7 @@ describe 'Database schema' do
cluster_providers_gcp: %w[gcp_project_id operation_id],
deploy_keys_projects: %w[deploy_key_id],
deployments: %w[deployable_id environment_id user_id],
draft_notes: %w[discussion_id],
draft_notes: %w[discussion_id commit_id],
emails: %w[user_id],
events: %w[target_id],
epics: %w[updated_by_id last_edited_by_id start_date_sourcing_milestone_id due_date_sourcing_milestone_id],
......
// Copied to ee/spec/frontend/diffs/mock_data/diff_file.js
export default {
submodule: false,
submodule_link: null,
......
// Copied to ee/spec/frontend/notes/mock_data.js
export const notesDataMock = {
discussionsPath: '/gitlab-org/gitlab-ce/issues/26/discussions.json',
lastFetchedAt: 1501862675,
......
......@@ -34,6 +34,10 @@ describe DiffNote do
subject { create(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) }
describe 'validations' do
it_behaves_like 'a valid diff positionable note', :diff_note_on_commit
end
describe "#position=" do
context "when provided a string" do
it "sets the position" do
......
# frozen_string_literal: true
shared_examples_for 'a valid diff positionable note' do |factory_on_commit|
context 'for commit' do
let(:project) { create(:project, :repository) }
let(:commit) { project.commit(sample_commit.id) }
let(:commit_id) { commit.id }
let(:diff_refs) { commit.diff_refs }
let(:position) do
Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: diff_refs
)
end
subject { build(factory_on_commit, commit_id: commit_id, position: position) }
context 'position diff refs matches commit diff refs' do
it 'is valid' do
expect(subject).to be_valid
expect(subject.errors).not_to have_key(:commit_id)
end
end
context 'position diff refs does not match commit diff refs' do
let(:diff_refs) do
Gitlab::Diff::DiffRefs.new(
base_sha: "not_existing_sha",
head_sha: "existing_sha"
)
end
it 'is invalid' do
expect(subject).to be_invalid
expect(subject.errors).to have_key(:commit_id)
end
end
context 'commit does not exist' do
let(:commit_id) { 'non-existing' }
it 'is invalid' do
expect(subject).to be_invalid
expect(subject.errors).to have_key(:commit_id)
end
end
end
end
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