2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-19 05:11:36 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-05-24 08:10:31 -04:00
|
|
|
RSpec.describe Integrations::Flowdock do
|
2016-04-21 11:13:14 -04:00
|
|
|
describe 'Validations' do
|
2021-06-30 20:08:17 -04:00
|
|
|
context 'when integration is active' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
subject.active = true
|
|
|
|
end
|
2016-04-21 11:13:14 -04:00
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:token) }
|
|
|
|
end
|
|
|
|
|
2021-06-30 20:08:17 -04:00
|
|
|
context 'when integration is inactive' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
subject.active = false
|
|
|
|
end
|
2016-04-21 11:13:14 -04:00
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-19 05:11:36 -04:00
|
|
|
describe "Execute" do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2021-06-16 17:10:19 -04:00
|
|
|
let(:sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
|
|
|
|
let(:api_url) { 'https://api.flowdock.com/v1/messages' }
|
|
|
|
|
|
|
|
subject(:flowdock_integration) { described_class.new }
|
2013-08-19 05:11:36 -04:00
|
|
|
|
|
|
|
before do
|
2021-06-16 17:10:19 -04:00
|
|
|
allow(flowdock_integration).to receive_messages(
|
2013-08-19 05:11:36 -04:00
|
|
|
project_id: project.id,
|
|
|
|
project: project,
|
|
|
|
token: 'verySecret'
|
|
|
|
)
|
2021-06-16 17:10:19 -04:00
|
|
|
WebMock.stub_request(:post, api_url)
|
2013-08-19 05:11:36 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "calls FlowDock API" do
|
2021-06-16 17:10:19 -04:00
|
|
|
flowdock_integration.execute(sample_data)
|
|
|
|
|
|
|
|
sample_data[:commits].each do |commit|
|
2015-08-14 09:31:11 -04:00
|
|
|
# One request to Flowdock per new commit
|
2021-06-16 17:10:19 -04:00
|
|
|
next if commit[:id] == sample_data[:before]
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2021-06-16 17:10:19 -04:00
|
|
|
expect(WebMock).to have_requested(:post, api_url).with(
|
2015-08-14 09:31:11 -04:00
|
|
|
body: /#{commit[:id]}.*#{project.path}/
|
|
|
|
).once
|
|
|
|
end
|
2013-08-19 05:11:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|