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/services/import/github/gists_import_service_spec.rb')
-rw-r--r--spec/services/import/github/gists_import_service_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/services/import/github/gists_import_service_spec.rb b/spec/services/import/github/gists_import_service_spec.rb
new file mode 100644
index 00000000000..c5d73e6479d
--- /dev/null
+++ b/spec/services/import/github/gists_import_service_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Import::Github::GistsImportService, feature_category: :importer do
+ subject(:import) { described_class.new(user, params) }
+
+ let_it_be(:user) { create(:user) }
+ let(:params) { { github_access_token: 'token' } }
+ let(:import_status) { instance_double('Gitlab::GithubGistsImport::Status') }
+
+ describe '#execute', :aggregate_failures do
+ before do
+ allow(Gitlab::GithubGistsImport::Status).to receive(:new).and_return(import_status)
+ end
+
+ context 'when import in progress' do
+ let(:expected_result) do
+ {
+ status: :error,
+ http_status: 422,
+ message: 'Import already in progress'
+ }
+ end
+
+ it 'returns error' do
+ expect(import_status).to receive(:started?).and_return(true)
+ expect(import.execute).to eq(expected_result)
+ end
+ end
+
+ context 'when import was not started' do
+ it 'returns success' do
+ encrypted_token = Gitlab::CryptoHelper.aes256_gcm_encrypt(params[:github_access_token])
+ expect(import_status).to receive(:started?).and_return(false)
+ expect(Gitlab::CryptoHelper)
+ .to receive(:aes256_gcm_encrypt).with(params[:github_access_token])
+ .and_return(encrypted_token)
+ expect(Gitlab::GithubGistsImport::StartImportWorker)
+ .to receive(:perform_async).with(user.id, encrypted_token)
+ expect(import_status).to receive(:start!)
+
+ expect(import.execute).to eq({ status: :success })
+ end
+ end
+ end
+end