mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
FIX: Make Discobot certificate route require login.
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
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)
|
||||
|
||||
stub_request(:get, "http://test.localhost//images/d-logo-sketch-small.png")
|
||||
.to_return(status: 200)
|
||||
|
||||
get '/discobot/certificate.svg', params: params
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
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
|
@ -0,0 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "Discobot welcome post" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.discourse_narrative_bot_enabled = true
|
||||
end
|
||||
|
||||
context 'when discourse_narrative_bot_welcome_post_delay is 0' do
|
||||
it 'should not delay the welcome post' do
|
||||
user
|
||||
expect { sign_in(user) }.to_not change { Jobs::NarrativeInit.jobs.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'When discourse_narrative_bot_welcome_post_delay is greater than 0' do
|
||||
before do
|
||||
SiteSetting.discourse_narrative_bot_welcome_post_delay = 5
|
||||
end
|
||||
|
||||
context 'when user logs in normally' do
|
||||
it 'should delay the welcome post until user logs in' do
|
||||
expect { sign_in(user) }.to change { Jobs::NarrativeInit.jobs.count }.by(1)
|
||||
expect(Jobs::NarrativeInit.jobs.first["args"].first["user_id"]).to eq(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user redeems an invite' do
|
||||
let(:invite) { Fabricate(:invite, invited_by: Fabricate(:admin), email: 'testing@gmail.com') }
|
||||
|
||||
it 'should delay the welcome post until the user logs in' do
|
||||
invite
|
||||
|
||||
expect do
|
||||
put "/invites/show/#{invite.invite_key}.json", params: {
|
||||
username: 'somename',
|
||||
name: 'testing',
|
||||
password: 'asodaasdaosdhq'
|
||||
}
|
||||
end.to change { User.count }.by(1)
|
||||
|
||||
expect(Jobs::NarrativeInit.jobs.first["args"].first["user_id"]).to eq(User.last.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user