2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-14 12:57:26 -05:00
|
|
|
require_dependency 'discourse_hub'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-02-14 12:57:26 -05:00
|
|
|
describe DiscourseHub do
|
2017-03-27 08:47:07 -04:00
|
|
|
describe '.discourse_version_check' do
|
2013-02-19 15:16:50 -05:00
|
|
|
it 'should return just return the json that the hub returns' do
|
2017-07-27 21:20:09 -04:00
|
|
|
hub_response = { 'success' => 'OK', 'latest_version' => '0.8.1', 'critical_updates' => false }
|
2017-06-15 20:08:15 -04:00
|
|
|
|
2017-06-16 15:31:13 -04:00
|
|
|
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api") + "/version_check").
|
2017-06-18 15:40:28 -04:00
|
|
|
with(query: DiscourseHub.version_check_payload).
|
2017-06-15 20:08:15 -04:00
|
|
|
to_return(status: 200, body: hub_response.to_json)
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(DiscourseHub.discourse_version_check).to eq(hub_response)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-27 08:47:07 -04:00
|
|
|
|
|
|
|
describe '.version_check_payload' do
|
|
|
|
|
|
|
|
describe 'when Discourse Hub has not fetched stats since past 7 days' do
|
|
|
|
it 'should include stats' do
|
|
|
|
DiscourseHub.stats_fetched_at = 8.days.ago
|
|
|
|
json = JSON.parse(DiscourseHub.version_check_payload.to_json)
|
|
|
|
|
|
|
|
expect(json["topic_count"]).to be_present
|
|
|
|
expect(json["post_count"]).to be_present
|
|
|
|
expect(json["user_count"]).to be_present
|
|
|
|
expect(json["topics_7_days"]).to be_present
|
|
|
|
expect(json["topics_30_days"]).to be_present
|
|
|
|
expect(json["posts_7_days"]).to be_present
|
|
|
|
expect(json["posts_30_days"]).to be_present
|
|
|
|
expect(json["users_7_days"]).to be_present
|
|
|
|
expect(json["users_30_days"]).to be_present
|
|
|
|
expect(json["active_users_7_days"]).to be_present
|
|
|
|
expect(json["active_users_30_days"]).to be_present
|
|
|
|
expect(json["like_count"]).to be_present
|
|
|
|
expect(json["likes_7_days"]).to be_present
|
|
|
|
expect(json["likes_30_days"]).to be_present
|
|
|
|
expect(json["installed_version"]).to be_present
|
|
|
|
expect(json["branch"]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when Discourse Hub has fetched stats in past 7 days' do
|
|
|
|
it 'should not include stats' do
|
|
|
|
DiscourseHub.stats_fetched_at = 2.days.ago
|
|
|
|
json = JSON.parse(DiscourseHub.version_check_payload.to_json)
|
|
|
|
|
|
|
|
expect(json["topic_count"]).not_to be_present
|
|
|
|
expect(json["post_count"]).not_to be_present
|
|
|
|
expect(json["user_count"]).not_to be_present
|
|
|
|
expect(json["like_count"]).not_to be_present
|
|
|
|
expect(json["likes_7_days"]).not_to be_present
|
|
|
|
expect(json["likes_30_days"]).not_to be_present
|
|
|
|
expect(json["installed_version"]).to be_present
|
|
|
|
expect(json["branch"]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when send_anonymize_stats is disabled' do
|
|
|
|
describe 'when Discourse Hub has not fetched stats for the past year' do
|
|
|
|
it 'should not include stats' do
|
|
|
|
DiscourseHub.stats_fetched_at = 1.year.ago
|
|
|
|
SiteSetting.share_anonymized_statistics = false
|
|
|
|
json = JSON.parse(DiscourseHub.version_check_payload.to_json)
|
|
|
|
|
|
|
|
expect(json["topic_count"]).not_to be_present
|
|
|
|
expect(json["post_count"]).not_to be_present
|
|
|
|
expect(json["user_count"]).not_to be_present
|
|
|
|
expect(json["like_count"]).not_to be_present
|
|
|
|
expect(json["likes_7_days"]).not_to be_present
|
|
|
|
expect(json["likes_30_days"]).not_to be_present
|
|
|
|
expect(json["installed_version"]).to be_present
|
|
|
|
expect(json["branch"]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-09 10:05:31 -04:00
|
|
|
|
|
|
|
describe '.collection_action' do
|
2018-10-09 21:34:50 -04:00
|
|
|
before do
|
|
|
|
@orig_logger = Rails.logger
|
|
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
|
|
end
|
2018-10-09 10:05:31 -04:00
|
|
|
|
2018-10-09 21:34:50 -04:00
|
|
|
after do
|
|
|
|
Rails.logger = @orig_logger
|
2018-10-09 10:05:31 -04:00
|
|
|
end
|
|
|
|
|
2018-10-09 21:34:50 -04:00
|
|
|
it 'should log correctly on error' do
|
2018-10-15 15:06:02 -04:00
|
|
|
stub_request(:get, (ENV['HUB_BASE_URL'] || "http://local.hub:3000/api") + '/test').
|
2018-10-09 21:34:50 -04:00
|
|
|
to_return(status: 500, body: "", headers: {})
|
|
|
|
|
|
|
|
DiscourseHub.collection_action(:get, '/test')
|
2018-10-09 10:05:31 -04:00
|
|
|
|
2018-10-09 21:34:50 -04:00
|
|
|
expect(Rails.logger.warnings).to eq([
|
|
|
|
DiscourseHub.response_status_log_message('/test', 500),
|
|
|
|
])
|
2018-10-09 10:05:31 -04:00
|
|
|
|
2018-10-09 21:34:50 -04:00
|
|
|
expect(Rails.logger.errors).to eq([
|
|
|
|
DiscourseHub.response_body_log_message("")
|
|
|
|
])
|
2018-10-09 10:05:31 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|