mirror of
https://github.com/discourse/discourse.git
synced 2025-03-30 06:35:55 +08:00
DEV: Fix undefined variable (#29876)
Follow up to commit 429cf656e78ae1858c29a446cccd386542ae2867.
This commit is contained in:
parent
02ad1f9cd5
commit
250a145361
@ -31,7 +31,7 @@ module Jobs
|
|||||||
uri = URI.parse(push_url)
|
uri = URI.parse(push_url)
|
||||||
|
|
||||||
http = FinalDestination::HTTP.new(uri.host, uri.port)
|
http = FinalDestination::HTTP.new(uri.host, uri.port)
|
||||||
http.use_ssl = true
|
http.use_ssl = uri.scheme == "https"
|
||||||
|
|
||||||
request =
|
request =
|
||||||
FinalDestination::HTTP::Post.new(
|
FinalDestination::HTTP::Post.new(
|
||||||
@ -45,7 +45,7 @@ module Jobs
|
|||||||
|
|
||||||
if response.code.to_i != 200
|
if response.code.to_i != 200
|
||||||
Rails.logger.warn(
|
Rails.logger.warn(
|
||||||
"Failed to push a notification to #{push_url} Status: #{result.status}: #{result.status_line}",
|
"Failed to push a notification to #{push_url} Status: #{response.code}: #{response.body}",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
|
@ -4,6 +4,7 @@ require "excon"
|
|||||||
|
|
||||||
RSpec.describe Jobs::PushNotification do
|
RSpec.describe Jobs::PushNotification do
|
||||||
fab!(:user)
|
fab!(:user)
|
||||||
|
fab!(:user2) { Fabricate(:user) }
|
||||||
fab!(:post)
|
fab!(:post)
|
||||||
let(:data) do
|
let(:data) do
|
||||||
{
|
{
|
||||||
@ -16,20 +17,31 @@ RSpec.describe Jobs::PushNotification do
|
|||||||
"clients" => [[user.id, "http://test.localhost"]],
|
"clients" => [[user.id, "http://test.localhost"]],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
let(:data_with_two_clients) do
|
||||||
|
{
|
||||||
|
"user_id" => user.id,
|
||||||
|
"payload" => {
|
||||||
|
"notification_type" => 1,
|
||||||
|
"post_url" => "/t/#{post.topic_id}/#{post.post_number}",
|
||||||
|
"excerpt" => "Hello you",
|
||||||
|
},
|
||||||
|
"clients" => [[user2.id, "https://test2.localhost"], [user.id, "http://test.localhost"]],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
let!(:request) do
|
let!(:request) do
|
||||||
stub_request(:post, "https://test.localhost:80/").with(
|
stub_request(:post, "http://test.localhost").with(
|
||||||
body: {
|
body: {
|
||||||
"secret_key" => SiteSetting.push_api_secret_key,
|
secret_key: SiteSetting.push_api_secret_key,
|
||||||
"url" => "http://test.localhost",
|
url: "http://test.localhost",
|
||||||
"title" => "Discourse",
|
title: "Discourse",
|
||||||
"description" => "",
|
description: "",
|
||||||
"notifications" => [
|
notifications: [
|
||||||
{
|
{
|
||||||
"notification_type" => 1,
|
notification_type: 1,
|
||||||
"excerpt" => "Hello you",
|
excerpt: "Hello you",
|
||||||
"url" => "http://test.localhost/t/#{post.topic_id}/#{post.post_number}",
|
url: "http://test.localhost/t/#{post.topic_id}/#{post.post_number}",
|
||||||
"client_id" => user.id,
|
client_id: user.id,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}.to_json,
|
}.to_json,
|
||||||
@ -39,6 +51,28 @@ RSpec.describe Jobs::PushNotification do
|
|||||||
).to_return(status: 200, body: "", headers: {})
|
).to_return(status: 200, body: "", headers: {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let!(:bad_request) do
|
||||||
|
stub_request(:post, "https://test2.localhost/").with(
|
||||||
|
body: {
|
||||||
|
secret_key: SiteSetting.push_api_secret_key,
|
||||||
|
url: "http://test.localhost",
|
||||||
|
title: "Discourse",
|
||||||
|
description: "",
|
||||||
|
notifications: [
|
||||||
|
{
|
||||||
|
notification_type: 1,
|
||||||
|
excerpt: "Hello you",
|
||||||
|
url: "http://test.localhost/t/#{post.topic_id}/#{post.post_number}",
|
||||||
|
client_id: user2.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}.to_json,
|
||||||
|
headers: {
|
||||||
|
"Content-Type" => "application/json",
|
||||||
|
},
|
||||||
|
).to_return(status: 404, body: "", headers: {})
|
||||||
|
end
|
||||||
|
|
||||||
before { SiteSetting.push_notification_time_window_mins = 5 }
|
before { SiteSetting.push_notification_time_window_mins = 5 }
|
||||||
|
|
||||||
context "with valid user" do
|
context "with valid user" do
|
||||||
@ -68,4 +102,16 @@ RSpec.describe Jobs::PushNotification do
|
|||||||
expect(request).not_to have_been_requested
|
expect(request).not_to have_been_requested
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with two clients" do
|
||||||
|
it "sends push notifications to both clients" do
|
||||||
|
user.update!(last_seen_at: 10.minutes.ago)
|
||||||
|
user2.update!(last_seen_at: 10.minutes.ago)
|
||||||
|
|
||||||
|
Jobs::PushNotification.new.execute(data_with_two_clients)
|
||||||
|
|
||||||
|
expect(request).to have_been_requested
|
||||||
|
expect(bad_request).to have_been_requested
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user