Skip to content

Commit f22ffdd

Browse files
committed
add tests for external service arrays; ping @maelle
1 parent e549fb9 commit f22ffdd

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

spec/responders/welcome_responder_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,38 @@
237237
end
238238
end
239239

240+
describe "#process_message with external service array" do
241+
before do
242+
settings = { env: {bot_github_user: "botsci"} }
243+
services = [
244+
{ name: "service1", url: "http://example1.com", data_from_issue: ["extra-data"] },
245+
{ name: "service2", url: "http://example2.com" }
246+
]
247+
@responder = subject.new(settings, {external_service: services})
248+
@responder.context = OpenStruct.new(issue_id: 33,
249+
issue_author: "opener",
250+
issue_title: "Test paper",
251+
repo: "openjournals/testing",
252+
sender: "xuanxu",
253+
issue_body: "Test Review\n\n<!--extra-data-->ABC123<!--end-extra-data-->")
254+
disable_github_calls_for(@responder)
255+
end
256+
257+
it "should add multiple ExternalServiceWorkers for array of services" do
258+
expect { @responder.process_message("") }.to change(ExternalServiceWorker.jobs, :size).by(2)
259+
end
260+
261+
it "should pass right info to workers for each service in array" do
262+
expected_locals_1 = { "extra-data" => "ABC123", "bot_name" => "botsci", "issue_author" => "opener", "issue_title" => "Test paper", "issue_id" => 33, "repo" => "openjournals/testing", "sender" => "xuanxu" }
263+
expected_locals_2 = { "bot_name" => "botsci", "issue_author" => "opener", "issue_title" => "Test paper", "issue_id" => 33, "repo" => "openjournals/testing", "sender" => "xuanxu" }
264+
265+
expect(ExternalServiceWorker).to receive(:perform_async).with({ "name" => "service1", "url" => "http://example1.com", "data_from_issue" => ["extra-data"] }, expected_locals_1)
266+
expect(ExternalServiceWorker).to receive(:perform_async).with({ "name" => "service2", "url" => "http://example2.com" }, expected_locals_2)
267+
268+
@responder.process_message("")
269+
end
270+
end
271+
240272
describe "misconfiguration" do
241273
it "should raise error if there is no name for the service" do
242274
@responder = subject.new({env: {bot_github_user: "botsci"}}, {external_service: { url: "URL" }})

0 commit comments

Comments
 (0)