Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_import_state_spec.rb')
-rw-r--r--spec/models/project_import_state_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/project_import_state_spec.rb b/spec/models/project_import_state_spec.rb
index e5232026c39..7ceb4931c4f 100644
--- a/spec/models/project_import_state_spec.rb
+++ b/spec/models/project_import_state_spec.rb
@@ -14,6 +14,30 @@ RSpec.describe ProjectImportState, type: :model, feature_category: :importers do
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
+
+ describe 'checksums attribute' do
+ let(:import_state) { build(:import_state, checksums: checksums) }
+
+ before do
+ import_state.validate
+ end
+
+ context 'when the checksums attribute has invalid fields' do
+ let(:checksums) { { fetched: { issue: :foo, note: 20 } } }
+
+ it 'adds errors' do
+ expect(import_state.errors.details.keys).to include(:checksums)
+ end
+ end
+
+ context 'when the checksums attribute has valid fields' do
+ let(:checksums) { { fetched: { issue: 8, note: 2 }, imported: { issue: 3, note: 2 } } }
+
+ it 'does not add errors' do
+ expect(import_state.errors.details.keys).not_to include(:checksums)
+ end
+ end
+ end
end
describe 'Project import job' do
@@ -199,6 +223,37 @@ RSpec.describe ProjectImportState, type: :model, feature_category: :importers do
.from(import_data).to(nil)
end
end
+
+ context 'state transition: started: [:finished, :canceled, :failed]' do
+ using RSpec::Parameterized::TableSyntax
+
+ let_it_be_with_reload(:project) { create(:project) }
+
+ where(
+ :import_type,
+ :import_status,
+ :transition,
+ :expected_checksums
+ ) do
+ 'github' | :started | :finish | { 'fetched' => {}, 'imported' => {} }
+ 'github' | :started | :cancel | { 'fetched' => {}, 'imported' => {} }
+ 'github' | :started | :fail_op | { 'fetched' => {}, 'imported' => {} }
+ 'github' | :scheduled | :cancel | {}
+ 'gitlab_project' | :started | :cancel | {}
+ end
+
+ with_them do
+ before do
+ create(:import_state, status: import_status, import_type: import_type, project: project)
+ end
+
+ it 'updates (or does not update) checksums' do
+ project.import_state.send(transition)
+
+ expect(project.import_state.checksums).to eq(expected_checksums)
+ end
+ end
+ end
end
describe 'clearing `jid` after finish', :clean_gitlab_redis_cache do