Alan Guo Xiang Tan 3491642f98
DEV: Make discourse_narrative_bot use Rails autoload ()
Why this change?

Instead of manually loading files, we should just structure the plugin
so that it relies on Rails autoload strategy and avoid all the manual
`require_relative`s.

What does this change do?

1. Structure the plugin to use Rails autoloading convention
2. Remove onceff jobs that were added 5-6 years ago. There is no need to
   carry these jobs anymore after such a long time.
3. Move setting of `SiteSetting.discourse_narrative_bot_enabled` to
   `false` in the test environment from core into the plugin.
2024-03-06 11:14:53 +08:00

49 lines
1.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Discobot Certificate" do
let(:user) { Fabricate(:user, name: "Jeff Atwood") }
let(:params) { { date: Time.zone.now.strftime("%b %d %Y"), user_id: user.id } }
before { SiteSetting.discourse_narrative_bot_enabled = true }
describe "when viewing the certificate" do
describe "when no logged in" do
it "should return the right response" do
get "/discobot/certificate.svg", params: params
expect(response.status).to eq(404)
end
end
describe "when logged in" do
before { sign_in(user) }
it "should return the right text" do
stub_request(:get, /letter_avatar_proxy/).to_return(
status: 200,
body: "http://test.localhost/cdn/avatar.png",
)
stub_request(:get, /avatar.png/).to_return(status: 200)
stub_request(:get, SiteSetting.site_logo_small_url).to_return(status: 200)
get "/discobot/certificate.svg", params: params
expect(response.status).to eq(200)
expect(response.body).to include("<svg")
expect(response.body).to include(user.avatar_template.gsub("{size}", "250"))
expect(response.body).to include(SiteSetting.site_logo_small_url)
end
describe "when params are missing" do
it "should raise the right errors" do
params.each do |key, _|
get "/discobot/certificate.svg", params: params.except(key)
expect(response.status).to eq(400)
end
end
end
end
end
end