mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
New bootstrap.json
endpoint for starting up Discourse
Discourse needs a bunch of data preloaded before it can start up. Normally we throw blobs of this into the HTML document that is requested but in some cases that's awkward to retrieve. For example with Ember CLI you have a separate javascript application that needs to make its own HTML. This API endpoint returns a JSON object with all the data Discourse needs to bootstrap and start up.
This commit is contained in:
40
spec/requests/bootstrap_controller_spec.rb
Normal file
40
spec/requests/bootstrap_controller_spec.rb
Normal file
@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe BootstrapController do
|
||||
|
||||
it "returns data as anonymous" do
|
||||
get "/bootstrap.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = response.parsed_body
|
||||
expect(json).to be_present
|
||||
|
||||
bootstrap = json['bootstrap']
|
||||
expect(bootstrap).to be_present
|
||||
expect(bootstrap['title']).to be_present
|
||||
expect(bootstrap['setup_data']['base_url']).to eq(Discourse.base_url)
|
||||
preloaded = bootstrap['preloaded']
|
||||
expect(preloaded['site']).to be_present
|
||||
expect(preloaded['siteSettings']).to be_present
|
||||
expect(preloaded['currentUser']).to be_blank
|
||||
expect(preloaded['topicTrackingStates']).to be_blank
|
||||
end
|
||||
|
||||
it "returns user data when authenticated" do
|
||||
user = Fabricate(:user)
|
||||
sign_in(user)
|
||||
get "/bootstrap.json"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
json = response.parsed_body
|
||||
expect(json).to be_present
|
||||
|
||||
bootstrap = json['bootstrap']
|
||||
preloaded = bootstrap['preloaded']
|
||||
expect(preloaded['currentUser']).to be_present
|
||||
expect(preloaded['topicTrackingStates']).to be_present
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user