qiita_team_services 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +3 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +26 -0
- data/config/locales/en.yml +31 -0
- data/config/locales/ja.yml +32 -0
- data/lib/qiita/team/services/engine.rb +6 -0
- data/lib/qiita/team/services/errors.rb +7 -0
- data/lib/qiita/team/services/events/base.rb +47 -0
- data/lib/qiita/team/services/events/item_became_coediting.rb +10 -0
- data/lib/qiita/team/services/events/item_comment_created.rb +17 -0
- data/lib/qiita/team/services/events/item_comment_destroyed.rb +17 -0
- data/lib/qiita/team/services/events/item_comment_updated.rb +17 -0
- data/lib/qiita/team/services/events/item_created.rb +10 -0
- data/lib/qiita/team/services/events/item_destroyed.rb +10 -0
- data/lib/qiita/team/services/events/item_updated.rb +10 -0
- data/lib/qiita/team/services/events/project_activated.rb +10 -0
- data/lib/qiita/team/services/events/project_archived.rb +10 -0
- data/lib/qiita/team/services/events/project_comment_created.rb +19 -0
- data/lib/qiita/team/services/events/project_comment_destroyed.rb +19 -0
- data/lib/qiita/team/services/events/project_comment_updated.rb +19 -0
- data/lib/qiita/team/services/events/project_created.rb +10 -0
- data/lib/qiita/team/services/events/project_destroyed.rb +10 -0
- data/lib/qiita/team/services/events/project_updated.rb +10 -0
- data/lib/qiita/team/services/events/team_member_added.rb +12 -0
- data/lib/qiita/team/services/events/team_member_removed.rb +12 -0
- data/lib/qiita/team/services/events.rb +28 -0
- data/lib/qiita/team/services/hooks/base.rb +45 -0
- data/lib/qiita/team/services/hooks/chatwork_v1.rb +149 -0
- data/lib/qiita/team/services/hooks/concerns/event_handlable.rb +49 -0
- data/lib/qiita/team/services/hooks/concerns/http_client.rb +74 -0
- data/lib/qiita/team/services/hooks/concerns/persistable.rb +64 -0
- data/lib/qiita/team/services/hooks/concerns/service.rb +31 -0
- data/lib/qiita/team/services/hooks/concerns/slack.rb +338 -0
- data/lib/qiita/team/services/hooks/hipchat_v1.rb +143 -0
- data/lib/qiita/team/services/hooks/slack_v1.rb +25 -0
- data/lib/qiita/team/services/hooks/slack_v2.rb +19 -0
- data/lib/qiita/team/services/hooks/webhook.rb +193 -0
- data/lib/qiita/team/services/hooks.rb +25 -0
- data/lib/qiita/team/services/properties/base.rb +20 -0
- data/lib/qiita/team/services/properties/boolean_property.rb +12 -0
- data/lib/qiita/team/services/properties/string_property.rb +12 -0
- data/lib/qiita/team/services/properties.rb +21 -0
- data/lib/qiita/team/services/resources/README.md +177 -0
- data/lib/qiita/team/services/templates/chatwork_v1.html.erb +25 -0
- data/lib/qiita/team/services/templates/hipchat_v1.html.erb +58 -0
- data/lib/qiita/team/services/templates/slack_v1.html.erb +54 -0
- data/lib/qiita/team/services/templates/slack_v2.html.erb +44 -0
- data/lib/qiita/team/services/templates/webhook.html.erb +25 -0
- data/lib/qiita/team/services/version.rb +3 -0
- data/lib/qiita_team_services.rb +34 -0
- data/qiita_team_services.gemspec +42 -0
- data/spec/hooks/chatwork_v1_spec.rb +118 -0
- data/spec/hooks/hipchat_v1_spec.rb +139 -0
- data/spec/hooks/slack_v1_spec.rb +55 -0
- data/spec/hooks/slack_v2_spec.rb +50 -0
- data/spec/hooks/webhook_spec.rb +465 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/factories/comments.rb +21 -0
- data/spec/support/factories/items.rb +26 -0
- data/spec/support/factories/projects.rb +17 -0
- data/spec/support/factories/taggings.rb +9 -0
- data/spec/support/factories/teams.rb +9 -0
- data/spec/support/factories/users.rb +11 -0
- data/spec/support/factory_girl.rb +13 -0
- data/spec/support/helpers/event_helper.rb +49 -0
- data/spec/support/helpers/hook_helper.rb +33 -0
- data/spec/support/helpers/http_client_stub_helper.rb +19 -0
- data/spec/support/helpers/slack_hook_helper.rb +104 -0
- data/spec/support/matchers/match_slack_attachments_request.rb +7 -0
- data/spec/support/resources/base.rb +23 -0
- data/spec/support/resources/comment.rb +29 -0
- data/spec/support/resources/item.rb +53 -0
- data/spec/support/resources/project.rb +45 -0
- data/spec/support/resources/tagging.rb +15 -0
- data/spec/support/resources/team.rb +11 -0
- data/spec/support/resources/user.rb +17 -0
- metadata +323 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
<div class="form-group">
|
2
|
+
<%= label :hook, "properties_color", "#{hook.class.human_attribute_name(:color)} *", class: "control-label" %>
|
3
|
+
<%= select_tag "hook[properties][color]", options_for_select(hook.class::AVAILABLE_COLORS.map { |color| [color, color] }), class: "form-control" %>
|
4
|
+
<% if hook.errors.key?(:color) %>
|
5
|
+
<br/>
|
6
|
+
<div class="alert alert-warning">
|
7
|
+
<% hook.errors.full_messages_for(:color).each do |message| %>
|
8
|
+
<p><%= message %></p>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= label :hook, "properties_from", "#{hook.class.human_attribute_name(:from)} *", class: "control-label" %>
|
16
|
+
<%= text_field_tag "hook[properties][from]", hook.from, class: "form-control" %>
|
17
|
+
<% if hook.errors.key?(:from) %>
|
18
|
+
<br/>
|
19
|
+
<div class="alert alert-warning">
|
20
|
+
<% hook.errors.full_messages_for(:from).each do |message| %>
|
21
|
+
<p><%= message %></p>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="form-group">
|
28
|
+
<%= label :hook, "properties_room", "#{hook.class.human_attribute_name(:room)} *", class: "control-label" %>
|
29
|
+
<%= text_field_tag "hook[properties][room]", hook.room, class: "form-control" %>
|
30
|
+
<% if hook.errors.key?(:room) %>
|
31
|
+
<br/>
|
32
|
+
<div class="alert alert-warning">
|
33
|
+
<% hook.errors.full_messages_for(:room).each do |message| %>
|
34
|
+
<p><%= message %></p>
|
35
|
+
<% end %>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div class="form-group">
|
41
|
+
<%= label :hook, "properties_token", "#{hook.class.human_attribute_name(:token)} *", class: "control-label" %>
|
42
|
+
<%= text_field_tag "hook[properties][token]", hook.token, class: "form-control" %>
|
43
|
+
<% if hook.errors.key?(:token) %>
|
44
|
+
<br/>
|
45
|
+
<div class="alert alert-warning">
|
46
|
+
<% hook.errors.full_messages_for(:token).each do |message| %>
|
47
|
+
<p><%= message %></p>
|
48
|
+
<% end %>
|
49
|
+
</div>
|
50
|
+
<% end %>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
<div class="checkbox">
|
54
|
+
<label for="hook_properties_with_notification">
|
55
|
+
<%= check_box_tag "hook[properties][with_notification]" %>
|
56
|
+
<%= hook.class.human_attribute_name(:with_notification) %>
|
57
|
+
</label>
|
58
|
+
</div>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
<div class="form-group">
|
2
|
+
<%= label :hook, "properties_teamname", "#{hook.class.human_attribute_name(:teamname)} *", class: "control-label" %>
|
3
|
+
<%= text_field_tag "hook[properties][teamname]", hook.teamname, class: "form-control" %>
|
4
|
+
<% if hook.errors.key?(:teamname) %>
|
5
|
+
<br/>
|
6
|
+
<div class="alert alert-warning">
|
7
|
+
<% hook.errors.full_messages_for(:teamname).each do |message| %>
|
8
|
+
<p><%= message %></p>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= label :hook, "properties_integration_token", "#{hook.class.human_attribute_name(:integration_token)} *", class: "control-label" %>
|
16
|
+
<%= text_field_tag "hook[properties][integration_token]", hook.integration_token, class: "form-control" %>
|
17
|
+
<% if hook.errors.key?(:integration_token) %>
|
18
|
+
<br/>
|
19
|
+
<div class="alert alert-warning">
|
20
|
+
<% hook.errors.full_messages_for(:integration_token).each do |message| %>
|
21
|
+
<p><%= message %></p>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="form-group">
|
28
|
+
<%= label :hook, "properties_username", "#{hook.class.human_attribute_name(:username)} *", class: "control-label" %>
|
29
|
+
<%= text_field_tag "hook[properties][username]", hook.username, class: "form-control" %>
|
30
|
+
<% if hook.errors.key?(:username) %>
|
31
|
+
<br/>
|
32
|
+
<div class="alert alert-warning">
|
33
|
+
<% hook.errors.full_messages_for(:username).each do |message| %>
|
34
|
+
<p><%= message %></p>
|
35
|
+
<% end %>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div class="form-group">
|
41
|
+
<%= label :hook, "properties_icon_emoji", "#{hook.class.human_attribute_name(:icon_emoji)}", class: "control-label" %>
|
42
|
+
<%= text_field_tag "hook[properties][icon_emoji]", hook.icon_emoji, class: "form-control" %>
|
43
|
+
<% if hook.errors.key?(:icon_emoji) %>
|
44
|
+
<br/>
|
45
|
+
<div class="alert alert-warning">
|
46
|
+
<% hook.errors.full_messages_for(:icon_emoji).each do |message| %>
|
47
|
+
<p><%= message %></p>
|
48
|
+
<% end %>
|
49
|
+
</div>
|
50
|
+
<% end %>
|
51
|
+
<div class="help-block">
|
52
|
+
<%= I18n.t("qiita.team.services.templates.slack_v2.icon_emoji_help_block_html") %>
|
53
|
+
</div>
|
54
|
+
</div>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<div class="form-group">
|
2
|
+
<%= label :hook, "properties_webhook_url", "#{hook.class.human_attribute_name(:webhook_url)} *", class: "control-label" %>
|
3
|
+
<%= text_field_tag "hook[properties][webhook_url]", hook.webhook_url, class: "form-control" %>
|
4
|
+
<% if hook.errors.key?(:webhook_url) %>
|
5
|
+
<br/>
|
6
|
+
<div class="alert alert-warning">
|
7
|
+
<% hook.errors.full_messages_for(:webhook_url).each do |message| %>
|
8
|
+
<p><%= message %></p>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
<div class="help-block">
|
13
|
+
<%= I18n.t("qiita.team.services.templates.slack_v2.webhook_url_help_block_html") %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="form-group">
|
18
|
+
<%= label :hook, "properties_username", "#{hook.class.human_attribute_name(:username)} *", class: "control-label" %>
|
19
|
+
<%= text_field_tag "hook[properties][username]", hook.username, class: "form-control" %>
|
20
|
+
<% if hook.errors.key?(:username) %>
|
21
|
+
<br/>
|
22
|
+
<div class="alert alert-warning">
|
23
|
+
<% hook.errors.full_messages_for(:username).each do |message| %>
|
24
|
+
<p><%= message %></p>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="form-group">
|
31
|
+
<%= label :hook, "properties_icon_emoji", "#{hook.class.human_attribute_name(:icon_emoji)}", class: "control-label" %>
|
32
|
+
<%= text_field_tag "hook[properties][icon_emoji]", hook.icon_emoji, class: "form-control" %>
|
33
|
+
<% if hook.errors.key?(:icon_emoji) %>
|
34
|
+
<br/>
|
35
|
+
<div class="alert alert-warning">
|
36
|
+
<% hook.errors.full_messages_for(:icon_emoji).each do |message| %>
|
37
|
+
<p><%= message %></p>
|
38
|
+
<% end %>
|
39
|
+
</div>
|
40
|
+
<% end %>
|
41
|
+
<div class="help-block">
|
42
|
+
<%= I18n.t("qiita.team.services.templates.slack_v2.icon_emoji_help_block_html") %>
|
43
|
+
</div>
|
44
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<div class="form-group">
|
2
|
+
<%= label :hook, "properties_url", "#{hook.class.human_attribute_name(:url)} *", class: "control-label" %>
|
3
|
+
<%= text_field_tag "hook[properties][url]", hook.token, class: "form-control" %>
|
4
|
+
<% if hook.errors.key?(:url) %>
|
5
|
+
<br/>
|
6
|
+
<div class="alert alert-warning">
|
7
|
+
<% hook.errors.full_messages_for(:url).each do |message| %>
|
8
|
+
<p><%= message %></p>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= label :hook, "properties_token", "#{hook.class.human_attribute_name(:token)} *", class: "control-label" %>
|
16
|
+
<%= text_field_tag "hook[properties][token]", hook.token, class: "form-control", readonly: true %>
|
17
|
+
<% if hook.errors.key?(:token) %>
|
18
|
+
<br/>
|
19
|
+
<div class="alert alert-warning">
|
20
|
+
<% hook.errors.full_messages_for(:token).each do |message| %>
|
21
|
+
<p><%= message %></p>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Qiita
|
2
|
+
module Team
|
3
|
+
module Services
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require "qiita/team/services/engine"
|
9
|
+
require "qiita/team/services/errors"
|
10
|
+
require "qiita/team/services/events/item_became_coediting"
|
11
|
+
require "qiita/team/services/events/item_comment_created"
|
12
|
+
require "qiita/team/services/events/item_comment_destroyed"
|
13
|
+
require "qiita/team/services/events/item_comment_updated"
|
14
|
+
require "qiita/team/services/events/item_created"
|
15
|
+
require "qiita/team/services/events/item_destroyed"
|
16
|
+
require "qiita/team/services/events/item_updated"
|
17
|
+
require "qiita/team/services/events/project_activated"
|
18
|
+
require "qiita/team/services/events/project_archived"
|
19
|
+
require "qiita/team/services/events/project_comment_created"
|
20
|
+
require "qiita/team/services/events/project_comment_destroyed"
|
21
|
+
require "qiita/team/services/events/project_comment_updated"
|
22
|
+
require "qiita/team/services/events/project_created"
|
23
|
+
require "qiita/team/services/events/project_destroyed"
|
24
|
+
require "qiita/team/services/events/project_updated"
|
25
|
+
require "qiita/team/services/events/team_member_added"
|
26
|
+
require "qiita/team/services/events/team_member_removed"
|
27
|
+
require "qiita/team/services/properties/boolean_property"
|
28
|
+
require "qiita/team/services/properties/string_property"
|
29
|
+
require "qiita/team/services/hooks/chatwork_v1"
|
30
|
+
require "qiita/team/services/hooks/hipchat_v1"
|
31
|
+
require "qiita/team/services/hooks/slack_v1"
|
32
|
+
require "qiita/team/services/hooks/slack_v2"
|
33
|
+
require "qiita/team/services/hooks/webhook"
|
34
|
+
require "qiita/team/services/version"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
module ::Qiita
|
5
|
+
module Team
|
6
|
+
module Services
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require "qiita/team/services/version"
|
12
|
+
|
13
|
+
Gem::Specification.new do |spec|
|
14
|
+
spec.name = "qiita_team_services"
|
15
|
+
spec.version = Qiita::Team::Services::VERSION
|
16
|
+
spec.authors = ["Yuku Takahashi"]
|
17
|
+
spec.email = ["yuku@qiita.com"]
|
18
|
+
spec.summary = "Official Qiita:Team Services Integration"
|
19
|
+
spec.homepage = "https://github.com/increments/qiita-team-services"
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0")
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "faraday", "~> 0.9"
|
26
|
+
spec.add_dependency "faraday_middleware", "~> 0.10"
|
27
|
+
spec.add_dependency "rails", "~> 4.2"
|
28
|
+
spec.add_dependency "rails-i18n"
|
29
|
+
|
30
|
+
# Service dependencies
|
31
|
+
spec.add_dependency "hipchat", "~> 1.5.2"
|
32
|
+
spec.add_dependency "slacken", "~> 0.1.3"
|
33
|
+
|
34
|
+
spec.add_development_dependency "factory_girl", "~> 4.5.0"
|
35
|
+
spec.add_development_dependency "ffaker", "~> 2.1"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
39
|
+
spec.add_development_dependency "rubocop", "~> 0.33"
|
40
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
41
|
+
spec.add_development_dependency "yard", "~> 0.8.7"
|
42
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
describe Qiita::Team::Services::Hooks::ChatworkV1 do
|
2
|
+
include Qiita::Team::Services::Helpers::EventHelper
|
3
|
+
include Qiita::Team::Services::Helpers::HttpClientStubHelper
|
4
|
+
include Qiita::Team::Services::Helpers::HookHelper
|
5
|
+
|
6
|
+
EXPECTED_AVAILABLE_EVENT_NAMES = [
|
7
|
+
:item_became_coediting,
|
8
|
+
:item_comment_created,
|
9
|
+
:item_created,
|
10
|
+
:item_updated,
|
11
|
+
:project_activated,
|
12
|
+
:project_archived,
|
13
|
+
:project_comment_created,
|
14
|
+
:project_created,
|
15
|
+
:project_updated,
|
16
|
+
:team_member_added,
|
17
|
+
]
|
18
|
+
|
19
|
+
shared_context "Delivery success" do
|
20
|
+
before do
|
21
|
+
stubs = get_http_client_stub(hook)
|
22
|
+
stubs.post("/v1/rooms/#{room_id}/messages") do |_env|
|
23
|
+
[200, { "Content-Type" => "application/json" }, { message_id: 1 }]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
shared_context "Delivery fail" do
|
29
|
+
before do
|
30
|
+
stubs = get_http_client_stub(hook)
|
31
|
+
stubs.post("/v1/rooms/#{room_id}/messages") do |_env|
|
32
|
+
[400, {}, ""]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:hook) do
|
38
|
+
described_class.new(properties)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:properties) do
|
42
|
+
{ "room_id" => room_id, "token" => token }
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:room_id) do
|
46
|
+
1
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:token) do
|
50
|
+
"abc"
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like "hook"
|
54
|
+
|
55
|
+
describe ".service_name" do
|
56
|
+
subject do
|
57
|
+
described_class.service_name
|
58
|
+
end
|
59
|
+
|
60
|
+
it { should eq "ChatWork" }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".available_event_names" do
|
64
|
+
subject do
|
65
|
+
described_class.available_event_names
|
66
|
+
end
|
67
|
+
|
68
|
+
it { should match_array EXPECTED_AVAILABLE_EVENT_NAMES }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#ping" do
|
72
|
+
subject do
|
73
|
+
hook.ping
|
74
|
+
end
|
75
|
+
|
76
|
+
it "sends a text message" do
|
77
|
+
expect(hook).to receive(:send_message).with(a_kind_of(String))
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when message is delivered successful" do
|
82
|
+
include_context "Delivery success"
|
83
|
+
|
84
|
+
it { expect { subject }.not_to raise_error }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when message is not delivered" do
|
88
|
+
include_context "Delivery fail"
|
89
|
+
|
90
|
+
it { expect { subject }.not_to raise_error }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
EXPECTED_AVAILABLE_EVENT_NAMES.each do |event_name|
|
95
|
+
describe "##{event_name}" do
|
96
|
+
subject do
|
97
|
+
hook.public_send(event_name, public_send("#{event_name}_event"))
|
98
|
+
end
|
99
|
+
|
100
|
+
it "sends a text message" do
|
101
|
+
expect(hook).to receive(:send_message).with(a_kind_of(String))
|
102
|
+
subject
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when message is delivered successfully" do
|
106
|
+
include_context "Delivery success"
|
107
|
+
|
108
|
+
it { expect { subject }.not_to raise_error }
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when message is not delivered successfully" do
|
112
|
+
include_context "Delivery fail"
|
113
|
+
|
114
|
+
it { expect { subject }.to raise_error(Qiita::Team::Services::DeliveryError) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
describe Qiita::Team::Services::Hooks::HipchatV1 do
|
2
|
+
include Qiita::Team::Services::Helpers::EventHelper
|
3
|
+
include Qiita::Team::Services::Helpers::HookHelper
|
4
|
+
|
5
|
+
EXPECTED_AVAILABLE_EVENT_NAMES = [
|
6
|
+
:item_became_coediting,
|
7
|
+
:item_comment_created,
|
8
|
+
:item_created,
|
9
|
+
:item_updated,
|
10
|
+
:project_activated,
|
11
|
+
:project_archived,
|
12
|
+
:project_comment_created,
|
13
|
+
:project_created,
|
14
|
+
:project_updated,
|
15
|
+
:team_member_added,
|
16
|
+
]
|
17
|
+
|
18
|
+
shared_context "Delivery success" do
|
19
|
+
before do
|
20
|
+
allow_any_instance_of(HipChat::Room).to receive(:send).and_return(true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
shared_context "Delivery fail" do
|
25
|
+
before do
|
26
|
+
allow_any_instance_of(HipChat::Room).to receive(:send).and_raise(HipChat::UnknownRoom)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:hook) do
|
31
|
+
described_class.new(properties)
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:properties) do
|
35
|
+
{
|
36
|
+
"color" => color,
|
37
|
+
"from" => from,
|
38
|
+
"room" => room,
|
39
|
+
"token" => token,
|
40
|
+
"with_notification" => with_notification,
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:color) do
|
45
|
+
"yellow"
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:from) do
|
49
|
+
"Qiita:Team"
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:room) do
|
53
|
+
"development"
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:token) do
|
57
|
+
"secrethipchattoken"
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:with_notification) do
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
it_behaves_like "hook"
|
65
|
+
|
66
|
+
describe ".service_name" do
|
67
|
+
subject do
|
68
|
+
described_class.service_name
|
69
|
+
end
|
70
|
+
|
71
|
+
it { should eq "HipChat" }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe ".available_event_names" do
|
75
|
+
subject do
|
76
|
+
described_class.available_event_names
|
77
|
+
end
|
78
|
+
|
79
|
+
it { should match_array EXPECTED_AVAILABLE_EVENT_NAMES }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#ping" do
|
83
|
+
subject do
|
84
|
+
hook.ping
|
85
|
+
end
|
86
|
+
|
87
|
+
it "sends a text message" do
|
88
|
+
expect_any_instance_of(HipChat::Room).to receive(:send).with(
|
89
|
+
from,
|
90
|
+
a_kind_of(String),
|
91
|
+
color: color,
|
92
|
+
notify: with_notification,
|
93
|
+
).once
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when message is delivered successful" do
|
98
|
+
include_context "Delivery success"
|
99
|
+
|
100
|
+
it { expect { subject }.not_to raise_error }
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when message is not delivered" do
|
104
|
+
include_context "Delivery fail"
|
105
|
+
|
106
|
+
it { expect { subject }.not_to raise_error }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
EXPECTED_AVAILABLE_EVENT_NAMES.each do |event_name|
|
111
|
+
describe "##{event_name}" do
|
112
|
+
subject do
|
113
|
+
hook.public_send(event_name, public_send("#{event_name}_event"))
|
114
|
+
end
|
115
|
+
|
116
|
+
it "sends a text message with HipChat client" do
|
117
|
+
expect_any_instance_of(HipChat::Room).to receive(:send).with(
|
118
|
+
from,
|
119
|
+
a_kind_of(String),
|
120
|
+
color: color,
|
121
|
+
notify: with_notification,
|
122
|
+
).once
|
123
|
+
subject
|
124
|
+
end
|
125
|
+
|
126
|
+
context "when message is delivered successfully" do
|
127
|
+
include_context "Delivery success"
|
128
|
+
|
129
|
+
it { expect { subject }.not_to raise_error }
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when message is not delivered successfully" do
|
133
|
+
include_context "Delivery fail"
|
134
|
+
|
135
|
+
it { expect { subject }.to raise_error(Qiita::Team::Services::DeliveryError) }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
describe Qiita::Team::Services::Hooks::SlackV1 do
|
2
|
+
include Qiita::Team::Services::Helpers::HttpClientStubHelper
|
3
|
+
include Qiita::Team::Services::Helpers::HookHelper
|
4
|
+
include Qiita::Team::Services::Helpers::SlackHookHelper
|
5
|
+
|
6
|
+
shared_context "Delivery success" do
|
7
|
+
before do
|
8
|
+
stubs = get_http_client_stub(hook)
|
9
|
+
stubs.post("/services/hooks/incoming-webhook?token=#{integration_token}") do |_env|
|
10
|
+
[200, { "Content-Type" => "application/json" }, { message_id: 1 }]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_context "Delivery fail" do
|
16
|
+
before do
|
17
|
+
stubs = get_http_client_stub(hook)
|
18
|
+
stubs.post("/services/hooks/incoming-webhook?token=#{integration_token}") do |_env|
|
19
|
+
[400, {}, ""]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:hook) do
|
25
|
+
described_class.new(properties)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:properties) do
|
29
|
+
{
|
30
|
+
"teamname" => teamname,
|
31
|
+
"integration_token" => integration_token,
|
32
|
+
"username" => username,
|
33
|
+
"icon_emoji" => icon_emoji,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:teamname) do
|
38
|
+
"increments"
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:integration_token) do
|
42
|
+
"integrationtoken"
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:username) do
|
46
|
+
"qiitan"
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:icon_emoji) do
|
50
|
+
":qiitan:"
|
51
|
+
end
|
52
|
+
|
53
|
+
it_behaves_like "hook"
|
54
|
+
it_behaves_like "Slack hook"
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
describe Qiita::Team::Services::Hooks::SlackV2 do
|
2
|
+
include Qiita::Team::Services::Helpers::HttpClientStubHelper
|
3
|
+
include Qiita::Team::Services::Helpers::HookHelper
|
4
|
+
include Qiita::Team::Services::Helpers::SlackHookHelper
|
5
|
+
|
6
|
+
shared_context "Delivery success" do
|
7
|
+
before do
|
8
|
+
stubs = get_http_client_stub(hook)
|
9
|
+
stubs.post(webhook_url) do |_env|
|
10
|
+
[200, { "Content-Type" => "application/json" }, { message_id: 1 }]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_context "Delivery fail" do
|
16
|
+
before do
|
17
|
+
stubs = get_http_client_stub(hook)
|
18
|
+
stubs.post(webhook_url) do |_env|
|
19
|
+
[400, {}, ""]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:hook) do
|
25
|
+
described_class.new(properties)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:properties) do
|
29
|
+
{
|
30
|
+
"webhook_url" => webhook_url,
|
31
|
+
"username" => username,
|
32
|
+
"icon_emoji" => icon_emoji,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:webhook_url) do
|
37
|
+
"https://example.com"
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:username) do
|
41
|
+
"qiitan"
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:icon_emoji) do
|
45
|
+
":qiitan:"
|
46
|
+
end
|
47
|
+
|
48
|
+
it_behaves_like "hook"
|
49
|
+
it_behaves_like "Slack hook"
|
50
|
+
end
|