mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
Previously enabling the Patreon plugin and clicking its sidebar link gave you an "Error loading route" whenever the Patreon connection was not configured. This change moves the plugin off the legacy admin route pattern and adds an empty state linking to its settings so an unconfigured Patreon explains why instead of failing. Before: <img width="700" alt="image" src="https://github.com/user-attachments/assets/90cc16c5-e3be-4b4a-8e59-87ce8c27875d" /> After: <img width="900" alt="image" src="https://github.com/user-attachments/assets/5865d330-1020-4b05-aff9-799a51e62c13" />
72 lines
2.1 KiB
Ruby
Vendored
72 lines
2.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
describe Patreon::PatreonAdminController do
|
|
describe "#list" do
|
|
let(:group1) { Fabricate(:group) }
|
|
let(:group2) { Fabricate(:group) }
|
|
let(:admin) { Fabricate(:admin) }
|
|
let(:filters) { { group1.id.to_s => ["0"], group2.id.to_s => ["208"], "777" => ["888"] } }
|
|
let(:rewards) { { "1": { sample: "reward" }, "2": { another: "one" } } }
|
|
|
|
before do
|
|
sign_in(admin)
|
|
SiteSetting.patreon_enabled = true
|
|
SiteSetting.patreon_creator_access_token = "TOKEN"
|
|
SiteSetting.patreon_creator_refresh_token = "TOKEN"
|
|
Patreon.set("filters", filters)
|
|
Patreon.set("rewards", rewards)
|
|
end
|
|
|
|
it "should display list of patreon groups" do
|
|
get "/patreon/list.json"
|
|
|
|
result = JSON.parse(response.body)
|
|
expect(result["filters"].count).to eq(2)
|
|
expect(result["rewards"].count).to eq(2)
|
|
end
|
|
|
|
it "reports that it is unconfigured when the creator tokens are missing" do
|
|
SiteSetting.patreon_creator_access_token = ""
|
|
|
|
get "/patreon/list.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body).to eq("unconfigured" => true)
|
|
end
|
|
|
|
it "should display list of rewards" do
|
|
get "/patreon/rewards.json"
|
|
|
|
rewards = JSON.parse(response.body)
|
|
expect(rewards.count).to eq(2)
|
|
end
|
|
|
|
it "should update existing filter" do
|
|
ids = %w[1 2]
|
|
|
|
post "/patreon/list.json", params: { rewards_ids: ids, group_id: group1.id }
|
|
|
|
expect(Patreon.get("filters")[group1.id.to_s]).to eq(ids)
|
|
end
|
|
|
|
it "should delete an filter" do
|
|
expect { delete "/patreon/list.json", params: { group_id: group1.id } }.to change {
|
|
Patreon.get("filters").count
|
|
}.by(-1)
|
|
expect(Patreon.get("filters")[group1.id.to_s]).to eq(nil)
|
|
end
|
|
|
|
it "should sync patreon groups" do
|
|
Patreon::Patron.expects(:sync_groups)
|
|
post "/patreon/sync_groups.json"
|
|
end
|
|
|
|
it "should enqueue job to sync patrons and groups" do
|
|
expect_enqueued_with(job: :patreon_sync_patrons_to_groups) do
|
|
post "/patreon/update_data.json"
|
|
end
|
|
|
|
expect(response.status).to eq(200)
|
|
end
|
|
end
|
|
end
|