Skip to content

Commit

Permalink
DEV: update specs with review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Grubba27 committed Sep 10, 2024
1 parent 3ea5b6c commit 4f681a8
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ def up
VALUES (:automation_id, :name, :component, :metadata, :target, NOW(), NOW())
SQL

providers = %i[
GroupmeProvider
DiscordProvider
GuildedProvider
MattermostProvider
MatrixProvider
TeamsProvider
ZulipProvider
PowerAutomateProvider
RocketchatProvider
GitterProvider
TelegramProvider
FlowdockProvider
GoogleProvider
WebexProvider
SlackProvider
]

DB
.query(rules_with_tag_added)
.each do |row|
Expand All @@ -68,9 +86,7 @@ def up

provider_name = channel[:provider]
provider =
DiscourseChatIntegration::Provider
.constants
.select { |constant| constant.to_s =~ /Provider$/ }
providers
.map { |p| DiscourseChatIntegration::Provider.const_get(p) }
.find { |p| p::PROVIDER_NAME == provider_name }

Expand Down
4 changes: 2 additions & 2 deletions spec/integration/automation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
automation.upsert_field!(
"provider",
"choices",
{ "value" => chan1.provider },
{ "value" => channel1.provider },
target: "script",
)
automation.upsert_field!("channel_name", "text", { "value" => "chan" }, target: "script")
Expand All @@ -56,7 +56,7 @@

expect(validated_provider.sent_messages.length).to eq(1)
expect(validated_provider.sent_messages.first[:post]).to eq(topic.id)
expect(validated_provider.sent_messages.first[:channel]).to eq(chan1)
expect(validated_provider.sent_messages.first[:channel]).to eq(channel1)
end

it "only triggers for the correct tag" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "discord",
data: {
name: "Awesome Channel",
webhook_url: "https://discord.com/api/webhooks/1234/abcd",
},
)
expect(described_class.get_channel_by_name("Awesome Channel")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,19 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "flowdock",
data: {
flow_token: "5d1fe04cf66e078d6a2b579ddb8a465b",
},
)
expect(described_class.get_channel_by_name("5d1fe04cf66e078d6a2b579ddb8a465b")).to eq(
expected,
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "gitter",
data: {
name: "gitterHQ/services",
webhook_url: "https://webhooks.gitter.im/e/a1e2i3o4u5",
},
)
expect(described_class.get_channel_by_name("gitterHQ/services")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "google",
data: {
name: "discourse",
webhook_url: "https://chat.googleapis.com/v1/abcdefg",
},
)
expect(described_class.get_channel_by_name("discourse")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "groupme",
data: {
groupme_instance_name: "my instance",
},
)
expect(described_class.get_channel_by_name("my instance")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "guilded",
data: {
name: "Awesome Channel",
webhook_url: "https://media.guilded.gg/webhooks/1234/abcd",
},
)
expect(described_class.get_channel_by_name("Awesome Channel")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "matrix",
data: {
name: "Awesome Channel",
room_id: "!blah:matrix.org",
},
)
expect(described_class.get_channel_by_name("Awesome Channel")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "mattermost",
data: {
identifier: "#awesomechannel",
},
)
expect(described_class.get_channel_by_name("#awesomechannel")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "powerautomate",
data: {
name: "discourse",
webhook_url:
"https://prod-189.westus.logic.azure.com:443/workflows/c94b462906e64fe8a7299043706be96e/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=-cmkg1oG-88dP3Yqdh62yTG1LUtJFcB91rQisorfw_w",
},
)
expect(described_class.get_channel_by_name("powerautomate")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "rocketchat",
data: {
identifier: "#general",
},
)
expect(described_class.get_channel_by_name("#general")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,17 @@
}.to raise_error(StandardError)
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "slack",
data: {
identifier: "#general",
},
)
expect(described_class.get_channel_by_name("#general")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@
end
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "teams",
data: {
name: "discourse",
webhook_url:
"https://outlook.office.com/webhook/677980e4-e03b-4a5e-ad29-dc1ee0c32a80@9e9b5238-5ab2-496a-8e6a-e9cf05c7eb5c/IncomingWebhook/e7a1006ded44478992769d0c4f391e34/e028ca8a-e9c8-4c6c-a4d8-578f881a3cff",
},
)
expect(described_class.get_channel_by_name("discourse")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "telegram",
data: {
name: "Awesome Channel",
chat_id: "123",
},
)
expect(described_class.get_channel_by_name("Awesome Channel")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
expected =
DiscourseChatIntegration::Channel.create!(
provider: "webex",
data: {
name: "discourse",
webhook_url:
"https://webexapis.com/v1/webhooks/incoming/jAHJjVVQ1cgEwb4ikQQawIrGdUtlocKA9fSNvIyADQoYo0mI70pztWUDOu22gDRPJOEJtCsc688zi1RMa",
},
)
expect(described_class.get_channel_by_name("discourse")).to eq(expected)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,19 @@
expect(stub1).to have_been_requested.once
end
end

describe ".get_channel_by_name" do
it "returns the right channel" do
created =
DiscourseChatIntegration::Channel.create!(
provider: "zulip",
data: {
stream: "foo",
subject: "Discourse Notifications",
},
)
channel = described_class.get_channel_by_name("foo")
expect(channel).to eq(created)
end
end
end

0 comments on commit 4f681a8

Please sign in to comment.