2024-07-19 14:57:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe '/sidekiq', type: :request do
|
2025-02-15 05:50:56 -05:00
|
|
|
context 'when Dawarich is in self-hosted mode' do
|
|
|
|
|
before do
|
|
|
|
|
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is not authenticated' do
|
|
|
|
|
it 'redirects to sign in page' do
|
|
|
|
|
get sidekiq_url
|
2024-07-19 14:57:14 -04:00
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
expect(response).to redirect_to('/users/sign_in')
|
|
|
|
|
end
|
2024-07-19 14:57:14 -04:00
|
|
|
end
|
|
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
context 'when user is authenticated' do
|
|
|
|
|
context 'when user is not admin' do
|
|
|
|
|
before { sign_in create(:user) }
|
2024-07-19 14:57:14 -04:00
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
it 'redirects to root page' do
|
|
|
|
|
get sidekiq_url
|
2024-07-19 14:57:14 -04:00
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
expect(response).to redirect_to(root_url)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows flash message' do
|
|
|
|
|
get sidekiq_url
|
|
|
|
|
|
|
|
|
|
expect(flash[:error]).to eq('You are not authorized to perform this action.')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is admin' do
|
|
|
|
|
before { sign_in create(:user, :admin) }
|
|
|
|
|
|
|
|
|
|
it 'renders a successful response' do
|
|
|
|
|
get sidekiq_url
|
|
|
|
|
|
|
|
|
|
expect(response).to be_successful
|
|
|
|
|
end
|
2024-07-19 14:57:14 -04:00
|
|
|
end
|
2025-02-15 05:50:56 -05:00
|
|
|
end
|
|
|
|
|
end
|
2024-07-19 14:57:14 -04:00
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
context 'when Dawarich is not in self-hosted mode' do
|
|
|
|
|
before do
|
|
|
|
|
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
|
|
|
|
|
Rails.application.reload_routes!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is not authenticated' do
|
|
|
|
|
it 'redirects to sign in page' do
|
2024-07-19 14:57:14 -04:00
|
|
|
get sidekiq_url
|
|
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
expect(response).to redirect_to('/users/sign_in')
|
2024-07-19 14:57:14 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
context 'when user is authenticated' do
|
2024-07-19 14:57:14 -04:00
|
|
|
before { sign_in create(:user, :admin) }
|
|
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
it 'redirects to root page' do
|
2024-07-19 14:57:14 -04:00
|
|
|
get sidekiq_url
|
|
|
|
|
|
2025-02-15 05:50:56 -05:00
|
|
|
expect(response).to redirect_to(root_url)
|
|
|
|
|
expect(flash[:error]).to eq('You are not authorized to perform this action.')
|
2024-07-19 14:57:14 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|