Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-11-25 22:36:37 +0300
committerFelipe Artur <felipefac@gmail.com>2016-12-15 16:09:31 +0300
commit141faaacf9119ce5d765efe73c6509030ba078cd (patch)
tree1f5cf350087ad524273e0ba80c7ddcc3ce640ad8 /spec/models/project_services/chat_message
parent2d1dfae9b63d35232e4bf537a0aca9b95e2d5e72 (diff)
Mattermost Notifications Service
Diffstat (limited to 'spec/models/project_services/chat_message')
-rw-r--r--spec/models/project_services/chat_message/build_message_spec.rb57
-rw-r--r--spec/models/project_services/chat_message/issue_message_spec.rb67
-rw-r--r--spec/models/project_services/chat_message/merge_message_spec.rb51
-rw-r--r--spec/models/project_services/chat_message/note_message_spec.rb130
-rw-r--r--spec/models/project_services/chat_message/pipeline_message_spec.rb67
-rw-r--r--spec/models/project_services/chat_message/push_message_spec.rb88
-rw-r--r--spec/models/project_services/chat_message/wiki_page_message_spec.rb73
7 files changed, 533 insertions, 0 deletions
diff --git a/spec/models/project_services/chat_message/build_message_spec.rb b/spec/models/project_services/chat_message/build_message_spec.rb
new file mode 100644
index 00000000000..b71d153f814
--- /dev/null
+++ b/spec/models/project_services/chat_message/build_message_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe ChatMessage::BuildMessage do
+ subject { described_class.new(args) }
+
+ let(:args) do
+ {
+ sha: '97de212e80737a608d939f648d959671fb0a0142',
+ ref: 'develop',
+ tag: false,
+
+ project_name: 'project_name',
+ project_url: 'example.gitlab.com',
+
+ commit: {
+ status: status,
+ author_name: 'hacker',
+ duration: duration,
+ },
+ }
+ end
+
+ let(:message) { build_message }
+
+ context 'build succeeded' do
+ let(:status) { 'success' }
+ let(:color) { 'good' }
+ let(:duration) { 10 }
+ let(:message) { build_message('passed') }
+
+ it 'returns a message with information about succeeded build' do
+ expect(subject.pretext).to be_empty
+ expect(subject.fallback).to eq(message)
+ expect(subject.attachments).to eq([text: message, color: color])
+ end
+ end
+
+ context 'build failed' do
+ let(:status) { 'failed' }
+ let(:color) { 'danger' }
+ let(:duration) { 10 }
+
+ it 'returns a message with information about failed build' do
+ expect(subject.pretext).to be_empty
+ expect(subject.fallback).to eq(message)
+ expect(subject.attachments).to eq([text: message, color: color])
+ end
+ end
+
+ def build_message(status_text = status)
+ "<example.gitlab.com|project_name>:" \
+ " Commit <example.gitlab.com/commit/" \
+ "97de212e80737a608d939f648d959671fb0a0142/builds|97de212e>" \
+ " of <example.gitlab.com/commits/develop|develop> branch" \
+ " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}"
+ 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
new file mode 100644
index 00000000000..ebe0ead4408
--- /dev/null
+++ b/spec/models/project_services/chat_message/issue_message_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe ChatMessage::IssueMessage, models: true do
+ subject { described_class.new(args) }
+
+ let(:args) do
+ {
+ user: {
+ name: 'Test User',
+ username: 'test.user'
+ },
+ project_name: 'project_name',
+ project_url: 'somewhere.com',
+
+ object_attributes: {
+ title: 'Issue title',
+ id: 10,
+ iid: 100,
+ assignee_id: 1,
+ url: 'url',
+ action: 'open',
+ state: 'opened',
+ description: 'issue description'
+ }
+ }
+ end
+
+ let(:color) { '#C95823' }
+
+ context '#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(
+ '<somewhere.com|[project_name>] Issue opened by test.user')
+ expect(subject.attachments).to eq([
+ {
+ title: "#100 Issue title",
+ title_link: "url",
+ 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(
+ '<somewhere.com|[project_name>] Issue <url|#100 Issue title> closed by test.user')
+ expect(subject.attachments).to be_empty
+ 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
new file mode 100644
index 00000000000..07c414c6ca4
--- /dev/null
+++ b/spec/models/project_services/chat_message/merge_message_spec.rb
@@ -0,0 +1,51 @@
+require 'spec_helper'
+
+describe ChatMessage::MergeMessage, models: true do
+ subject { described_class.new(args) }
+
+ let(:args) do
+ {
+ user: {
+ name: 'Test User',
+ username: 'test.user'
+ },
+ project_name: 'project_name',
+ project_url: 'somewhere.com',
+
+ object_attributes: {
+ title: "Issue title\nSecond line",
+ id: 10,
+ iid: 100,
+ assignee_id: 1,
+ url: 'url',
+ state: 'opened',
+ description: 'issue description',
+ source_branch: 'source_branch',
+ target_branch: 'target_branch',
+ }
+ }
+ end
+
+ let(:color) { '#345' }
+
+ context 'open' do
+ it 'returns a message regarding opening of merge requests' do
+ expect(subject.pretext).to eq(
+ 'test.user opened <somewhere.com/merge_requests/100|merge request !100> '\
+ 'in <somewhere.com|project_name>: *Issue title*')
+ 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 closed <somewhere.com/merge_requests/100|merge request !100> '\
+ 'in <somewhere.com|project_name>: *Issue title*')
+ 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
new file mode 100644
index 00000000000..31936da40a2
--- /dev/null
+++ b/spec/models/project_services/chat_message/note_message_spec.rb
@@ -0,0 +1,130 @@
+require 'spec_helper'
+
+describe ChatMessage::NoteMessage, models: true do
+ let(:color) { '#345' }
+
+ before do
+ @args = {
+ user: {
+ name: 'Test User',
+ username: 'test.user',
+ avatar_url: 'http://fakeavatar'
+ },
+ project_name: 'project_name',
+ project_url: 'somewhere.com',
+ repository: {
+ name: 'project_name',
+ url: 'somewhere.com',
+ },
+ object_attributes: {
+ id: 10,
+ note: 'comment on a commit',
+ url: 'url',
+ 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
+
+ it 'returns a message regarding notes on commits' do
+ message = described_class.new(@args)
+ expect(message.pretext).to eq("test.user <url|commented on " \
+ "commit 5f163b2b> in <somewhere.com|project_name>: " \
+ "*Added a commit message*")
+ expected_attachments = [
+ {
+ text: "comment on a commit",
+ color: color,
+ }
+ ]
+ expect(message.attachments).to eq(expected_attachments)
+ 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
+
+ it 'returns a message regarding notes on a merge request' do
+ message = described_class.new(@args)
+ expect(message.pretext).to eq("test.user <url|commented on " \
+ "merge request !30> in <somewhere.com|project_name>: " \
+ "*merge request title*")
+ expected_attachments = [
+ {
+ text: "comment on a merge request",
+ color: color,
+ }
+ ]
+ expect(message.attachments).to eq(expected_attachments)
+ 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
+
+ it 'returns a message regarding notes on an issue' do
+ message = described_class.new(@args)
+ expect(message.pretext).to eq(
+ "test.user <url|commented on " \
+ "issue #20> in <somewhere.com|project_name>: " \
+ "*issue title*")
+ expected_attachments = [
+ {
+ text: "comment on an issue",
+ color: color,
+ }
+ ]
+ expect(message.attachments).to eq(expected_attachments)
+ 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
+
+ it 'returns a message regarding notes on a project snippet' do
+ message = described_class.new(@args)
+ expect(message.pretext).to eq("test.user <url|commented on " \
+ "snippet #5> in <somewhere.com|project_name>: " \
+ "*snippet title*")
+ expected_attachments = [
+ {
+ text: "comment on a snippet",
+ color: color,
+ }
+ ]
+ expect(message.attachments).to eq(expected_attachments)
+ 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
new file mode 100644
index 00000000000..eca71db07b6
--- /dev/null
+++ b/spec/models/project_services/chat_message/pipeline_message_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe ChatMessage::PipelineMessage do
+ subject { described_class.new(args) }
+ let(:user) { { name: 'hacker' } }
+
+ let(:args) do
+ {
+ object_attributes: {
+ id: 123,
+ sha: '97de212e80737a608d939f648d959671fb0a0142',
+ tag: false,
+ ref: 'develop',
+ status: status,
+ duration: duration
+ },
+ project: { path_with_namespace: 'project_name',
+ web_url: 'example.gitlab.com' },
+ user: user
+ }
+ end
+
+ let(:message) { build_message }
+
+ context 'pipeline succeeded' do
+ let(:status) { 'success' }
+ let(:color) { 'good' }
+ let(:duration) { 10 }
+ let(:message) { build_message('passed') }
+
+ it 'returns a message with information about succeeded build' do
+ verify_message
+ end
+ end
+
+ context 'pipeline failed' do
+ let(:status) { 'failed' }
+ let(:color) { 'danger' }
+ let(:duration) { 10 }
+
+ it 'returns a message with information about failed build' do
+ verify_message
+ end
+
+ context 'when triggered by API therefore lacking user' do
+ let(:user) { nil }
+ let(:message) { build_message(status, 'API') }
+
+ it 'returns a message stating it is by API' do
+ verify_message
+ end
+ end
+ end
+
+ def verify_message
+ expect(subject.pretext).to be_empty
+ expect(subject.fallback).to eq(message)
+ expect(subject.attachments).to eq([text: message, color: color])
+ end
+
+ def build_message(status_text = status, name = user[:name])
+ "<example.gitlab.com|project_name>:" \
+ " Pipeline <example.gitlab.com/pipelines/123|#123>" \
+ " of <example.gitlab.com/commits/develop|develop> branch" \
+ " by #{name} #{status_text} in #{duration} #{'second'.pluralize(duration)}"
+ 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
new file mode 100644
index 00000000000..b781c4505db
--- /dev/null
+++ b/spec/models/project_services/chat_message/push_message_spec.rb
@@ -0,0 +1,88 @@
+require 'spec_helper'
+
+describe ChatMessage::PushMessage, models: true 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',
+ project_url: 'url'
+ }
+ end
+
+ let(:color) { '#345' }
+
+ context 'push' do
+ before do
+ args[:commits] = [
+ { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } },
+ { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } },
+ ]
+ end
+
+ it 'returns a message regarding pushes' do
+ expect(subject.pretext).to eq(
+ 'test.user pushed to branch <url/commits/master|master> of '\
+ '<url|project_name> (<url/compare/before...after|Compare changes>)'
+ )
+ expect(subject.attachments).to eq([
+ {
+ text: "<url1|abcdefgh>: message1 - author1\n"\
+ "<url2|12345678>: message2 - author2",
+ color: color,
+ }
+ ])
+ 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',
+ project_url: 'url'
+ }
+ end
+
+ it 'returns a message regarding pushes' do
+ expect(subject.pretext).to eq('test.user pushed new tag ' \
+ '<url/commits/new_tag|new_tag> to ' \
+ '<url|project_name>')
+ expect(subject.attachments).to be_empty
+ end
+ end
+
+ context 'new branch' do
+ before do
+ args[:before] = Gitlab::Git::BLANK_SHA
+ end
+
+ it 'returns a message regarding a new branch' do
+ expect(subject.pretext).to eq(
+ 'test.user pushed new branch <url/commits/master|master> to '\
+ '<url|project_name>'
+ )
+ expect(subject.attachments).to be_empty
+ end
+ end
+
+ context 'removed branch' do
+ before do
+ args[:after] = Gitlab::Git::BLANK_SHA
+ end
+
+ it 'returns a message regarding a removed branch' do
+ expect(subject.pretext).to eq(
+ 'test.user removed branch master from <url|project_name>'
+ )
+ expect(subject.attachments).to be_empty
+ 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
new file mode 100644
index 00000000000..94c04dc0865
--- /dev/null
+++ b/spec/models/project_services/chat_message/wiki_page_message_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe ChatMessage::WikiPageMessage, models: true do
+ subject { described_class.new(args) }
+
+ let(:args) do
+ {
+ user: {
+ name: 'Test User',
+ username: 'test.user'
+ },
+ project_name: 'project_name',
+ project_url: 'somewhere.com',
+ object_attributes: {
+ title: 'Wiki page title',
+ url: 'url',
+ content: 'Wiki page description'
+ }
+ }
+ end
+
+ describe '#pretext' do
+ context 'when :action == "create"' do
+ before { args[:object_attributes][:action] = 'create' }
+
+ it 'returns a message that a new wiki page was created' do
+ expect(subject.pretext).to eq(
+ 'test.user created <url|wiki page> in <somewhere.com|project_name>: '\
+ '*Wiki page title*')
+ end
+ end
+
+ context 'when :action == "update"' do
+ before { args[:object_attributes][:action] = 'update' }
+
+ it 'returns a message that a wiki page was updated' do
+ expect(subject.pretext).to eq(
+ 'test.user edited <url|wiki page> in <somewhere.com|project_name>: '\
+ '*Wiki page title*')
+ end
+ end
+ end
+
+ describe '#attachments' do
+ let(:color) { '#345' }
+
+ context 'when :action == "create"' do
+ before { args[:object_attributes][:action] = 'create' }
+
+ it 'returns the attachment for a new wiki page' do
+ expect(subject.attachments).to eq([
+ {
+ text: "Wiki page description",
+ color: color,
+ }
+ ])
+ end
+ end
+
+ context 'when :action == "update"' do
+ before { args[:object_attributes][:action] = 'update' }
+
+ it 'returns the attachment for an updated wiki page' do
+ expect(subject.attachments).to eq([
+ {
+ text: "Wiki page description",
+ color: color,
+ }
+ ])
+ end
+ end
+ end
+end