2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-21 16:05:44 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-05-24 08:10:31 -04:00
|
|
|
RSpec.describe Integrations::Packagist do
|
2017-09-21 16:05:44 -04:00
|
|
|
let(:packagist_params) do
|
|
|
|
{
|
|
|
|
active: true,
|
|
|
|
project: project,
|
|
|
|
properties: {
|
|
|
|
username: packagist_username,
|
|
|
|
token: packagist_token,
|
|
|
|
server: packagist_server
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-09-03 08:08:47 -04:00
|
|
|
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) }
|
|
|
|
|
2021-07-14 14:08:31 -04:00
|
|
|
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}" }
|
2020-09-03 08:08:47 -04:00
|
|
|
end
|
|
|
|
|
2017-09-21 16:05:44 -04:00
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
|
2021-06-17 23:10:18 -04:00
|
|
|
let(:packagist_integration) { described_class.create!(packagist_params) }
|
2017-09-21 16:05:44 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:post, packagist_hook_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Packagist API' do
|
2021-06-17 23:10:18 -04:00
|
|
|
packagist_integration.execute(push_sample_data)
|
2017-09-21 16:05:44 -04:00
|
|
|
|
|
|
|
expect(a_request(:post, packagist_hook_url)).to have_been_made.once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|