mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: post notifications in JSON so we properly support arrays and so on
This commit is contained in:
parent
76857e3f77
commit
340874d345
2 changed files with 41 additions and 33 deletions
|
@ -20,7 +20,8 @@ module Jobs
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
RestClient.send :post, push_url, payload.merge({notifications: notifications})
|
RestClient.send :post, push_url, payload.merge({notifications: notifications}).to_json, content_type: :json, accept: :json
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -344,43 +344,50 @@ describe PostAlerter do
|
||||||
push_url: "https://site2.com/push")
|
push_url: "https://site2.com/push")
|
||||||
end
|
end
|
||||||
|
|
||||||
# I want to test payload ... but we have chicked egg problem
|
|
||||||
# if I test it then it makes the req and the the expects is not correct ...
|
|
||||||
# need to track all reqs in rest client and check after the fact
|
|
||||||
|
|
||||||
# payload = {
|
|
||||||
# secret_key: SiteSetting.push_api_secret_key,
|
body = nil
|
||||||
# url: Discourse.base_url,
|
headers = nil
|
||||||
# title: SiteSetting.title,
|
|
||||||
# description: SiteSetting.site_description,
|
|
||||||
# notifications: [
|
|
||||||
# {
|
|
||||||
# 'notification_type' => 1,
|
|
||||||
# 'post_number' => 1,
|
|
||||||
# 'topic_title' => topic.title,
|
|
||||||
# 'topic_id' => topic.id,
|
|
||||||
# 'excerpt' => 'Hello @eviltrout',
|
|
||||||
# 'username' => user.username,
|
|
||||||
# 'url' => UrlHelper.absolute(mention_post.url),
|
|
||||||
# 'client_id' => 'xxx0'
|
|
||||||
# },
|
|
||||||
# {
|
|
||||||
# 'notification_type' => 1,
|
|
||||||
# 'post_number' => 1,
|
|
||||||
# 'topic_title' => topic.title,
|
|
||||||
# 'topic_id' => topic.id,
|
|
||||||
# 'excerpt' => 'Hello @eviltrout',
|
|
||||||
# 'username' => user.username,
|
|
||||||
# 'url' => UrlHelper.absolute(mention_post.url),
|
|
||||||
# 'client_id' => 'xxx1'
|
|
||||||
# }
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
|
|
||||||
# should only happen once even though we are using 2 keys
|
# should only happen once even though we are using 2 keys
|
||||||
RestClient.expects(:post).returns("OK")
|
RestClient.expects(:post).with{|_req,_body,_headers|
|
||||||
|
headers = _headers
|
||||||
|
body = _body
|
||||||
|
}.returns("OK")
|
||||||
|
|
||||||
mention_post
|
mention_post
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"secret_key" => SiteSetting.push_api_secret_key,
|
||||||
|
"url" => Discourse.base_url,
|
||||||
|
"title" => SiteSetting.title,
|
||||||
|
"description" => SiteSetting.site_description,
|
||||||
|
"notifications" => [
|
||||||
|
{
|
||||||
|
'notification_type' => 1,
|
||||||
|
'post_number' => 1,
|
||||||
|
'topic_title' => topic.title,
|
||||||
|
'topic_id' => topic.id,
|
||||||
|
'excerpt' => 'Hello @eviltrout',
|
||||||
|
'username' => user.username,
|
||||||
|
'url' => UrlHelper.absolute(mention_post.url),
|
||||||
|
'client_id' => 'xxx0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'notification_type' => 1,
|
||||||
|
'post_number' => 1,
|
||||||
|
'topic_title' => topic.title,
|
||||||
|
'topic_id' => topic.id,
|
||||||
|
'excerpt' => 'Hello @eviltrout',
|
||||||
|
'username' => user.username,
|
||||||
|
'url' => UrlHelper.absolute(mention_post.url),
|
||||||
|
'client_id' => 'xxx1'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(JSON.parse(body)).to eq(payload)
|
||||||
|
expect(headers[:content_type]).to eq(:json)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue