1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# frozen_string_literal: true
require 'spec_helper'
describe API::Entities::ProjectImportStatus do
describe '#as_json' do
subject { entity.as_json }
let(:correlation_id) { 'cid' }
context 'when no import state exists' do
let(:entity) { described_class.new(build(:project)) }
it 'includes basic fields and no failures' do
expect(subject[:import_status]).to eq('none')
expect(subject[:correlation_id]).to be_nil
expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([])
end
end
context 'when import has not finished yet' do
let(:project) { create(:project, :import_scheduled, import_correlation_id: correlation_id) }
let(:entity) { described_class.new(project) }
it 'includes basic fields and no failures', :aggregate_failures do
expect(subject[:import_status]).to eq('scheduled')
expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([])
end
end
context 'when import has finished with failed relations' do
let(:project) { create(:project, :import_finished, import_correlation_id: correlation_id) }
let(:entity) { described_class.new(project) }
it 'includes basic fields with failed relations', :aggregate_failures do
create(:import_failure, :hard_failure, project: project, correlation_id_value: correlation_id)
expect(subject[:import_status]).to eq('finished')
expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).not_to be_empty
end
end
context 'when import has failed' do
let(:project) { create(:project, :import_failed, import_correlation_id: correlation_id, import_last_error: 'error') }
let(:entity) { described_class.new(project) }
it 'includes basic fields with import error', :aggregate_failures do
expect(subject[:import_status]).to eq('failed')
expect(subject[:correlation_id]).to eq(correlation_id)
expect(subject[:import_error]).to eq('error')
expect(subject[:failed_relations]).to eq([])
end
end
end
end
|