docbrown/spec/requests/async_info_spec.rb
rhymes 6cd64c4071
Rubocop: enable and fix Style/Send and Style/Next (#9366)
* Enable and fix Style/Send

* Enable and fix Style/Next

* Fix private cookies send

* Fix merging indentation issues
2020-07-20 16:28:00 +02:00

52 lines
1.6 KiB
Ruby

require "rails_helper"
RSpec.describe "AsyncInfo", type: :request do
let(:controller_instance) { AsyncInfoController.new }
before do
allow(AsyncInfoController).to receive(:new).and_return(controller_instance)
end
describe "GET /async_info/base_data" do
context "when not logged-in" do
it "returns json without user" do
get "/async_info/base_data"
expect(response.parsed_body.keys).to match_array(%w[broadcast param token])
end
it "renders normal response even if site config is private" do
SiteConfig.public = false
get "/async_info/base_data"
expect(response.parsed_body.keys).to match_array(%w[broadcast param token])
end
end
context "when logged in" do
it "returns token and user" do
allow(controller_instance).to receive(:remember_user_token).and_return(nil)
sign_in create(:user)
get "/async_info/base_data"
expect(response.parsed_body.keys).to match_array(%w[broadcast param token user])
end
end
end
describe "GET /async_info/shell_version" do
it "returns shell_version" do
get "/async_info/shell_version"
expect(response.body).to include("version")
end
end
describe "#remember_user_token" do
# We require the remember_user_token key bc we also use it for caching in Fastly
# If this key changes, Fastly needs to be updated
it "requires remember_user_token cookie to be present" do
get "/async_info/base_data"
token = "a_token"
controller.__send__("cookies")[:remember_user_token] = "a_token"
expect(controller.remember_user_token).to eq(token)
end
end
end