docbrown/spec/requests/api/v0/instances_spec.rb
Alex 7a48708156
API: Add instance endpoint and spec (#14301)
* Create /api/forem_directories endpoint and spec

* PR feedback

* Update regex in spec
2021-07-23 12:10:08 -04:00

46 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe "Api::V0::Instances", type: :request do
describe "GET /api/instance" do
it "returns the correct attributes", :aggregate_failures do
get api_instance_path
expect(response.parsed_body["cover_image_url"]).to eq Settings::General.main_social_image
expect(response.parsed_body["description"]).to eq Settings::Community.community_description
expect(response.parsed_body["logo_image_url"]).to eq Settings::General.logo_png
expect(response.parsed_body["name"]).to eq Settings::Community.community_name
expect(response.parsed_body["tagline"]).to eq Settings::Community.tagline
expect(response.parsed_body["version"]).to match(/(stable|beta|edge)\.\d{8}\.\d+/)
expect(response.parsed_body["visibility"]).to eq "public"
end
context "when the Forem is public" do
it "returns public for visibility" do
allow(Settings::General).to receive(:waiting_on_first_user).and_return(false)
allow(Settings::UserExperience).to receive(:public).and_return(true)
get api_instance_path
expect(response.parsed_body["visibility"]).to eq "public"
end
end
context "when the Forem is not public" do
it "returns private for visibility" do
allow(Settings::General).to receive(:waiting_on_first_user).and_return(false)
allow(Settings::UserExperience).to receive(:public).and_return(false)
get api_instance_path
expect(response.parsed_body["visibility"]).to eq "private"
end
end
context "when the Forem is pending" do
it "returns pending for visibility" do
allow(Settings::General).to receive(:waiting_on_first_user).and_return(true)
get api_instance_path
expect(response.parsed_body["visibility"]).to eq "pending"
end
end
end
end