File: import_bitbucket_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (70 lines) | stat: -rw-r--r-- 2,086 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::ImportBitbucket, :with_current_organization, feature_category: :importers do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let(:params) do
    {
      bitbucket_username: 'foo',
      bitbucket_app_password: 'bar',
      repo_path: 'path/to/repo',
      target_namespace: user.namespace_path,
      organization_id: current_organization.id
    }
  end

  describe 'POST /import/bitbucket' do
    context 'when authenticated' do
      before do
        allow_next_instance_of(Import::BitbucketService) do |service|
          allow(service).to receive(:execute).and_return(
            status: :success,
            project: project
          )
        end
      end

      it 'calls Import::BitbucketService with correct params' do
        expect(Import::BitbucketService).to receive(:new).with(user, hash_including(params))

        post api('/import/bitbucket', user), params: params
      end

      context 'when successful' do
        it 'returns project entity response' do
          post api('/import/bitbucket', user), params: params

          expect(response).to have_gitlab_http_status(:created)
          expect(json_response['name']).to eq(project.name)
        end
      end

      context 'when unsuccessful' do
        it 'returns api error' do
          allow_next_instance_of(Import::BitbucketService) do |service|
            allow(service).to receive(:execute).and_return(
              status: :error,
              http_status: :unprocessable_entity,
              message: 'Error!'
            )
          end

          post api('/import/bitbucket', user), params: params

          expect(response).to have_gitlab_http_status(:unprocessable_entity)
          expect(json_response['message']['error']).to eq('Error!')
        end
      end
    end

    context 'when unauthenticated' do
      it 'returns api error' do
        post api('/import/bitbucket')

        expect(response).to have_gitlab_http_status(:unauthorized)
      end
    end
  end
end