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

packagist_spec.rb « integrations « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1976e73e2e399b032457e16423faddf8fd1df8e (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Integrations::Packagist do
  let(:packagist_params) do
    {
        active: true,
        project: project,
        properties: {
            username: packagist_username,
            token: packagist_token,
            server: packagist_server
        }
    }
  end

  let(:packagist_hook_url) do
    "#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}"
  end

  let(:packagist_token) { 'verySecret' }
  let(:packagist_username) { 'theUser' }
  let(:packagist_server) { 'https://packagist.example.com' }
  let(:project) { create(:project) }

  it_behaves_like Integrations::HasWebHook do
    let(:integration) { described_class.new(packagist_params) }
    let(:hook_url) { "#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}" }
  end

  it_behaves_like Integrations::ResetSecretFields do
    let(:integration) { described_class.new(packagist_params) }
  end

  describe '#execute' do
    let(:user)    { create(:user) }
    let(:project) { create(:project, :repository) }
    let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
    let(:packagist_integration) { described_class.create!(packagist_params) }

    before do
      stub_request(:post, packagist_hook_url)
    end

    it 'calls Packagist API' do
      packagist_integration.execute(push_sample_data)

      expect(a_request(:post, packagist_hook_url)).to have_been_made.once
    end
  end
end