discourse/plugins/discourse-narrative-bot/spec/requests/discobot_certificate_spec.rb
Rafael dos Santos Silva bf5611f7eb
FIX: Make discobot certificate faster/non blocking (#11344)
This moves the way we add the user avatar and site logo
to the discobot certificates from embeded base64 png to
just using the files urls in the href to the image tag.

This will make generation faster and the certificate
smaller overall, but it can't be used in a  `img` tag
anymore, since SVGs in `img` tags don't load the external images

In order to work around that we will move the certificate
in posts to an iframe, which works fine without any user
visible changes. For this to be possible the plugin automatically
adds the site current domain to the list of allowed iframe origins.
2021-02-01 20:49:32 -03:00

55 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
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
}
}
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 do
sign_in(user)
end
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