summaryrefslogtreecommitdiff
path: root/spec/models/project_services/chat_message/build_message_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_services/chat_message/build_message_spec.rb')
-rw-r--r--spec/models/project_services/chat_message/build_message_spec.rb57
1 files changed, 57 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