2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe "Discobot Certificate" do
|
2018-08-19 23:21:54 -04:00
|
|
|
let(:user) { Fabricate(:user, name: "Jeff Atwood") }
|
|
|
|
|
|
|
|
let(:params) { { date: Time.zone.now.strftime("%b %d %Y"), user_id: user.id } }
|
|
|
|
|
|
|
|
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
|
2019-10-21 12:14:15 -04:00
|
|
|
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)
|
2018-08-19 23:21:54 -04:00
|
|
|
|
2019-01-02 02:29:17 -05:00
|
|
|
stub_request(:get, SiteSetting.site_logo_small_url).to_return(status: 200)
|
2018-08-19 23:21:54 -04:00
|
|
|
|
|
|
|
get "/discobot/certificate.svg", params: params
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2021-02-01 18:49:32 -05:00
|
|
|
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)
|
2018-08-19 23:21:54 -04:00
|
|
|
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
|