2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-25 14:36:37 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-05-31 23:10:06 -04:00
|
|
|
RSpec.describe Integrations::Slack do
|
2021-06-02 05:09:46 -04:00
|
|
|
it_behaves_like Integrations::SlackMattermostNotifier, "Slack"
|
2021-03-10 19:09:38 -05:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
stub_request(:post, "https://slack.service.url/")
|
|
|
|
end
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
let_it_be(:slack_integration) { create(:integrations_slack, branches_to_be_notified: 'all') }
|
2021-03-10 19:09:38 -05:00
|
|
|
|
|
|
|
it 'uses only known events', :aggregate_failures do
|
|
|
|
described_class::SUPPORTED_EVENTS_FOR_USAGE_LOG.each do |action|
|
|
|
|
expect(Gitlab::UsageDataCounters::HLLRedisCounter.known_event?("i_ecosystem_slack_service_#{action}_notification")).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'hook data includes a user object' do
|
|
|
|
let_it_be(:user) { create_default(:user) }
|
|
|
|
let_it_be(:project) { create_default(:project, :repository, :wiki_repo) }
|
|
|
|
|
|
|
|
shared_examples 'increases the usage data counter' do |event_name|
|
|
|
|
it 'increases the usage data counter' do
|
|
|
|
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(event_name, values: user.id).and_call_original
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
slack_integration.execute(data)
|
2021-03-10 19:09:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'event is not supported for usage log' do
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
|
|
|
|
|
|
|
|
it 'does not increase the usage data counter' do
|
|
|
|
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with('i_ecosystem_slack_service_pipeline_notification', values: user.id)
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
slack_integration.execute(data)
|
2021-03-10 19:09:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'issue notification' do
|
|
|
|
let_it_be(:issue) { create(:issue) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { issue.to_hook_data(user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_issue_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'push notification' do
|
|
|
|
let(:data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_push_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'deployment notification' do
|
|
|
|
let_it_be(:deployment) { create(:deployment, user: user) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-04-29 14:10:23 -04:00
|
|
|
let(:data) { Gitlab::DataBuilder::Deployment.build(deployment, Time.current) }
|
2021-03-10 19:09:38 -05:00
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_deployment_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'wiki_page notification' do
|
2021-04-20 20:11:06 -04:00
|
|
|
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, message: 'user created page: Awesome wiki_page') }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
|
|
|
|
|
2021-04-20 20:11:06 -04:00
|
|
|
before do
|
|
|
|
# Skip this method that is not relevant to this test to prevent having
|
|
|
|
# to update project which is frozen
|
|
|
|
allow(project.wiki).to receive(:after_wiki_activity)
|
|
|
|
end
|
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_wiki_page_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge_request notification' do
|
|
|
|
let_it_be(:merge_request) { create(:merge_request) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { merge_request.to_hook_data(user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_merge_request_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'note notification' do
|
|
|
|
let_it_be(:issue_note) { create(:note_on_issue, note: 'issue note') }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { Gitlab::DataBuilder::Note.build(issue_note, user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_note_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'tag_push notification' do
|
|
|
|
let(:oldrev) { Gitlab::Git::BLANK_SHA }
|
|
|
|
let(:newrev) { '8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b' } # gitlab-test: git rev-parse refs/tags/v1.1.0
|
|
|
|
let(:ref) { 'refs/tags/v1.1.0' }
|
|
|
|
let(:data) { Git::TagHooksService.new(project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref }).send(:push_data) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_tag_push_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'confidential note notification' do
|
|
|
|
let_it_be(:confidential_issue_note) { create(:note_on_issue, note: 'issue note', confidential: true) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { Gitlab::DataBuilder::Note.build(confidential_issue_note, user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_confidential_note_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'confidential issue notification' do
|
|
|
|
let_it_be(:issue) { create(:issue, confidential: true) }
|
2021-04-09 08:09:12 -04:00
|
|
|
|
2021-03-10 19:09:38 -05:00
|
|
|
let(:data) { issue.to_hook_data(user) }
|
|
|
|
|
|
|
|
it_behaves_like 'increases the usage data counter', 'i_ecosystem_slack_service_confidential_issue_notification'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'hook data does not include a user' do
|
|
|
|
let(:data) { Gitlab::DataBuilder::Pipeline.build(create(:ci_pipeline)) }
|
|
|
|
|
|
|
|
it 'does not increase the usage data counter' do
|
|
|
|
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
slack_integration.execute(data)
|
2021-03-10 19:09:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-25 14:36:37 -05:00
|
|
|
end
|