Commit 68cafaee authored by Arturo Herrero's avatar Arturo Herrero

Update Jira issue entity with spec

Complete Jira issue entity, adding specs for Jira issue entity and
serializer.
parent 4a1cc00c
......@@ -3,7 +3,7 @@
module Integrations
module Jira
class IssueEntity < Grape::Entity
expose :project_id do |_jira_issue|
expose :project_id do |_jira_issue, options|
options[:project].id
end
......@@ -25,49 +25,45 @@ module Integrations
expose :labels do |jira_issue|
jira_issue.labels.map do |name|
bg_color = Label.color_for(name)
text_color = LabelsHelper.text_color_for_bg(bg_color)
{
name: name,
color: "#b728d9",
text_color: "#FFFFFF"
color: bg_color,
text_color: text_color
}
end
end
expose :author do |jira_issue|
{
id: 1,
name: jira_issue.creator['displayName'],
username: jira_issue.creator['name'],
avatar_url: 'http://127.0.0.1:3000/uploads/-/system/user/avatar/1/avatar.png',
web_url: 'http://127.0.0.1:3000/root'
name: jira_issue.reporter.displayName
}
end
expose :assignees do |jira_issue|
[
{
id: 1,
name: jira_issue.assignee&.displayName,
# username: jira_issue.assignee&.name,
avatar_url: "http://127.0.0.1:3000/uploads/-/system/user/avatar/1/avatar.png",
web_url: "http://127.0.0.1:3000/root"
}
]
if jira_issue.assignee.present?
[
{
name: jira_issue.assignee.displayName
}
]
else
[]
end
end
expose :weburl do |jira_issue|
expose :web_url do |jira_issue|
"#{jira_issue.client.options[:site]}projects/#{jira_issue.project.key}/issues/#{jira_issue.key}"
end
# TODO
# {
# references: {
# short: "#39",
# relative: jira_issue.key,
# full: "gitlab-org/gitlab-shell#39"
# }
# }
expose :references do |jira_issue|
{
relative: jira_issue.key
}
end
end
end
end
......@@ -3,126 +3,64 @@
require 'spec_helper'
RSpec.describe Integrations::Jira::IssueEntity do
# TODO
# let(:project) { create(:project) }
# let(:resource) { create(:issue, project: project) }
# let(:user) { create(:user) }
#
# let(:request) { double('request', current_user: user) }
#
# subject { described_class.new(resource, project: project, request: request).as_json }
#
# it 'has Issuable attributes' do
# expect(subject).to include(:id, :iid, :author_id, :description, :lock_version, :milestone_id,
# :title, :updated_by_id, :created_at, :updated_at, :milestone, :labels)
# end
#
# it 'has time estimation attributes' do
# expect(subject).to include(:time_estimate, :total_time_spent, :human_time_estimate, :human_total_time_spent)
# end
#
# context 'when issue got moved' do
# let(:public_project) { create(:project, :public) }
# let(:member) { create(:user) }
# let(:non_member) { create(:user) }
# let(:issue) { create(:issue, project: public_project) }
#
# before do
# project.add_developer(member)
# public_project.add_developer(member)
# Issues::MoveService.new(public_project, member).execute(issue, project)
# end
#
# context 'when user cannot read target project' do
# it 'does not return moved_to_id' do
# request = double('request', current_user: non_member)
#
# response = described_class.new(issue, request: request).as_json
#
# expect(response[:moved_to_id]).to be_nil
# end
# end
#
# context 'when user can read target project' do
# it 'returns moved moved_to_id' do
# request = double('request', current_user: member)
#
# response = described_class.new(issue, request: request).as_json
#
# expect(response[:moved_to_id]).to eq(issue.moved_to_id)
# end
# end
# end
#
# context 'when issue got duplicated' do
# let(:private_project) { create(:project, :private) }
# let(:member) { create(:user) }
# let(:issue) { create(:issue, project: project) }
# let(:new_issue) { create(:issue, project: private_project) }
#
# before do
# Issues::DuplicateService
# .new(project, member)
# .execute(issue, new_issue)
# end
#
# context 'when user cannot read new issue' do
# let(:non_member) { create(:user) }
#
# it 'does not return duplicated_to_id' do
# request = double('request', current_user: non_member)
#
# response = described_class.new(issue, request: request).as_json
#
# expect(response[:duplicated_to_id]).to be_nil
# end
# end
#
# context 'when user can read target project' do
# before do
# project.add_developer(member)
# private_project.add_developer(member)
# end
#
# it 'returns duplicated duplicated_to_id' do
# request = double('request', current_user: member)
#
# response = described_class.new(issue, request: request).as_json
#
# expect(response[:duplicated_to_id]).to eq(issue.duplicated_to_id)
# end
# end
# end
#
# context 'when issuable in active or archived project' do
# before do
# project.add_developer(user)
# end
#
# context 'when project is active' do
# it 'returns archived false' do
# expect(subject[:is_project_archived]).to eq(false)
# end
#
# it 'returns nil for archived project doc' do
# response = described_class.new(resource, request: request).as_json
#
# expect(response[:archived_project_docs_path]).to be nil
# end
# end
#
# context 'when project is archived' do
# before do
# project.update(archived: true)
# end
#
# it 'returns archived true' do
# expect(subject[:is_project_archived]).to eq(true)
# end
#
# it 'returns archived project doc' do
# expect(subject[:archived_project_docs_path]).to eq('/help/user/project/settings/index.md#archiving-a-project')
# end
# end
# end
let(:project) { build(:project) }
let(:jira_issue) do
double(
summary: 'summary',
created: '2020-06-25T15:39:30.000+0000',
updated: '2020-06-26T15:38:32.000+0000',
resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'],
reporter: double('displayName' => 'reporter'),
assignee: double('displayName' => 'assignee'),
project: double(key: 'GL'),
key: 'GL-5',
client: double(options: { site: 'http://jira.com/' })
)
end
subject { described_class.new(jira_issue, project: project).as_json }
it 'returns the Jira issues attributes' do
expect(subject).to include(
project_id: project.id,
title: 'summary',
created_at: '2020-06-25T15:39:30.000+0000',
updated_at: '2020-06-26T15:38:32.000+0000',
closed_at: '2020-06-27T13:23:51.000+0000',
labels: [
{
name: 'backend',
color: '#b43fdd',
text_color: '#FFFFFF'
}
],
author: { name: 'reporter' },
assignees: [
{ name: 'assignee' }
],
web_url: 'http://jira.com/projects/GL/issues/GL-5',
references: { relative: 'GL-5' }
)
end
context 'without assignee' do
before do
allow(jira_issue).to receive(:assignee).and_return(nil)
end
it 'returns an empty array' do
expect(subject).to include(assignees: [])
end
end
context 'without labels' do
before do
allow(jira_issue).to receive(:labels).and_return([])
end
it 'returns an empty array' do
expect(subject).to include(labels: [])
end
end
end
......@@ -3,47 +3,28 @@
require 'spec_helper'
RSpec.describe Integrations::Jira::IssueSerializer do
# TODO
# let(:user) { create(:user) }
#
# let(:serializer) do
# described_class.new(user: user)
# end
#
# subject { serializer.represent(resource) }
#
# describe '#represent' do
# context 'when a single object is being serialized' do
# let(:resource) { create(:label) }
#
# it 'serializes the label object' do
# expect(subject[:id]).to eq resource.id
# end
# end
#
# context 'when multiple objects are being serialized' do
# let(:num_labels) { 2 }
# let(:resource) { create_list(:label, num_labels) }
#
# it 'serializes the array of labels' do
# expect(subject.size).to eq(num_labels)
# end
# end
# end
#
# describe '#represent_appearance' do
# context 'when represents only appearance' do
# let(:resource) { create(:label) }
#
# subject { serializer.represent_appearance(resource) }
#
# it 'serializes only attributes used for appearance' do
# expect(subject.keys).to eq([:id, :title, :color, :text_color])
# expect(subject[:id]).to eq(resource.id)
# expect(subject[:title]).to eq(resource.title)
# expect(subject[:color]).to eq(resource.color)
# expect(subject[:text_color]).to eq(resource.text_color)
# end
# end
# end
let(:serializer) { described_class.new }
let(:project) { build(:project) }
subject { serializer.represent(jira_issues, project: project) }
describe '#represent' do
context 'when an empty array is being serialized' do
let(:jira_issues) { [] }
it 'returns an empty array' do
expect(subject).to eq([])
end
end
context 'when multiple objects are being serialized' do
let(:jira_issues) do
[double.as_null_object, double.as_null_object]
end
it 'serializes the array of jira issues' do
expect(subject.size).to eq(jira_issues.size)
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