Commit 95a970ec authored by Sean McGivern's avatar Sean McGivern

Merge branch '223918-jira-issue-list-presenter' into 'master'

Create Jira issue serializer

Closes #223918

See merge request gitlab-org/gitlab!35567
parents 74af310d 68cafaee
# frozen_string_literal: true
module Integrations
module Jira
class IssueEntity < Grape::Entity
expose :project_id do |_jira_issue, options|
options[:project].id
end
expose :title do |jira_issue|
jira_issue.summary
end
expose :created_at do |jira_issue|
jira_issue.created
end
expose :updated_at do |jira_issue|
jira_issue.updated
end
expose :closed_at do |jira_issue|
jira_issue.resolutiondate
end
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: bg_color,
text_color: text_color
}
end
end
expose :author do |jira_issue|
{
name: jira_issue.reporter.displayName
}
end
expose :assignees do |jira_issue|
if jira_issue.assignee.present?
[
{
name: jira_issue.assignee.displayName
}
]
else
[]
end
end
expose :web_url do |jira_issue|
"#{jira_issue.client.options[:site]}projects/#{jira_issue.project.key}/issues/#{jira_issue.key}"
end
expose :references do |jira_issue|
{
relative: jira_issue.key
}
end
end
end
end
# frozen_string_literal: true
module Integrations
module Jira
class IssueSerializer < BaseSerializer
entity ::Integrations::Jira::IssueEntity
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::Jira::IssueEntity do
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
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::Jira::IssueSerializer do
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