2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe Gitlab::LegacyGithubImport::MilestoneFormatter do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2016-06-02 11:05:42 +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
|
|
|
|
{
|
|
|
|
state: 'open',
|
|
|
|
title: '1.0',
|
|
|
|
description: 'Version 1.0',
|
|
|
|
due_on: nil,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: updated_at,
|
|
|
|
closed_at: nil
|
|
|
|
}
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:iid_attr) { :number }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
subject(:formatter) { described_class.new(project, raw_data) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
shared_examples 'Gitlab::LegacyGithubImport::MilestoneFormatter#attributes' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:data) { base_data.merge(iid_attr => 1347) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
context 'when milestone is open' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:raw_data) { double(data.merge(state: 'open')) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'returns formatted attributes' do
|
|
|
|
expected = {
|
|
|
|
iid: 1347,
|
|
|
|
project: project,
|
|
|
|
title: '1.0',
|
|
|
|
description: 'Version 1.0',
|
|
|
|
state: 'active',
|
|
|
|
due_date: nil,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: updated_at
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(formatter.attributes).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone is closed' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:raw_data) { double(data.merge(state: 'closed')) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'returns formatted attributes' do
|
|
|
|
expected = {
|
|
|
|
iid: 1347,
|
|
|
|
project: project,
|
|
|
|
title: '1.0',
|
|
|
|
description: 'Version 1.0',
|
|
|
|
state: 'closed',
|
|
|
|
due_date: nil,
|
|
|
|
created_at: created_at,
|
2016-09-29 09:46:39 +05:30
|
|
|
updated_at: updated_at
|
2016-06-02 11:05:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
expect(formatter.attributes).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone has a due date' do
|
|
|
|
let(:due_date) { DateTime.strptime('2011-01-28T19:01:12Z') }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:raw_data) { double(data.merge(due_on: due_date)) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'returns formatted attributes' do
|
|
|
|
expected = {
|
|
|
|
iid: 1347,
|
|
|
|
project: project,
|
|
|
|
title: '1.0',
|
|
|
|
description: 'Version 1.0',
|
|
|
|
state: 'active',
|
|
|
|
due_date: due_date,
|
|
|
|
created_at: created_at,
|
|
|
|
updated_at: updated_at
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(formatter.attributes).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when importing a GitHub project' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like 'Gitlab::LegacyGithubImport::MilestoneFormatter#attributes'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when importing a Gitea project' do
|
|
|
|
let(:iid_attr) { :id }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
before do
|
|
|
|
project.update(import_type: 'gitea')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like 'Gitlab::LegacyGithubImport::MilestoneFormatter#attributes'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|