debian-mirror-gitlab/spec/models/integrations/packagist_spec.rb

79 lines
2.3 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2021-09-04 01:27:46 +05:30
RSpec.describe Integrations::Packagist do
2021-09-30 23:02:18 +05:30
it_behaves_like Integrations::HasWebHook do
2023-01-13 00:05:48 +05:30
let_it_be(:project) { create(:project) }
let(:integration) { build(:packagist_integration, project: project) }
let(:hook_url) { "#{integration.server}/api/update-package?username={username}&apiToken={token}" }
2020-11-24 15:15:51 +05:30
end
2022-07-29 17:44:30 +05:30
it_behaves_like Integrations::ResetSecretFields do
2023-01-13 00:05:48 +05:30
let(:integration) { build(:packagist_integration) }
2022-07-29 17:44:30 +05:30
end
2018-03-17 18:26:18 +05:30
describe '#execute' do
2023-01-13 00:05:48 +05:30
let(:project) { build(:project) }
let(:integration) { build(:packagist_integration, project: project) }
let(:packagist_hook_url) do
"#{integration.server}/api/update-package?username=#{integration.username}&apiToken=#{integration.token}"
end
2018-03-17 18:26:18 +05:30
before do
stub_request(:post, packagist_hook_url)
end
it 'calls Packagist API' do
2023-01-13 00:05:48 +05:30
user = create(:user)
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
integration.execute(push_sample_data)
2018-03-17 18:26:18 +05:30
expect(a_request(:post, packagist_hook_url)).to have_been_made.once
end
end
2023-01-13 00:05:48 +05:30
describe '#test' do
let(:integration) { build(:packagist_integration) }
let(:test_data) { { foo: 'bar' } }
subject(:result) { integration.test(test_data) }
context 'when test request executes without errors' do
before do
allow(integration).to receive(:execute).with(test_data).and_return(
ServiceResponse.success(message: 'success message', payload: { http_status: http_status })
)
end
context 'when response is a 200' do
let(:http_status) { 200 }
it 'return failure result' do
is_expected.to eq(success: false, result: 'success message')
end
end
context 'when response is a 202' do
let(:http_status) { 202 }
it 'return success result' do
is_expected.to eq(success: true, result: 'success message')
end
end
end
context 'when test request executes with errors' do
before do
allow(integration).to receive(:execute).with(test_data).and_raise(StandardError, 'error message')
end
it 'return failure result' do
is_expected.to eq(success: false, result: 'error message')
end
end
end
2018-03-17 18:26:18 +05:30
end