web_upload_strategy_spec.rb 1.51 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::ImportExport::AfterExportStrategies::WebUploadStrategy do
4 5
  include StubRequests

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  let(:example_url) { 'http://www.example.com' }
  let(:strategy) { subject.new(url: example_url, http_method: 'post') }
  let!(:project) { create(:project, :with_export) }
  let!(:user) { build(:user) }

  subject { described_class }

  describe 'validations' do
    it 'only POST and PUT method allowed' do
      %w(POST post PUT put).each do |method|
        expect(subject.new(url: example_url, http_method: method)).to be_valid
      end

      expect(subject.new(url: example_url, http_method: 'whatever')).not_to be_valid
    end

    it 'onyl allow urls as upload urls' do
      expect(subject.new(url: example_url)).to be_valid
      expect(subject.new(url: 'whatever')).not_to be_valid
    end
  end

  describe '#execute' do
29 30 31
    it 'removes the exported project file after the upload' do
      allow(strategy).to receive(:send_file)
      allow(strategy).to receive(:handle_response_error)
32

33
      expect(project).to receive(:remove_exports)
34

35
      strategy.execute(user, project)
36
    end
37 38 39

    context 'when upload fails' do
      it 'stores the export error' do
40
        stub_full_request(example_url, method: :post).to_return(status: [404, 'Page not found'])
41 42 43 44 45 46 47 48

        strategy.execute(user, project)

        errors = project.import_export_shared.errors
        expect(errors).not_to be_empty
        expect(errors.first).to eq "Error uploading the project. Code 404: Page not found"
      end
    end
49 50
  end
end