BigW Consortium Gitlab

milestone_formatter_spec.rb 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
require 'spec_helper'

describe Gitlab::GithubImport::MilestoneFormatter, lib: true do
  let(:project) { create(:empty_project) }
  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
18
  let(:iid_attr) { :number }
19

20 21 22 23
  subject(:formatter) { described_class.new(project, raw_data) }

  shared_examples 'Gitlab::GithubImport::MilestoneFormatter#attributes' do
    let(:data) { base_data.merge(iid_attr => 1347) }
24 25

    context 'when milestone is open' do
26
      let(:raw_data) { double(data.merge(state: 'open')) }
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

      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
45
      let(:raw_data) { double(data.merge(state: 'closed')) }
46 47 48 49 50 51 52 53 54 55

      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,
56
          updated_at: updated_at
57 58 59 60 61 62 63 64
        }

        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') }
65
      let(:raw_data) { double(data.merge(due_on: due_date)) }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

      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
83 84 85 86 87 88 89 90 91 92 93 94 95

  context 'when importing a GitHub project' do
    it_behaves_like 'Gitlab::GithubImport::MilestoneFormatter#attributes'
  end

  context 'when importing a Gitea project' do
    let(:iid_attr) { :id }
    before do
      project.update(import_type: 'gitea')
    end

    it_behaves_like 'Gitlab::GithubImport::MilestoneFormatter#attributes'
  end
96
end