2016-01-14 18:37:52 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::GithubImport::IssueFormatter, lib: true do
|
|
|
|
let!(:project) { create(:project, namespace: create(:namespace, path: 'octocat')) }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:octocat) { double(id: 123456, login: 'octocat') }
|
2016-01-14 18:37:52 +05:30
|
|
|
let(:created_at) { DateTime.strptime('2011-01-26T19:01:12Z') }
|
|
|
|
let(:updated_at) { DateTime.strptime('2011-01-27T19:01:12Z') }
|
|
|
|
|
|
|
|
let(:base_data) do
|
|
|
|
{
|
|
|
|
number: 1347,
|
2016-06-02 11:05:42 +05:30
|
|
|
milestone: nil,
|
2016-01-14 18:37:52 +05:30
|
|
|
state: 'open',
|
|
|
|
title: 'Found a bug',
|
|
|
|
body: "I'm having a problem with this.",
|
|
|
|
assignee: nil,
|
|
|
|
user: octocat,
|
|
|
|
comments: 0,
|
|
|
|
pull_request: nil,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: updated_at,
|
|
|
|
closed_at: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:issue) { described_class.new(project, raw_data)}
|
|
|
|
|
|
|
|
describe '#attributes' do
|
|
|
|
context 'when issue is open' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(state: 'open')) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns formatted attributes' do
|
|
|
|
expected = {
|
2016-06-02 11:05:42 +05:30
|
|
|
iid: 1347,
|
2016-01-14 18:37:52 +05:30
|
|
|
project: project,
|
2016-06-02 11:05:42 +05:30
|
|
|
milestone: nil,
|
2016-01-14 18:37:52 +05:30
|
|
|
title: 'Found a bug',
|
|
|
|
description: "*Created by: octocat*\n\nI'm having a problem with this.",
|
|
|
|
state: 'opened',
|
|
|
|
author_id: project.creator_id,
|
|
|
|
assignee_id: nil,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: updated_at
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(issue.attributes).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issue is closed' do
|
|
|
|
let(:closed_at) { DateTime.strptime('2011-01-28T19:01:12Z') }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(state: 'closed', closed_at: closed_at)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns formatted attributes' do
|
|
|
|
expected = {
|
2016-06-02 11:05:42 +05:30
|
|
|
iid: 1347,
|
2016-01-14 18:37:52 +05:30
|
|
|
project: project,
|
2016-06-02 11:05:42 +05:30
|
|
|
milestone: nil,
|
2016-01-14 18:37:52 +05:30
|
|
|
title: 'Found a bug',
|
|
|
|
description: "*Created by: octocat*\n\nI'm having a problem with this.",
|
|
|
|
state: 'closed',
|
|
|
|
author_id: project.creator_id,
|
|
|
|
assignee_id: nil,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: closed_at
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(issue.attributes).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is assigned to someone' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(assignee: octocat)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns nil as assignee_id when is not a GitLab user' do
|
|
|
|
expect(issue.attributes.fetch(:assignee_id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns GitLab user id as assignee_id when is a GitLab user' do
|
|
|
|
gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
|
|
|
|
|
|
|
expect(issue.attributes.fetch(:assignee_id)).to eq gl_user.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
context 'when it has a milestone' do
|
|
|
|
let(:milestone) { double(number: 45) }
|
|
|
|
let(:raw_data) { double(base_data.merge(milestone: milestone)) }
|
|
|
|
|
|
|
|
it 'returns nil when milestone does not exist' do
|
|
|
|
expect(issue.attributes.fetch(:milestone)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns milestone when it exists' do
|
|
|
|
milestone = create(:milestone, project: project, iid: 45)
|
|
|
|
|
|
|
|
expect(issue.attributes.fetch(:milestone)).to eq milestone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
context 'when author is a GitLab user' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(user: octocat)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns project#creator_id as author_id when is not a GitLab user' do
|
|
|
|
expect(issue.attributes.fetch(:author_id)).to eq project.creator_id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns GitLab user id as author_id when is a GitLab user' do
|
|
|
|
gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github')
|
|
|
|
|
|
|
|
expect(issue.attributes.fetch(:author_id)).to eq gl_user.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_comments?' do
|
|
|
|
context 'when number of comments is greater than zero' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(comments: 1)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(issue.has_comments?).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when number of comments is equal to zero' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(comments: 0)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(issue.has_comments?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#number' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(number: 1347)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns pull request number' do
|
|
|
|
expect(issue.number).to eq 1347
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
context 'when mention a pull request' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(pull_request: double)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(issue.valid?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when does not mention a pull request' do
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:raw_data) { double(base_data.merge(pull_request: nil)) }
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(issue.valid?).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|