diff options
Diffstat (limited to 'spec/models/project_services')
6 files changed, 335 insertions, 384 deletions
diff --git a/spec/models/project_services/chat_message/pipeline_message_spec.rb b/spec/models/project_services/chat_message/pipeline_message_spec.rb index e99148d1d1f..7c3e48f572a 100644 --- a/spec/models/project_services/chat_message/pipeline_message_spec.rb +++ b/spec/models/project_services/chat_message/pipeline_message_spec.rb @@ -55,475 +55,324 @@ describe ChatMessage::PipelineMessage do allow(Gitlab::UrlBuilder).to receive(:build).with(args[:user]).and_return("http://example.gitlab.com/hacker") end - context 'when the fancy_pipeline_slack_notifications feature flag is disabled' do - before do - stub_feature_flags(fancy_pipeline_slack_notifications: false) - end + it 'returns an empty pretext' do + expect(subject.pretext).to be_empty + end + + it "returns the pipeline summary in the activity's title" do + expect(subject.activity[:title]).to eq( + "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ + " of branch [develop](http://example.gitlab.com/commits/develop)" \ + " by The Hacker (hacker) has passed" + ) + end - it 'returns an empty pretext' do - expect(subject.pretext).to be_empty + context "when the pipeline failed" do + before do + args[:object_attributes][:status] = 'failed' end - it "returns the pipeline summary in the activity's title" do + it "returns the summary with a 'failed' status" do expect(subject.activity[:title]).to eq( "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) passed" + " by The Hacker (hacker) has failed" ) end + end - context "when the pipeline failed" do - before do - args[:object_attributes][:status] = 'failed' - end - - it "returns the summary with a 'failed' status" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) failed" - ) - end - end - - context 'when no user is provided because the pipeline was triggered by the API' do - before do - args[:user] = nil - end - - it "returns the summary with 'API' as the username" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by API passed" - ) - end - end - - it "returns a link to the project in the activity's subtitle" do - expect(subject.activity[:subtitle]).to eq("in [project_name](http://example.gitlab.com)") - end - - it "returns the build duration in the activity's text property" do - expect(subject.activity[:text]).to eq("in 02:00:10") - end - - it "returns the user's avatar image URL in the activity's image property" do - expect(subject.activity[:image]).to eq("http://example.com/avatar") - end - - context 'when the user does not have an avatar' do - before do - args[:user][:avatar_url] = nil - end - - it "returns an empty string in the activity's image property" do - expect(subject.activity[:image]).to be_empty - end + context "when the pipeline passed with warnings" do + before do + args[:object_attributes][:detailed_status] = 'passed with warnings' end - it "returns the pipeline summary as the attachment's text property" do - expect(subject.attachments.first[:text]).to eq( - "<http://example.gitlab.com|project_name>:" \ - " Pipeline <http://example.gitlab.com/pipelines/123|#123>" \ - " of branch <http://example.gitlab.com/commits/develop|develop>" \ - " by The Hacker (hacker) passed in 02:00:10" + it "returns the summary with a 'passed with warnings' status" do + expect(subject.activity[:title]).to eq( + "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ + " of branch [develop](http://example.gitlab.com/commits/develop)" \ + " by The Hacker (hacker) has passed with warnings" ) end - - it "returns 'good' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('good') - end - - context "when the pipeline failed" do - before do - args[:object_attributes][:status] = 'failed' - end - - it "returns 'danger' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('danger') - end - end - - context 'when rendering markdown' do - before do - args[:markdown] = true - end - - it 'returns the pipeline summary as the attachments in markdown format' do - expect(subject.attachments).to eq( - "[project_name](http://example.gitlab.com):" \ - " Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) passed in 02:00:10" - ) - end - end - - context 'when ref type is tag' do - before do - args[:object_attributes][:tag] = true - args[:object_attributes][:ref] = 'new_tag' - end - - it "returns the pipeline summary in the activity's title" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of tag [new_tag](http://example.gitlab.com/-/tags/new_tag)" \ - " by The Hacker (hacker) passed" - ) - end - - it "returns the pipeline summary as the attachment's text property" do - expect(subject.attachments.first[:text]).to eq( - "<http://example.gitlab.com|project_name>:" \ - " Pipeline <http://example.gitlab.com/pipelines/123|#123>" \ - " of tag <http://example.gitlab.com/-/tags/new_tag|new_tag>" \ - " by The Hacker (hacker) passed in 02:00:10" - ) - end - - context 'when rendering markdown' do - before do - args[:markdown] = true - end - - it 'returns the pipeline summary as the attachments in markdown format' do - expect(subject.attachments).to eq( - "[project_name](http://example.gitlab.com):" \ - " Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of tag [new_tag](http://example.gitlab.com/-/tags/new_tag)" \ - " by The Hacker (hacker) passed in 02:00:10" - ) - end - end - end end - context 'when the fancy_pipeline_slack_notifications feature flag is enabled' do + context 'when no user is provided because the pipeline was triggered by the API' do before do - stub_feature_flags(fancy_pipeline_slack_notifications: true) - end - - it 'returns an empty pretext' do - expect(subject.pretext).to be_empty + args[:user] = nil end - it "returns the pipeline summary in the activity's title" do + it "returns the summary with 'API' as the username" do expect(subject.activity[:title]).to eq( "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) has passed" + " by API has passed" ) end + end - context "when the pipeline failed" do - before do - args[:object_attributes][:status] = 'failed' - end + it "returns a link to the project in the activity's subtitle" do + expect(subject.activity[:subtitle]).to eq("in [project_name](http://example.gitlab.com)") + end - it "returns the summary with a 'failed' status" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) has failed" - ) - end - end + it "returns the build duration in the activity's text property" do + expect(subject.activity[:text]).to eq("in 02:00:10") + end - context "when the pipeline passed with warnings" do - before do - args[:object_attributes][:detailed_status] = 'passed with warnings' - end + it "returns the user's avatar image URL in the activity's image property" do + expect(subject.activity[:image]).to eq("http://example.com/avatar") + end - it "returns the summary with a 'passed with warnings' status" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) has passed with warnings" - ) - end + context 'when the user does not have an avatar' do + before do + args[:user][:avatar_url] = nil end - context 'when no user is provided because the pipeline was triggered by the API' do - before do - args[:user] = nil - end - - it "returns the summary with 'API' as the username" do - expect(subject.activity[:title]).to eq( - "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by API has passed" - ) - end + it "returns an empty string in the activity's image property" do + expect(subject.activity[:image]).to be_empty end + end - it "returns a link to the project in the activity's subtitle" do - expect(subject.activity[:subtitle]).to eq("in [project_name](http://example.gitlab.com)") - end + it "returns the pipeline summary as the attachment's fallback property" do + expect(subject.attachments.first[:fallback]).to eq( + "<http://example.gitlab.com|project_name>:" \ + " Pipeline <http://example.gitlab.com/pipelines/123|#123>" \ + " of branch <http://example.gitlab.com/commits/develop|develop>" \ + " by The Hacker (hacker) has passed in 02:00:10" + ) + end - it "returns the build duration in the activity's text property" do - expect(subject.activity[:text]).to eq("in 02:00:10") - end + it "returns 'good' as the attachment's color property" do + expect(subject.attachments.first[:color]).to eq('good') + end - it "returns the user's avatar image URL in the activity's image property" do - expect(subject.activity[:image]).to eq("http://example.com/avatar") + context "when the pipeline failed" do + before do + args[:object_attributes][:status] = 'failed' end - context 'when the user does not have an avatar' do - before do - args[:user][:avatar_url] = nil - end - - it "returns an empty string in the activity's image property" do - expect(subject.activity[:image]).to be_empty - end + it "returns 'danger' as the attachment's color property" do + expect(subject.attachments.first[:color]).to eq('danger') end + end - it "returns the pipeline summary as the attachment's fallback property" do - expect(subject.attachments.first[:fallback]).to eq( - "<http://example.gitlab.com|project_name>:" \ - " Pipeline <http://example.gitlab.com/pipelines/123|#123>" \ - " of branch <http://example.gitlab.com/commits/develop|develop>" \ - " by The Hacker (hacker) has passed in 02:00:10" - ) + context "when the pipeline passed with warnings" do + before do + args[:object_attributes][:detailed_status] = 'passed with warnings' end - it "returns 'good' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('good') + it "returns 'warning' as the attachment's color property" do + expect(subject.attachments.first[:color]).to eq('warning') end + end - context "when the pipeline failed" do - before do - args[:object_attributes][:status] = 'failed' - end + it "returns the committer's name and username as the attachment's author_name property" do + expect(subject.attachments.first[:author_name]).to eq('The Hacker (hacker)') + end - it "returns 'danger' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('danger') - end - end + it "returns the committer's avatar URL as the attachment's author_icon property" do + expect(subject.attachments.first[:author_icon]).to eq('http://example.com/avatar') + end - context "when the pipeline passed with warnings" do - before do - args[:object_attributes][:detailed_status] = 'passed with warnings' - end + it "returns the committer's GitLab profile URL as the attachment's author_link property" do + expect(subject.attachments.first[:author_link]).to eq('http://example.gitlab.com/hacker') + end - it "returns 'warning' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('warning') - end + context 'when no user is provided because the pipeline was triggered by the API' do + before do + args[:user] = nil end it "returns the committer's name and username as the attachment's author_name property" do - expect(subject.attachments.first[:author_name]).to eq('The Hacker (hacker)') + expect(subject.attachments.first[:author_name]).to eq('API') end - it "returns the committer's avatar URL as the attachment's author_icon property" do - expect(subject.attachments.first[:author_icon]).to eq('http://example.com/avatar') + it "returns nil as the attachment's author_icon property" do + expect(subject.attachments.first[:author_icon]).to be_nil end - it "returns the committer's GitLab profile URL as the attachment's author_link property" do - expect(subject.attachments.first[:author_link]).to eq('http://example.gitlab.com/hacker') + it "returns nil as the attachment's author_link property" do + expect(subject.attachments.first[:author_link]).to be_nil end + end - context 'when no user is provided because the pipeline was triggered by the API' do - before do - args[:user] = nil - end + it "returns the pipeline ID, status, and duration as the attachment's title property" do + expect(subject.attachments.first[:title]).to eq("Pipeline #123 has passed in 02:00:10") + end - it "returns the committer's name and username as the attachment's author_name property" do - expect(subject.attachments.first[:author_name]).to eq('API') - end + it "returns the pipeline URL as the attachment's title_link property" do + expect(subject.attachments.first[:title_link]).to eq("http://example.gitlab.com/pipelines/123") + end - it "returns nil as the attachment's author_icon property" do - expect(subject.attachments.first[:author_icon]).to be_nil - end + it "returns two attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(2) + end - it "returns nil as the attachment's author_link property" do - expect(subject.attachments.first[:author_link]).to be_nil - end - end + it "returns the commit message as the attachment's second field property" do + expect(subject.attachments.first[:fields][0]).to eq({ + title: "Branch", + value: "<http://example.gitlab.com/commits/develop|develop>", + short: true + }) + end - it "returns the pipeline ID, status, and duration as the attachment's title property" do - expect(subject.attachments.first[:title]).to eq("Pipeline #123 has passed in 02:00:10") - end + it "returns the ref name and link as the attachment's second field property" do + expect(subject.attachments.first[:fields][1]).to eq({ + title: "Commit", + value: "<http://example.com/commit|A test commit message>", + short: true + }) + end - it "returns the pipeline URL as the attachment's title_link property" do - expect(subject.attachments.first[:title_link]).to eq("http://example.gitlab.com/pipelines/123") + context "when a job in the pipeline fails" do + before do + args[:builds] = [ + { id: 1, name: "rspec", status: "failed", stage: "test" }, + { id: 2, name: "karma", status: "success", stage: "test" } + ] end - it "returns two attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(2) + it "returns four attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(4) end - it "returns the commit message as the attachment's second field property" do - expect(subject.attachments.first[:fields][0]).to eq({ - title: "Branch", - value: "<http://example.gitlab.com/commits/develop|develop>", + it "returns the stage name and link to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do + expect(subject.attachments.first[:fields][2]).to eq({ + title: "Failed stage", + value: "<http://example.gitlab.com/pipelines/123/failures|test>", short: true }) end - it "returns the ref name and link as the attachment's second field property" do - expect(subject.attachments.first[:fields][1]).to eq({ - title: "Commit", - value: "<http://example.com/commit|A test commit message>", + it "returns the job name and link as the attachment's fourth field property" do + expect(subject.attachments.first[:fields][3]).to eq({ + title: "Failed job", + value: "<http://example.gitlab.com/-/jobs/1|rspec>", short: true }) end + end - context "when a job in the pipeline fails" do - before do - args[:builds] = [ - { id: 1, name: "rspec", status: "failed", stage: "test" }, - { id: 2, name: "karma", status: "success", stage: "test" } - ] - end - - it "returns four attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(4) - end - - it "returns the stage name and link to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do - expect(subject.attachments.first[:fields][2]).to eq({ - title: "Failed stage", - value: "<http://example.gitlab.com/pipelines/123/failures|test>", - short: true - }) - end - - it "returns the job name and link as the attachment's fourth field property" do - expect(subject.attachments.first[:fields][3]).to eq({ - title: "Failed job", - value: "<http://example.gitlab.com/-/jobs/1|rspec>", - short: true - }) + context "when lots of jobs across multiple stages fail" do + before do + args[:builds] = (1..25).map do |i| + { id: i, name: "job-#{i}", status: "failed", stage: "stage-" + ((i % 3) + 1).to_s } end end - context "when lots of jobs across multiple stages fail" do - before do - args[:builds] = (1..25).map do |i| - { id: i, name: "job-#{i}", status: "failed", stage: "stage-" + ((i % 3) + 1).to_s } - end - end + it "returns the stage names and links to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do + expect(subject.attachments.first[:fields][2]).to eq({ + title: "Failed stages", + value: "<http://example.gitlab.com/pipelines/123/failures|stage-2>, <http://example.gitlab.com/pipelines/123/failures|stage-1>, <http://example.gitlab.com/pipelines/123/failures|stage-3>", + short: true + }) + end - it "returns the stage names and links to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do - expect(subject.attachments.first[:fields][2]).to eq({ - title: "Failed stages", - value: "<http://example.gitlab.com/pipelines/123/failures|stage-2>, <http://example.gitlab.com/pipelines/123/failures|stage-1>, <http://example.gitlab.com/pipelines/123/failures|stage-3>", - short: true - }) + it "returns the job names and links as the attachment's fourth field property" do + expected_jobs = 25.downto(16).map do |i| + "<http://example.gitlab.com/-/jobs/#{i}|job-#{i}>" end - it "returns the job names and links as the attachment's fourth field property" do - expected_jobs = 25.downto(16).map do |i| - "<http://example.gitlab.com/-/jobs/#{i}|job-#{i}>" - end + expected_jobs << "and <http://example.gitlab.com/pipelines/123/failures|15 more>" - expected_jobs << "and <http://example.gitlab.com/pipelines/123/failures|15 more>" - - expect(subject.attachments.first[:fields][3]).to eq({ - title: "Failed jobs", - value: expected_jobs.join(", "), - short: true - }) - end + expect(subject.attachments.first[:fields][3]).to eq({ + title: "Failed jobs", + value: expected_jobs.join(", "), + short: true + }) end + end - context "when jobs succeed on retries" do - before do - args[:builds] = [ - { id: 1, name: "job-1", status: "failed", stage: "stage-1" }, - { id: 2, name: "job-2", status: "failed", stage: "stage-2" }, - { id: 3, name: "job-3", status: "failed", stage: "stage-3" }, - { id: 7, name: "job-1", status: "failed", stage: "stage-1" }, - { id: 8, name: "job-1", status: "success", stage: "stage-1" } - ] - end - - it "do not return a job which succeeded on retry" do - expected_jobs = [ - "<http://example.gitlab.com/-/jobs/3|job-3>", - "<http://example.gitlab.com/-/jobs/2|job-2>" - ] - - expect(subject.attachments.first[:fields][3]).to eq( - title: "Failed jobs", - value: expected_jobs.join(", "), - short: true - ) - end + context "when jobs succeed on retries" do + before do + args[:builds] = [ + { id: 1, name: "job-1", status: "failed", stage: "stage-1" }, + { id: 2, name: "job-2", status: "failed", stage: "stage-2" }, + { id: 3, name: "job-3", status: "failed", stage: "stage-3" }, + { id: 7, name: "job-1", status: "failed", stage: "stage-1" }, + { id: 8, name: "job-1", status: "success", stage: "stage-1" } + ] + end + + it "do not return a job which succeeded on retry" do + expected_jobs = [ + "<http://example.gitlab.com/-/jobs/3|job-3>", + "<http://example.gitlab.com/-/jobs/2|job-2>" + ] + + expect(subject.attachments.first[:fields][3]).to eq( + title: "Failed jobs", + value: expected_jobs.join(", "), + short: true + ) end + end - context "when jobs failed even on retries" do - before do - args[:builds] = [ - { id: 1, name: "job-1", status: "failed", stage: "stage-1" }, - { id: 2, name: "job-2", status: "failed", stage: "stage-2" }, - { id: 3, name: "job-3", status: "failed", stage: "stage-3" }, - { id: 7, name: "job-1", status: "failed", stage: "stage-1" }, - { id: 8, name: "job-1", status: "failed", stage: "stage-1" } - ] - end - - it "returns only first instance of the failed job" do - expected_jobs = [ - "<http://example.gitlab.com/-/jobs/3|job-3>", - "<http://example.gitlab.com/-/jobs/2|job-2>", - "<http://example.gitlab.com/-/jobs/1|job-1>" - ] - - expect(subject.attachments.first[:fields][3]).to eq( - title: "Failed jobs", - value: expected_jobs.join(", "), - short: true - ) - end + context "when jobs failed even on retries" do + before do + args[:builds] = [ + { id: 1, name: "job-1", status: "failed", stage: "stage-1" }, + { id: 2, name: "job-2", status: "failed", stage: "stage-2" }, + { id: 3, name: "job-3", status: "failed", stage: "stage-3" }, + { id: 7, name: "job-1", status: "failed", stage: "stage-1" }, + { id: 8, name: "job-1", status: "failed", stage: "stage-1" } + ] + end + + it "returns only first instance of the failed job" do + expected_jobs = [ + "<http://example.gitlab.com/-/jobs/3|job-3>", + "<http://example.gitlab.com/-/jobs/2|job-2>", + "<http://example.gitlab.com/-/jobs/1|job-1>" + ] + + expect(subject.attachments.first[:fields][3]).to eq( + title: "Failed jobs", + value: expected_jobs.join(", "), + short: true + ) end + end - context "when the CI config file contains a YAML error" do - let(:has_yaml_errors) { true } - - it "returns three attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(3) - end + context "when the CI config file contains a YAML error" do + let(:has_yaml_errors) { true } - it "returns the YAML error deatils as the attachment's third field property" do - expect(subject.attachments.first[:fields][2]).to eq({ - title: "Invalid CI config YAML file", - value: "yaml error description here", - short: false - }) - end + it "returns three attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(3) end - it "returns the project's name as the attachment's footer property" do - expect(subject.attachments.first[:footer]).to eq("project_name") + it "returns the YAML error deatils as the attachment's third field property" do + expect(subject.attachments.first[:fields][2]).to eq({ + title: "Invalid CI config YAML file", + value: "yaml error description here", + short: false + }) end + end - it "returns the project's avatar URL as the attachment's footer_icon property" do - expect(subject.attachments.first[:footer_icon]).to eq("http://example.com/project_avatar") - end + it "returns the project's name as the attachment's footer property" do + expect(subject.attachments.first[:footer]).to eq("project_name") + end - it "returns the pipeline's timestamp as the attachment's ts property" do - expected_ts = Time.parse(args[:object_attributes][:finished_at]).to_i - expect(subject.attachments.first[:ts]).to eq(expected_ts) - end + it "returns the project's avatar URL as the attachment's footer_icon property" do + expect(subject.attachments.first[:footer_icon]).to eq("http://example.com/project_avatar") + end - context 'when rendering markdown' do - before do - args[:markdown] = true - end + it "returns the pipeline's timestamp as the attachment's ts property" do + expected_ts = Time.parse(args[:object_attributes][:finished_at]).to_i + expect(subject.attachments.first[:ts]).to eq(expected_ts) + end - it 'returns the pipeline summary as the attachments in markdown format' do - expect(subject.attachments).to eq( - "[project_name](http://example.gitlab.com):" \ - " Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ - " of branch [develop](http://example.gitlab.com/commits/develop)" \ - " by The Hacker (hacker) has passed in 02:00:10" - ) - end + context 'when rendering markdown' do + before do + args[:markdown] = true + end + + it 'returns the pipeline summary as the attachments in markdown format' do + expect(subject.attachments).to eq( + "[project_name](http://example.gitlab.com):" \ + " Pipeline [#123](http://example.gitlab.com/pipelines/123)" \ + " of branch [develop](http://example.gitlab.com/commits/develop)" \ + " by The Hacker (hacker) has passed in 02:00:10" + ) end end end diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index badc964db16..88a93eef214 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -65,7 +65,7 @@ describe IrkerService do conn = @irker_server.accept conn.each_line do |line| - msg = JSON.parse(line.chomp("\n")) + msg = Gitlab::Json.parse(line.chomp("\n")) expect(msg.keys).to match_array(%w(to privmsg)) expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits", "irc://test.net/#test"]) diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 32e6b5afce5..a0d36f0a238 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -69,11 +69,23 @@ describe JiraService do end describe '.reference_pattern' do - it_behaves_like 'allows project key on reference pattern' + using RSpec::Parameterized::TableSyntax - it 'does not allow # on the code' do - expect(described_class.reference_pattern.match('#123')).to be_nil - expect(described_class.reference_pattern.match('1#23#12')).to be_nil + where(:key, :result) do + '#123' | '' + '1#23#12' | '' + 'JIRA-1234A' | 'JIRA-1234' + 'JIRA-1234-some_tag' | 'JIRA-1234' + 'JIRA-1234_some_tag' | 'JIRA-1234' + 'EXT_EXT-1234' | 'EXT_EXT-1234' + 'EXT3_EXT-1234' | 'EXT3_EXT-1234' + '3EXT_EXT-1234' | '' + end + + with_them do + specify do + expect(described_class.reference_pattern.match(key).to_s).to eq(result) + end end end @@ -570,6 +582,79 @@ describe JiraService do end end + describe '#create_cross_reference_note' do + let_it_be(:user) { build_stubbed(:user) } + let_it_be(:project) { create(:project, :repository) } + let(:jira_service) do + described_class.new( + project: project, + url: url, + username: username, + password: password + ) + end + let(:jira_issue) { ExternalIssue.new('JIRA-123', project) } + + subject { jira_service.create_cross_reference_note(jira_issue, resource, user) } + + shared_examples 'creates a comment on Jira' do + let(:issue_url) { "#{url}/rest/api/2/issue/JIRA-123" } + let(:comment_url) { "#{issue_url}/comment" } + let(:remote_link_url) { "#{issue_url}/remotelink" } + + before do + allow(JIRA::Resource::Remotelink).to receive(:all).and_return([]) + stub_request(:get, issue_url).with(basic_auth: [username, password]) + stub_request(:post, comment_url).with(basic_auth: [username, password]) + stub_request(:post, remote_link_url).with(basic_auth: [username, password]) + end + + it 'creates a comment on Jira' do + subject + + expect(WebMock).to have_requested(:post, comment_url).with( + body: /mentioned this issue in/ + ).once + end + end + + context 'when resource is a commit' do + let(:resource) { project.commit('master') } + + context 'when disabled' do + before do + allow_next_instance_of(JiraService) do |instance| + allow(instance).to receive(:commit_events) { false } + end + end + + it { is_expected.to eq('Events for commits are disabled.') } + end + + context 'when enabled' do + it_behaves_like 'creates a comment on Jira' + end + end + + context 'when resource is a merge request' do + let(:resource) { build_stubbed(:merge_request, source_project: project) } + + context 'when disabled' do + before do + allow_next_instance_of(JiraService) do |instance| + allow(instance).to receive(:merge_requests_events) { false } + end + end + + it { is_expected.to eq('Events for merge requests are disabled.') } + end + + context 'when enabled' do + it_behaves_like 'creates a comment on Jira' + end + end + end + describe '#test' do let(:jira_service) do described_class.new( diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb index 87e482059f2..836181929e3 100644 --- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb +++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb @@ -121,5 +121,12 @@ describe MattermostSlashCommandsService do end end end + + describe '#chat_responder' do + it 'returns the responder to use for Mattermost' do + expect(described_class.new.chat_responder) + .to eq(Gitlab::Chat::Responder::Mattermost) + end + end end end diff --git a/spec/models/project_services/microsoft_teams_service_spec.rb b/spec/models/project_services/microsoft_teams_service_spec.rb index d93b8a2cb40..425599c73d4 100644 --- a/spec/models/project_services/microsoft_teams_service_spec.rb +++ b/spec/models/project_services/microsoft_teams_service_spec.rb @@ -121,7 +121,7 @@ describe MicrosoftTeamsService do message: "user created page: Awesome wiki_page" } end - let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) } + let(:wiki_page) { create(:wiki_page, wiki: project.wiki, **opts) } let(:wiki_page_sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') } it "calls Microsoft Teams API" do diff --git a/spec/models/project_services/webex_teams_service_spec.rb b/spec/models/project_services/webex_teams_service_spec.rb new file mode 100644 index 00000000000..38977ef3b7d --- /dev/null +++ b/spec/models/project_services/webex_teams_service_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe WebexTeamsService do + it_behaves_like "chat service", "Webex Teams" do + let(:client_arguments) { webhook_url } + let(:content_key) { :markdown } + end +end |