diff options
Diffstat (limited to 'spec/models/project_services/chat_message')
9 files changed, 0 insertions, 1480 deletions
diff --git a/spec/models/project_services/chat_message/alert_message_spec.rb b/spec/models/project_services/chat_message/alert_message_spec.rb deleted file mode 100644 index 4d400990789..00000000000 --- a/spec/models/project_services/chat_message/alert_message_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::AlertMessage do - subject { described_class.new(args) } - - let_it_be(:start_time) { Time.current } - - let(:alert) { create(:alert_management_alert, started_at: start_time) } - - let(:args) do - { - project_name: 'project_name', - project_url: 'http://example.com' - }.merge(Gitlab::DataBuilder::Alert.build(alert)) - end - - describe '#message' do - it 'returns the correct message' do - expect(subject.message).to eq("Alert firing in #{args[:project_name]}") - end - end - - describe '#attachments' do - it 'returns an array of one' do - expect(subject.attachments).to be_a(Array) - expect(subject.attachments.size).to eq(1) - end - - it 'contains the correct attributes' do - attachments_item = subject.attachments.first - expect(attachments_item).to have_key(:title) - expect(attachments_item).to have_key(:title_link) - expect(attachments_item).to have_key(:color) - expect(attachments_item).to have_key(:fields) - end - - it 'returns the correct color' do - expect(subject.attachments.first[:color]).to eq("#C95823") - end - - it 'returns the correct attachment fields' do - attachments_item = subject.attachments.first - fields = attachments_item[:fields].map { |h| h[:title] } - - expect(fields).to match_array(['Severity', 'Events', 'Status', 'Start time']) - end - - it 'returns the correctly formatted time' do - time_item = subject.attachments.first[:fields].detect { |h| h[:title] == 'Start time' } - - expected_time = start_time.strftime("%B #{start_time.day.ordinalize}, %Y %l:%M%p %Z") - - expect(time_item[:value]).to eq(expected_time) - end - end -end diff --git a/spec/models/project_services/chat_message/base_message_spec.rb b/spec/models/project_services/chat_message/base_message_spec.rb deleted file mode 100644 index a7ddf230758..00000000000 --- a/spec/models/project_services/chat_message/base_message_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::BaseMessage do - let(:base_message) { described_class.new(args) } - let(:args) { { project_url: 'https://gitlab-domain.com' } } - - describe '#fallback' do - subject { base_message.fallback } - - before do - allow(base_message).to receive(:message).and_return(message) - end - - context 'without relative links' do - let(:message) { 'Just another *markdown* message' } - - it { is_expected.to eq(message) } - end - - context 'with relative links' do - let(:message) { 'Check this out ![Screenshot1](/uploads/Screenshot1.png)' } - - it { is_expected.to eq('Check this out https://gitlab-domain.com/uploads/Screenshot1.png') } - end - - context 'with multiple relative links' do - let(:message) { 'Check this out ![Screenshot1](/uploads/Screenshot1.png). And this ![Screenshot2](/uploads/Screenshot2.png)' } - - it { is_expected.to eq('Check this out https://gitlab-domain.com/uploads/Screenshot1.png. And this https://gitlab-domain.com/uploads/Screenshot2.png') } - end - end -end diff --git a/spec/models/project_services/chat_message/deployment_message_spec.rb b/spec/models/project_services/chat_message/deployment_message_spec.rb deleted file mode 100644 index 6bdf2120b36..00000000000 --- a/spec/models/project_services/chat_message/deployment_message_spec.rb +++ /dev/null @@ -1,164 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::DeploymentMessage do - describe '#pretext' do - it 'returns a message with the data returned by the deployment data builder' do - environment = create(:environment, name: "myenvironment") - project = create(:project, :repository) - commit = project.commit('HEAD') - deployment = create(:deployment, status: :success, environment: environment, project: project, sha: commit.sha) - data = Gitlab::DataBuilder::Deployment.build(deployment) - - message = described_class.new(data) - - expect(message.pretext).to eq("Deploy to myenvironment succeeded") - end - - it 'returns a message for a successful deployment' do - data = { - status: 'success', - environment: 'production' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Deploy to production succeeded') - end - - it 'returns a message for a failed deployment' do - data = { - status: 'failed', - environment: 'production' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Deploy to production failed') - end - - it 'returns a message for a canceled deployment' do - data = { - status: 'canceled', - environment: 'production' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Deploy to production canceled') - end - - it 'returns a message for a deployment to another environment' do - data = { - status: 'success', - environment: 'staging' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Deploy to staging succeeded') - end - - it 'returns a message for a deployment with any other status' do - data = { - status: 'unknown', - environment: 'staging' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Deploy to staging unknown') - end - - it 'returns a message for a running deployment' do - data = { - status: 'running', - environment: 'production' - } - - message = described_class.new(data) - - expect(message.pretext).to eq('Starting deploy to production') - end - end - - describe '#attachments' do - def deployment_data(params) - { - object_kind: "deployment", - status: "success", - deployable_id: 3, - deployable_url: "deployable_url", - environment: "sandbox", - project: { - name: "greatproject", - web_url: "project_web_url", - path_with_namespace: "project_path_with_namespace" - }, - user: { - name: "Jane Person", - username: "jane" - }, - user_url: "user_url", - short_sha: "12345678", - commit_url: "commit_url", - commit_title: "commit title text" - }.merge(params) - end - - it 'returns attachments with the data returned by the deployment data builder' do - user = create(:user, name: "John Smith", username: "smith") - namespace = create(:namespace, name: "myspace") - project = create(:project, :repository, namespace: namespace, name: "myproject") - commit = project.commit('HEAD') - environment = create(:environment, name: "myenvironment", project: project) - ci_build = create(:ci_build, project: project) - deployment = create(:deployment, :success, deployable: ci_build, environment: environment, project: project, user: user, sha: commit.sha) - job_url = Gitlab::Routing.url_helpers.project_job_url(project, ci_build) - commit_url = Gitlab::UrlBuilder.build(deployment.commit) - user_url = Gitlab::Routing.url_helpers.user_url(user) - data = Gitlab::DataBuilder::Deployment.build(deployment) - - message = described_class.new(data) - - expect(message.attachments).to eq([{ - text: "[myspace/myproject](#{project.web_url}) with job [##{ci_build.id}](#{job_url}) by [John Smith (smith)](#{user_url})\n[#{deployment.short_sha}](#{commit_url}): #{commit.title}", - color: "good" - }]) - end - - it 'returns attachments for a failed deployment' do - data = deployment_data(status: 'failed') - - message = described_class.new(data) - - expect(message.attachments).to eq([{ - text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text", - color: "danger" - }]) - end - - it 'returns attachments for a canceled deployment' do - data = deployment_data(status: 'canceled') - - message = described_class.new(data) - - expect(message.attachments).to eq([{ - text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text", - color: "warning" - }]) - end - - it 'uses a neutral color for a deployment with any other status' do - data = deployment_data(status: 'some-new-status-we-make-in-the-future') - - message = described_class.new(data) - - expect(message.attachments).to eq([{ - text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text", - color: "#334455" - }]) - end - end -end diff --git a/spec/models/project_services/chat_message/issue_message_spec.rb b/spec/models/project_services/chat_message/issue_message_spec.rb deleted file mode 100644 index 4701ef3e49e..00000000000 --- a/spec/models/project_services/chat_message/issue_message_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::IssueMessage do - subject { described_class.new(args) } - - let(:args) do - { - user: { - name: 'Test User', - username: 'test.user', - avatar_url: 'http://someavatar.com' - }, - project_name: 'project_name', - project_url: 'http://somewhere.com', - - object_attributes: { - title: 'Issue title', - id: 10, - iid: 100, - assignee_id: 1, - url: 'http://url.com', - action: 'open', - state: 'opened', - description: 'issue description' - } - } - end - - context 'without markdown' do - let(:color) { '#C95823' } - - describe '#initialize' do - before do - args[:object_attributes][:description] = nil - end - - it 'returns a non-null description' do - expect(subject.description).to eq('') - end - end - - context 'open' do - it 'returns a message regarding opening of issues' do - expect(subject.pretext).to eq( - '[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)') - expect(subject.attachments).to eq([ - { - title: "#100 Issue title", - title_link: "http://url.com", - text: "issue description", - color: color - } - ]) - end - end - - context 'close' do - before do - args[:object_attributes][:action] = 'close' - args[:object_attributes][:state] = 'closed' - end - - it 'returns a message regarding closing of issues' do - expect(subject.pretext). to eq( - '[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by Test User (test.user)') - expect(subject.attachments).to be_empty - end - end - - context 'reopen' do - before do - args[:object_attributes][:action] = 'reopen' - args[:object_attributes][:state] = 'opened' - end - - it 'returns a message regarding reopening of issues' do - expect(subject.pretext) - .to eq('[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> opened by Test User (test.user)') - expect(subject.attachments).to be_empty - end - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - context 'open' do - it 'returns a message regarding opening of issues' do - expect(subject.pretext).to eq( - '[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) opened by Test User (test.user)') - expect(subject.attachments).to eq('issue description') - expect(subject.activity).to eq({ - title: 'Issue opened by Test User (test.user)', - subtitle: 'in [project_name](http://somewhere.com)', - text: '[#100 Issue title](http://url.com)', - image: 'http://someavatar.com' - }) - end - end - - context 'close' do - before do - args[:object_attributes][:action] = 'close' - args[:object_attributes][:state] = 'closed' - end - - it 'returns a message regarding closing of issues' do - expect(subject.pretext). to eq( - '[[project_name](http://somewhere.com)] Issue [#100 Issue title](http://url.com) closed by Test User (test.user)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq({ - title: 'Issue closed by Test User (test.user)', - subtitle: 'in [project_name](http://somewhere.com)', - text: '[#100 Issue title](http://url.com)', - image: 'http://someavatar.com' - }) - end - end - end -end diff --git a/spec/models/project_services/chat_message/merge_message_spec.rb b/spec/models/project_services/chat_message/merge_message_spec.rb deleted file mode 100644 index 71cfe3ff45b..00000000000 --- a/spec/models/project_services/chat_message/merge_message_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::MergeMessage do - subject { described_class.new(args) } - - let(:args) do - { - user: { - name: 'Test User', - username: 'test.user', - avatar_url: 'http://someavatar.com' - }, - project_name: 'project_name', - project_url: 'http://somewhere.com', - - object_attributes: { - title: "Merge request title\nSecond line", - id: 10, - iid: 100, - assignee_id: 1, - url: 'http://url.com', - state: 'opened', - description: 'merge request description', - source_branch: 'source_branch', - target_branch: 'target_branch' - } - } - end - - context 'without markdown' do - let(:color) { '#345' } - - context 'open' do - it 'returns a message regarding opening of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) opened merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'close' do - before do - args[:object_attributes][:state] = 'closed' - end - it 'returns a message regarding closing of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) closed merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - context 'open' do - it 'returns a message regarding opening of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) opened merge request [!100 *Merge request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq({ - title: 'Merge request opened by Test User (test.user)', - subtitle: 'in [project_name](http://somewhere.com)', - text: '[!100 *Merge request title*](http://somewhere.com/-/merge_requests/100)', - image: 'http://someavatar.com' - }) - end - end - - context 'close' do - before do - args[:object_attributes][:state] = 'closed' - end - - it 'returns a message regarding closing of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) closed merge request [!100 *Merge request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq({ - title: 'Merge request closed by Test User (test.user)', - subtitle: 'in [project_name](http://somewhere.com)', - text: '[!100 *Merge request title*](http://somewhere.com/-/merge_requests/100)', - image: 'http://someavatar.com' - }) - end - end - end - - context 'approved' do - before do - args[:object_attributes][:action] = 'approved' - end - - it 'returns a message regarding completed approval of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) approved merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> '\ - 'in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'unapproved' do - before do - args[:object_attributes][:action] = 'unapproved' - end - - it 'returns a message regarding revocation of completed approval of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) unapproved merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> '\ - 'in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'approval' do - before do - args[:object_attributes][:action] = 'approval' - end - - it 'returns a message regarding added approval of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) added their approval to merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> '\ - 'in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'unapproval' do - before do - args[:object_attributes][:action] = 'unapproval' - end - - it 'returns a message regarding revoking approval of merge requests' do - expect(subject.pretext).to eq( - 'Test User (test.user) removed their approval from merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge request title*> '\ - 'in <http://somewhere.com|project_name>') - expect(subject.attachments).to be_empty - end - end -end diff --git a/spec/models/project_services/chat_message/note_message_spec.rb b/spec/models/project_services/chat_message/note_message_spec.rb deleted file mode 100644 index 6a741365d55..00000000000 --- a/spec/models/project_services/chat_message/note_message_spec.rb +++ /dev/null @@ -1,192 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::NoteMessage do - subject { described_class.new(args) } - - let(:color) { '#345' } - let(:args) do - { - user: { - name: 'Test User', - username: 'test.user', - avatar_url: 'http://fakeavatar' - }, - project_name: 'project_name', - project_url: 'http://somewhere.com', - repository: { - name: 'project_name', - url: 'http://somewhere.com' - }, - object_attributes: { - id: 10, - note: 'comment on a commit', - url: 'http://url.com', - noteable_type: 'Commit' - } - } - end - - context 'commit notes' do - before do - args[:object_attributes][:note] = 'comment on a commit' - args[:object_attributes][:noteable_type] = 'Commit' - args[:commit] = { - id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23', - message: "Added a commit message\ndetails\n123\n" - } - end - - context 'without markdown' do - it 'returns a message regarding notes on commits' do - expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \ - "commit 5f163b2b> in <http://somewhere.com|project_name>: " \ - "*Added a commit message*") - expect(subject.attachments).to eq([{ - text: 'comment on a commit', - color: color - }]) - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding notes on commits' do - expect(subject.pretext).to eq( - 'Test User (test.user) [commented on commit 5f163b2b](http://url.com) in [project_name](http://somewhere.com): *Added a commit message*' - ) - expect(subject.attachments).to eq('comment on a commit') - expect(subject.activity).to eq({ - title: 'Test User (test.user) [commented on commit 5f163b2b](http://url.com)', - subtitle: 'in [project_name](http://somewhere.com)', - text: 'Added a commit message', - image: 'http://fakeavatar' - }) - end - end - end - - context 'merge request notes' do - before do - args[:object_attributes][:note] = 'comment on a merge request' - args[:object_attributes][:noteable_type] = 'MergeRequest' - args[:merge_request] = { - id: 1, - iid: 30, - title: "merge request title\ndetails\n" - } - end - - context 'without markdown' do - it 'returns a message regarding notes on a merge request' do - expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \ - "merge request !30> in <http://somewhere.com|project_name>: " \ - "*merge request title*") - expect(subject.attachments).to eq([{ - text: 'comment on a merge request', - color: color - }]) - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding notes on a merge request' do - expect(subject.pretext).to eq( - 'Test User (test.user) [commented on merge request !30](http://url.com) in [project_name](http://somewhere.com): *merge request title*') - expect(subject.attachments).to eq('comment on a merge request') - expect(subject.activity).to eq({ - title: 'Test User (test.user) [commented on merge request !30](http://url.com)', - subtitle: 'in [project_name](http://somewhere.com)', - text: 'merge request title', - image: 'http://fakeavatar' - }) - end - end - end - - context 'issue notes' do - before do - args[:object_attributes][:note] = 'comment on an issue' - args[:object_attributes][:noteable_type] = 'Issue' - args[:issue] = { - id: 1, - iid: 20, - title: "issue title\ndetails\n" - } - end - - context 'without markdown' do - it 'returns a message regarding notes on an issue' do - expect(subject.pretext).to eq( - "Test User (test.user) <http://url.com|commented on " \ - "issue #20> in <http://somewhere.com|project_name>: " \ - "*issue title*") - expect(subject.attachments).to eq([{ - text: 'comment on an issue', - color: color - }]) - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding notes on an issue' do - expect(subject.pretext).to eq( - 'Test User (test.user) [commented on issue #20](http://url.com) in [project_name](http://somewhere.com): *issue title*') - expect(subject.attachments).to eq('comment on an issue') - expect(subject.activity).to eq({ - title: 'Test User (test.user) [commented on issue #20](http://url.com)', - subtitle: 'in [project_name](http://somewhere.com)', - text: 'issue title', - image: 'http://fakeavatar' - }) - end - end - end - - context 'project snippet notes' do - before do - args[:object_attributes][:note] = 'comment on a snippet' - args[:object_attributes][:noteable_type] = 'Snippet' - args[:snippet] = { - id: 5, - title: "snippet title\ndetails\n" - } - end - - context 'without markdown' do - it 'returns a message regarding notes on a project snippet' do - expect(subject.pretext).to eq("Test User (test.user) <http://url.com|commented on " \ - "snippet $5> in <http://somewhere.com|project_name>: " \ - "*snippet title*") - expect(subject.attachments).to eq([{ - text: 'comment on a snippet', - color: color - }]) - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding notes on a project snippet' do - expect(subject.pretext).to eq( - 'Test User (test.user) [commented on snippet $5](http://url.com) in [project_name](http://somewhere.com): *snippet title*') - expect(subject.attachments).to eq('comment on a snippet') - end - end - end -end diff --git a/spec/models/project_services/chat_message/pipeline_message_spec.rb b/spec/models/project_services/chat_message/pipeline_message_spec.rb deleted file mode 100644 index 4eb2f57315b..00000000000 --- a/spec/models/project_services/chat_message/pipeline_message_spec.rb +++ /dev/null @@ -1,378 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' - -RSpec.describe ChatMessage::PipelineMessage do - subject { described_class.new(args) } - - let(:args) do - { - object_attributes: { - id: 123, - sha: '97de212e80737a608d939f648d959671fb0a0142', - tag: false, - ref: 'develop', - status: 'success', - detailed_status: nil, - duration: 7210, - finished_at: "2019-05-27 11:56:36 -0300" - }, - project: { - id: 234, - name: "project_name", - path_with_namespace: 'group/project_name', - web_url: 'http://example.gitlab.com', - avatar_url: 'http://example.com/project_avatar' - }, - user: { - id: 345, - name: "The Hacker", - username: "hacker", - email: "hacker@example.gitlab.com", - avatar_url: "http://example.com/avatar" - }, - commit: { - id: "abcdef" - }, - builds: nil, - markdown: false - } - end - - let(:has_yaml_errors) { false } - - before do - test_commit = double("A test commit", committer: args[:user], title: "A test commit message") - test_project = double("A test project", commit_by: test_commit, name: args[:project][:name], web_url: args[:project][:web_url]) - allow(test_project).to receive(:avatar_url).with(no_args).and_return("/avatar") - allow(test_project).to receive(:avatar_url).with(only_path: false).and_return(args[:project][:avatar_url]) - allow(Project).to receive(:find) { test_project } - - test_pipeline = double("A test pipeline", has_yaml_errors?: has_yaml_errors, - yaml_errors: "yaml error description here") - allow(Ci::Pipeline).to receive(:find) { test_pipeline } - - allow(Gitlab::UrlBuilder).to receive(:build).with(test_commit).and_return("http://example.com/commit") - allow(Gitlab::UrlBuilder).to receive(:build).with(args[:user]).and_return("http://example.gitlab.com/hacker") - 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 - - 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) has failed" - ) - end - end - - context "when the pipeline passed with warnings" do - before do - args[:object_attributes][:detailed_status] = 'passed with warnings' - 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 - 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 - 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 - 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 '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 the pipeline passed with warnings" do - before do - args[:object_attributes][:detailed_status] = 'passed with warnings' - end - - it "returns 'warning' as the attachment's color property" do - expect(subject.attachments.first[:color]).to eq('warning') - end - 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 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 - - 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 - - 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('API') - end - - it "returns nil as the attachment's author_icon property" do - expect(subject.attachments.first[:author_icon]).to be_nil - 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 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 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 two attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(2) - 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 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 - - 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 - }) - 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 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>" - - 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 - 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 - - 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 name as the attachment's footer property" do - expect(subject.attachments.first[:footer]).to eq("project_name") - 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 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 - - 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/chat_message/push_message_spec.rb b/spec/models/project_services/chat_message/push_message_spec.rb deleted file mode 100644 index e3ba4c2aefe..00000000000 --- a/spec/models/project_services/chat_message/push_message_spec.rb +++ /dev/null @@ -1,215 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::PushMessage do - subject { described_class.new(args) } - - let(:args) do - { - after: 'after', - before: 'before', - project_name: 'project_name', - ref: 'refs/heads/master', - user_name: 'test.user', - user_avatar: 'http://someavatar.com', - project_url: 'http://url.com' - } - end - - let(:color) { '#345' } - - context 'push' do - before do - args[:commits] = [ - { message: 'message1', title: 'message1', url: 'http://url1.com', id: 'abcdefghijkl', author: { name: 'author1' } }, - { - message: 'message2' + ' w' * 100 + "\nsecondline", - title: 'message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ...', - url: 'http://url2.com', - id: '123456789012', - author: { name: 'author2' } - } - ] - end - - context 'without markdown' do - it 'returns a message regarding pushes' do - expect(subject.pretext).to eq( - 'test.user pushed to branch <http://url.com/commits/master|master> of '\ - '<http://url.com|project_name> (<http://url.com/compare/before...after|Compare changes>)') - expect(subject.attachments).to eq([{ - text: "<http://url1.com|abcdefgh>: message1 - author1\n\n"\ - "<http://url2.com|12345678>: message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ... - author2", - color: color - }]) - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding pushes' do - expect(subject.pretext).to eq( - 'test.user pushed to branch [master](http://url.com/commits/master) of [project_name](http://url.com) ([Compare changes](http://url.com/compare/before...after))') - expect(subject.attachments).to eq( - "[abcdefgh](http://url1.com): message1 - author1\n\n[12345678](http://url2.com): message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ... - author2") - expect(subject.activity).to eq( - title: 'test.user pushed to branch [master](http://url.com/commits/master)', - subtitle: 'in [project_name](http://url.com)', - text: '[Compare changes](http://url.com/compare/before...after)', - image: 'http://someavatar.com' - ) - end - end - end - - context 'tag push' do - let(:args) do - { - after: 'after', - before: Gitlab::Git::BLANK_SHA, - project_name: 'project_name', - ref: 'refs/tags/new_tag', - user_name: 'test.user', - user_avatar: 'http://someavatar.com', - project_url: 'http://url.com' - } - end - - context 'without markdown' do - it 'returns a message regarding pushes' do - expect(subject.pretext).to eq('test.user pushed new tag ' \ - '<http://url.com/-/tags/new_tag|new_tag> to ' \ - '<http://url.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding pushes' do - expect(subject.pretext).to eq( - 'test.user pushed new tag [new_tag](http://url.com/-/tags/new_tag) to [project_name](http://url.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq( - title: 'test.user pushed new tag [new_tag](http://url.com/-/tags/new_tag)', - subtitle: 'in [project_name](http://url.com)', - text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)', - image: 'http://someavatar.com' - ) - end - end - end - - context 'removed tag' do - let(:args) do - { - after: Gitlab::Git::BLANK_SHA, - before: 'before', - project_name: 'project_name', - ref: 'refs/tags/new_tag', - user_name: 'test.user', - user_avatar: 'http://someavatar.com', - project_url: 'http://url.com' - } - end - - context 'without markdown' do - it 'returns a message regarding removal of tags' do - expect(subject.pretext).to eq('test.user removed tag ' \ - 'new_tag from ' \ - '<http://url.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding removal of tags' do - expect(subject.pretext).to eq( - 'test.user removed tag new_tag from [project_name](http://url.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq( - title: 'test.user removed tag new_tag', - subtitle: 'in [project_name](http://url.com)', - text: '[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)', - image: 'http://someavatar.com' - ) - end - end - end - - context 'new branch' do - before do - args[:before] = Gitlab::Git::BLANK_SHA - end - - context 'without markdown' do - it 'returns a message regarding a new branch' do - expect(subject.pretext).to eq( - 'test.user pushed new branch <http://url.com/commits/master|master> to '\ - '<http://url.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding a new branch' do - expect(subject.pretext).to eq( - 'test.user pushed new branch [master](http://url.com/commits/master) to [project_name](http://url.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq( - title: 'test.user pushed new branch [master](http://url.com/commits/master)', - subtitle: 'in [project_name](http://url.com)', - text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)', - image: 'http://someavatar.com' - ) - end - end - end - - context 'removed branch' do - before do - args[:after] = Gitlab::Git::BLANK_SHA - end - - context 'without markdown' do - it 'returns a message regarding a removed branch' do - expect(subject.pretext).to eq( - 'test.user removed branch master from <http://url.com|project_name>') - expect(subject.attachments).to be_empty - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - it 'returns a message regarding a removed branch' do - expect(subject.pretext).to eq( - 'test.user removed branch master from [project_name](http://url.com)') - expect(subject.attachments).to be_empty - expect(subject.activity).to eq( - title: 'test.user removed branch master', - subtitle: 'in [project_name](http://url.com)', - text: '[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)', - image: 'http://someavatar.com' - ) - end - end - end -end diff --git a/spec/models/project_services/chat_message/wiki_page_message_spec.rb b/spec/models/project_services/chat_message/wiki_page_message_spec.rb deleted file mode 100644 index 04c9e5934be..00000000000 --- a/spec/models/project_services/chat_message/wiki_page_message_spec.rb +++ /dev/null @@ -1,171 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChatMessage::WikiPageMessage do - subject { described_class.new(args) } - - let(:args) do - { - user: { - name: 'Test User', - username: 'test.user', - avatar_url: 'http://someavatar.com' - }, - project_name: 'project_name', - project_url: 'http://somewhere.com', - object_attributes: { - title: 'Wiki page title', - url: 'http://url.com', - content: 'Wiki page content', - message: 'Wiki page commit message' - } - } - end - - context 'without markdown' do - describe '#pretext' do - context 'when :action == "create"' do - before do - args[:object_attributes][:action] = 'create' - end - - it 'returns a message that a new wiki page was created' do - expect(subject.pretext).to eq( - 'Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\ - '*Wiki page title*') - end - end - - context 'when :action == "update"' do - before do - args[:object_attributes][:action] = 'update' - end - - it 'returns a message that a wiki page was updated' do - expect(subject.pretext).to eq( - 'Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\ - '*Wiki page title*') - end - end - end - - describe '#attachments' do - let(:color) { '#345' } - - context 'when :action == "create"' do - before do - args[:object_attributes][:action] = 'create' - end - - it 'returns the commit message for a new wiki page' do - expect(subject.attachments).to eq([ - { - text: "Wiki page commit message", - color: color - } - ]) - end - end - - context 'when :action == "update"' do - before do - args[:object_attributes][:action] = 'update' - end - - it 'returns the commit message for an updated wiki page' do - expect(subject.attachments).to eq([ - { - text: "Wiki page commit message", - color: color - } - ]) - end - end - end - end - - context 'with markdown' do - before do - args[:markdown] = true - end - - describe '#pretext' do - context 'when :action == "create"' do - before do - args[:object_attributes][:action] = 'create' - end - - it 'returns a message that a new wiki page was created' do - expect(subject.pretext).to eq( - 'Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*') - end - end - - context 'when :action == "update"' do - before do - args[:object_attributes][:action] = 'update' - end - - it 'returns a message that a wiki page was updated' do - expect(subject.pretext).to eq( - 'Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*') - end - end - end - - describe '#attachments' do - context 'when :action == "create"' do - before do - args[:object_attributes][:action] = 'create' - end - - it 'returns the commit message for a new wiki page' do - expect(subject.attachments).to eq('Wiki page commit message') - end - end - - context 'when :action == "update"' do - before do - args[:object_attributes][:action] = 'update' - end - - it 'returns the commit message for an updated wiki page' do - expect(subject.attachments).to eq('Wiki page commit message') - end - end - end - - describe '#activity' do - context 'when :action == "create"' do - before do - args[:object_attributes][:action] = 'create' - end - - it 'returns the attachment for a new wiki page' do - expect(subject.activity).to eq({ - title: 'Test User (test.user) created [wiki page](http://url.com)', - subtitle: 'in [project_name](http://somewhere.com)', - text: 'Wiki page title', - image: 'http://someavatar.com' - }) - end - end - - context 'when :action == "update"' do - before do - args[:object_attributes][:action] = 'update' - end - - it 'returns the attachment for an updated wiki page' do - expect(subject.activity).to eq({ - title: 'Test User (test.user) edited [wiki page](http://url.com)', - subtitle: 'in [project_name](http://somewhere.com)', - text: 'Wiki page title', - image: 'http://someavatar.com' - }) - end - end - end - end -end |