2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-09 01:19:15 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::IssuableMetadata do
|
2017-11-07 09:00:21 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project, :public, :repository, creator: user, namespace: user.namespace) }
|
2017-07-09 01:19:15 -04:00
|
|
|
|
|
|
|
it 'returns an empty Hash if an empty collection is provided' do
|
2020-05-27 11:08:11 -04:00
|
|
|
expect(described_class.new(user, Issue.none).data).to eq({})
|
2017-07-09 01:19:15 -04:00
|
|
|
end
|
|
|
|
|
2017-11-07 09:00:21 -05:00
|
|
|
it 'raises an error when given a collection with no limit' do
|
2020-05-27 11:08:11 -04:00
|
|
|
expect { described_class.new(user, Issue.all) }.to raise_error(/must have a limit/)
|
2017-11-07 09:00:21 -05:00
|
|
|
end
|
|
|
|
|
2017-07-09 01:19:15 -04:00
|
|
|
context 'issues' do
|
|
|
|
let!(:issue) { create(:issue, author: user, project: project) }
|
|
|
|
let!(:closed_issue) { create(:issue, state: :closed, author: user, project: project) }
|
|
|
|
let!(:downvote) { create(:award_emoji, :downvote, awardable: closed_issue) }
|
|
|
|
let!(:upvote) { create(:award_emoji, :upvote, awardable: issue) }
|
2019-04-07 14:35:16 -04:00
|
|
|
let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, target_project: project, title: "Test") }
|
2017-07-09 01:19:15 -04:00
|
|
|
let!(:closing_issues) { create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request) }
|
|
|
|
|
|
|
|
it 'aggregates stats on issues' do
|
2020-05-27 11:08:11 -04:00
|
|
|
data = described_class.new(user, Issue.all.limit(10)).data
|
2017-07-09 01:19:15 -04:00
|
|
|
|
|
|
|
expect(data.count).to eq(2)
|
|
|
|
expect(data[issue.id].upvotes).to eq(1)
|
|
|
|
expect(data[issue.id].downvotes).to eq(0)
|
2019-02-27 05:28:53 -05:00
|
|
|
expect(data[issue.id].user_notes_count).to eq(0)
|
2017-07-09 01:19:15 -04:00
|
|
|
expect(data[issue.id].merge_requests_count).to eq(1)
|
|
|
|
|
|
|
|
expect(data[closed_issue.id].upvotes).to eq(0)
|
|
|
|
expect(data[closed_issue.id].downvotes).to eq(1)
|
2019-02-27 05:28:53 -05:00
|
|
|
expect(data[closed_issue.id].user_notes_count).to eq(0)
|
2017-07-09 01:19:15 -04:00
|
|
|
expect(data[closed_issue.id].merge_requests_count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge requests' do
|
2019-04-07 14:35:16 -04:00
|
|
|
let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, target_project: project, title: "Test") }
|
2017-07-09 01:19:15 -04:00
|
|
|
let!(:merge_request_closed) { create(:merge_request, state: "closed", source_project: project, target_project: project, title: "Closed Test") }
|
|
|
|
let!(:downvote) { create(:award_emoji, :downvote, awardable: merge_request) }
|
|
|
|
let!(:upvote) { create(:award_emoji, :upvote, awardable: merge_request) }
|
|
|
|
let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") }
|
|
|
|
|
|
|
|
it 'aggregates stats on merge requests' do
|
2020-05-27 11:08:11 -04:00
|
|
|
data = described_class.new(user, MergeRequest.all.limit(10)).data
|
2017-07-09 01:19:15 -04:00
|
|
|
|
|
|
|
expect(data.count).to eq(2)
|
|
|
|
expect(data[merge_request.id].upvotes).to eq(1)
|
|
|
|
expect(data[merge_request.id].downvotes).to eq(1)
|
2019-02-27 05:28:53 -05:00
|
|
|
expect(data[merge_request.id].user_notes_count).to eq(1)
|
2017-07-09 01:19:15 -04:00
|
|
|
expect(data[merge_request.id].merge_requests_count).to eq(0)
|
|
|
|
|
|
|
|
expect(data[merge_request_closed.id].upvotes).to eq(0)
|
|
|
|
expect(data[merge_request_closed.id].downvotes).to eq(0)
|
2019-02-27 05:28:53 -05:00
|
|
|
expect(data[merge_request_closed.id].user_notes_count).to eq(0)
|
2017-07-09 01:19:15 -04:00
|
|
|
expect(data[merge_request_closed.id].merge_requests_count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|