# frozen_string_literal: true require "rails_helper" describe WellKnown::NodeInfoController do describe "#discovery" do subject { get :discovery } it "returns the expected response" do subject parsed = JSON.parse(response.body) expect(parsed).to eq({ "links" => [ { "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1", "href" => "http://test.host/nodeinfo/2.1", } ], }) end end describe "#nodeinfo" do subject { get :nodeinfo } it "is valid as specified by the schema" do get(:discovery) schema = response.body subject parsed = JSON.parse(response.body) messages = JSON::Validator.fully_validate(schema, parsed) expect(messages).to be_empty end context "version is 2023.0102.1" do before do allow(Retrospring::Version).to receive(:to_s).and_return("2023.0102.1") end it "returns the correct version" do subject parsed = JSON.parse(response.body) expect(parsed["software"]).to eq({ "name" => "Retrospring", "version" => "2023.0102.1", "repository" => "https://lab.freak.university/FreakU/retrospring" }) end end context "site has users" do let(:num_users) { rand(10..50) } before do FactoryBot.create_list(:user, num_users) end it "includes the correct user count" do subject parsed = JSON.parse(response.body) expect(parsed.dig("usage", "users", "total")).to eq(num_users) end end end end