2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-07-29 11:41:55 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-05-10 14:10:41 -04:00
|
|
|
RSpec.describe Integrations::Asana do
|
2014-07-29 11:41:55 -04:00
|
|
|
describe 'Validations' do
|
|
|
|
context 'active' do
|
|
|
|
before do
|
|
|
|
subject.active = true
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of :api_key }
|
2014-07-29 11:41:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Execute' do
|
2022-01-18 16:16:02 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
2019-12-12 13:07:34 -05:00
|
|
|
let(:gid) { "123456789ABCD" }
|
2022-01-18 16:16:02 -05:00
|
|
|
let(:asana_task) { double(::Asana::Resources::Task) }
|
|
|
|
let(:asana_integration) { described_class.new }
|
2014-07-29 11:41:55 -04:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
let(:data) do
|
2016-01-05 10:31:05 -05:00
|
|
|
{
|
2015-12-31 17:27:34 -05:00
|
|
|
object_kind: 'push',
|
|
|
|
ref: 'master',
|
|
|
|
user_name: user.name,
|
2022-01-18 16:16:02 -05:00
|
|
|
commits: [
|
2015-12-31 17:27:34 -05:00
|
|
|
{
|
2022-01-18 16:16:02 -05:00
|
|
|
message: message,
|
2017-05-03 07:22:03 -04:00
|
|
|
url: 'https://gitlab.com/'
|
2015-12-31 17:27:34 -05:00
|
|
|
}
|
2022-01-18 16:16:02 -05:00
|
|
|
]
|
2015-12-31 17:27:34 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-07-29 11:41:55 -04:00
|
|
|
before do
|
2022-01-18 16:16:02 -05:00
|
|
|
allow(asana_integration).to receive_messages(
|
2014-07-29 11:41:55 -04:00
|
|
|
project: project,
|
|
|
|
project_id: project.id,
|
2015-01-16 06:49:50 -05:00
|
|
|
api_key: 'verySecret',
|
|
|
|
restrict_to_branch: 'master'
|
2014-07-29 11:41:55 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
subject(:execute_integration) { asana_integration.execute(data) }
|
|
|
|
|
|
|
|
context 'when creating a story' do
|
|
|
|
let(:message) { "Message from commit. related to ##{gid}" }
|
|
|
|
let(:expected_message) do
|
|
|
|
"#{user.name} pushed to branch master of #{project.full_name} ( https://gitlab.com/ ): #{message}"
|
|
|
|
end
|
2015-12-31 17:27:34 -05:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
it 'calls Asana integration to create a story' do
|
|
|
|
expect(asana_task).to receive(:add_comment).with(text: expected_message)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, gid).once.and_return(asana_task)
|
2014-07-29 11:41:55 -04:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
execute_integration
|
|
|
|
end
|
2014-07-29 11:41:55 -04:00
|
|
|
end
|
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
context 'when creating a story and closing a task' do
|
|
|
|
let(:message) { 'fix #456789' }
|
2014-07-29 11:41:55 -04:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
it 'calls Asana integration to create a story and close a task' do
|
|
|
|
expect(asana_task).to receive(:add_comment)
|
|
|
|
expect(asana_task).to receive(:update).with(completed: true)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(asana_task)
|
|
|
|
|
|
|
|
execute_integration
|
|
|
|
end
|
2014-07-29 11:41:55 -04:00
|
|
|
end
|
2015-12-16 09:08:05 -05:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
context 'when closing via url' do
|
|
|
|
let(:message) { 'closes https://app.asana.com/19292/956299/42' }
|
2015-12-16 09:08:05 -05:00
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
it 'calls Asana integration to close via url' do
|
|
|
|
expect(asana_task).to receive(:add_comment)
|
|
|
|
expect(asana_task).to receive(:update).with(completed: true)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(asana_task)
|
|
|
|
|
|
|
|
execute_integration
|
|
|
|
end
|
2015-12-16 09:08:05 -05:00
|
|
|
end
|
|
|
|
|
2022-01-18 16:16:02 -05:00
|
|
|
context 'with multiple matches per line' do
|
|
|
|
let(:message) do
|
|
|
|
<<-EOF
|
|
|
|
minor bigfix, refactoring, fixed #123 and Closes #456 work on #789
|
|
|
|
ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows multiple matches per line' do
|
|
|
|
expect(asana_task).to receive(:add_comment)
|
|
|
|
expect(asana_task).to receive(:update).with(completed: true)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '123').once.and_return(asana_task)
|
|
|
|
|
|
|
|
asana_task_2 = double(Asana::Resources::Task)
|
|
|
|
expect(asana_task_2).to receive(:add_comment)
|
|
|
|
expect(asana_task_2).to receive(:update).with(completed: true)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '456').once.and_return(asana_task_2)
|
|
|
|
|
|
|
|
asana_task_3 = double(Asana::Resources::Task)
|
|
|
|
expect(asana_task_3).to receive(:add_comment)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '789').once.and_return(asana_task_3)
|
|
|
|
|
|
|
|
asana_task_4 = double(Asana::Resources::Task)
|
|
|
|
expect(asana_task_4).to receive(:add_comment)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(asana_task_4)
|
|
|
|
|
|
|
|
asana_task_5 = double(Asana::Resources::Task)
|
|
|
|
expect(asana_task_5).to receive(:add_comment)
|
|
|
|
expect(asana_task_5).to receive(:update).with(completed: true)
|
|
|
|
expect(::Asana::Resources::Task).to receive(:find_by_id).with(anything, '12').once.and_return(asana_task_5)
|
|
|
|
|
|
|
|
execute_integration
|
|
|
|
end
|
2015-12-16 09:08:05 -05:00
|
|
|
end
|
2014-07-29 11:41:55 -04:00
|
|
|
end
|
|
|
|
end
|