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:
Diffstat (limited to 'spec/models/integrations/asana_spec.rb')
-rw-r--r--spec/models/integrations/asana_spec.rb92
1 files changed, 56 insertions, 36 deletions
diff --git a/spec/models/integrations/asana_spec.rb b/spec/models/integrations/asana_spec.rb
index 376aec1088e..70c56d35a04 100644
--- a/spec/models/integrations/asana_spec.rb
+++ b/spec/models/integrations/asana_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
let_it_be(:project) { build(:project) }
let(:gid) { "123456789ABCD" }
- let(:asana_task) { double(::Asana::Resources::Task) }
+ let(:asana_task) { double(data: { gid: gid }) }
let(:asana_integration) { described_class.new }
let(:ref) { 'main' }
let(:restrict_to_branch) { nil }
@@ -41,6 +41,15 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
}
end
+ let(:completed_message) do
+ {
+ body: {
+ completed: true
+ },
+ headers: { "Authorization" => "Bearer verySecret" }
+ }
+ end
+
before do
allow(asana_integration).to receive_messages(
project: project,
@@ -60,9 +69,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
let(:ref) { 'main' }
it 'calls the Asana integration' 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)
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task)
execute_integration
end
@@ -72,8 +82,8 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
let(:ref) { 'mai' }
it 'does not call the Asana integration' do
- expect(asana_task).not_to receive(:add_comment)
- expect(::Asana::Resources::Task).not_to receive(:find_by_id)
+ expect(Gitlab::HTTP).not_to receive(:post)
+ expect(Gitlab::HTTP).not_to receive(:put)
execute_integration
end
@@ -83,12 +93,17 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
context 'when creating a story' do
let(:message) { "Message from commit. related to ##{gid}" }
let(:expected_message) do
- "#{user.name} pushed to branch main of #{project.full_name} ( https://gitlab.com/ ): #{message}"
+ {
+ body: {
+ text: "#{user.name} pushed to branch main of #{project.full_name} ( https://gitlab.com/ ): #{message}"
+ },
+ headers: { "Authorization" => "Bearer verySecret" }
+ }
end
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)
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/#{gid}/stories", expected_message).once.and_return(asana_task)
execute_integration
end
@@ -98,9 +113,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
let(:message) { 'fix #456789' }
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)
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/456789/stories", anything).once.and_return(asana_task)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/456789", completed_message).once.and_return(asana_task)
execute_integration
end
@@ -110,9 +126,10 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
let(:message) { 'closes https://app.asana.com/19292/956299/42' }
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)
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/42", completed_message).once.and_return(asana_task)
execute_integration
end
@@ -127,27 +144,30 @@ RSpec.describe Integrations::Asana, feature_category: :integrations do
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)
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/123/stories", anything).once.and_return(asana_task)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/123", completed_message).once.and_return(asana_task)
+
+ asana_task_2 = double(double(data: { gid: 456 }))
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/456/stories", anything).once.and_return(asana_task_2)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/456", completed_message).once.and_return(asana_task_2)
+
+ asana_task_3 = double(double(data: { gid: 789 }))
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/789/stories", anything).once.and_return(asana_task_3)
+
+ asana_task_4 = double(double(data: { gid: 42 }))
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/42/stories", anything).once.and_return(asana_task_4)
+
+ asana_task_5 = double(double(data: { gid: 12 }))
+ expect(Gitlab::HTTP).to receive(:post)
+ .with("https://app.asana.com/api/1.0/tasks/12/stories", anything).once.and_return(asana_task_5)
+ expect(Gitlab::HTTP).to receive(:put)
+ .with("https://app.asana.com/api/1.0/tasks/12", completed_message).once.and_return(asana_task_5)
execute_integration
end