2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-17 11:05:09 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
RSpec.describe Admin::ExportDomainAllowsController do
|
2022-11-17 11:05:09 +01:00
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
|
|
|
end
|
|
|
|
|
2023-10-16 17:20:28 +02:00
|
|
|
describe 'GET #new' do
|
|
|
|
it 'returns http success' do
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-17 11:05:09 +01:00
|
|
|
describe 'GET #export' do
|
|
|
|
it 'renders instances' do
|
|
|
|
Fabricate(:domain_allow, domain: 'good.domain')
|
|
|
|
Fabricate(:domain_allow, domain: 'better.domain')
|
|
|
|
|
|
|
|
get :export, params: { format: :csv }
|
|
|
|
expect(response).to have_http_status(200)
|
2023-12-04 09:52:21 +01:00
|
|
|
expect(response.body).to eq(domain_allows_csv_file)
|
2022-11-17 11:05:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #import' do
|
|
|
|
it 'allows imported domains' do
|
|
|
|
post :import, params: { admin_import: { data: fixture_file_upload('domain_allows.csv') } }
|
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_instances_path)
|
|
|
|
|
|
|
|
# Header should not be imported
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(DomainAllow.where(domain: '#domain').present?).to be(false)
|
2022-11-17 11:05:09 +01:00
|
|
|
|
|
|
|
# Domains should now be added
|
|
|
|
get :export, params: { format: :csv }
|
|
|
|
expect(response).to have_http_status(200)
|
2023-12-04 09:52:21 +01:00
|
|
|
expect(response.body).to eq(domain_allows_csv_file)
|
2022-11-17 11:05:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays error on no file selected' do
|
|
|
|
post :import, params: { admin_import: {} }
|
|
|
|
expect(response).to redirect_to(admin_instances_path)
|
|
|
|
expect(flash[:error]).to eq(I18n.t('admin.export_domain_allows.no_file'))
|
|
|
|
end
|
|
|
|
end
|
2023-12-04 09:52:21 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def domain_allows_csv_file
|
|
|
|
File.read(File.join(file_fixture_path, 'domain_allows.csv'))
|
|
|
|
end
|
2022-11-17 11:05:09 +01:00
|
|
|
end
|