|
|
@ -4,32 +4,33 @@ RSpec.describe BulkUploadController, type: :request do |
|
|
|
let(:url) { "/logs/bulk-upload" } |
|
|
|
let(:url) { "/logs/bulk-upload" } |
|
|
|
let(:user) { FactoryBot.create(:user) } |
|
|
|
let(:user) { FactoryBot.create(:user) } |
|
|
|
let(:organisation) { user.organisation } |
|
|
|
let(:organisation) { user.organisation } |
|
|
|
|
|
|
|
let(:valid_file) { fixture_file_upload("2021_22_lettings_bulk_upload.xlsx", "application/vnd.ms-excel") } |
|
|
|
|
|
|
|
let(:invalid_file) { fixture_file_upload("random.txt", "text/plain") } |
|
|
|
|
|
|
|
let(:empty_file) { fixture_file_upload("2021_22_lettings_bulk_upload_empty.xlsx", "application/vnd.ms-excel") } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
allow(Organisation).to receive(:find).with(107_242).and_return(organisation) |
|
|
|
allow(Organisation).to receive(:find).with(107_242).and_return(organisation) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "a not signed in user" do |
|
|
|
context "when a user is not signed in" do |
|
|
|
describe "GET #show" do |
|
|
|
describe "GET #show" do |
|
|
|
|
|
|
|
before { get url, headers: headers, params: {} } |
|
|
|
|
|
|
|
|
|
|
|
it "does not let you see the bulk upload page" do |
|
|
|
it "does not let you see the bulk upload page" do |
|
|
|
get url, headers: headers, params: {} |
|
|
|
|
|
|
|
expect(response).to redirect_to("/users/sign-in") |
|
|
|
expect(response).to redirect_to("/users/sign-in") |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "POST #bulk upload" do |
|
|
|
describe "POST #bulk upload" do |
|
|
|
before do |
|
|
|
before { post url, params: { bulk_upload: { case_log_bulk_upload: valid_file } } } |
|
|
|
@file = fixture_file_upload("2021_22_lettings_bulk_upload.xlsx", "application/vnd.ms-excel") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "does not let you submit bulk uploads" do |
|
|
|
it "does not let you submit bulk uploads" do |
|
|
|
post url, params: { bulk_upload: { case_log_bulk_upload: @file } } |
|
|
|
|
|
|
|
expect(response).to redirect_to("/users/sign-in") |
|
|
|
expect(response).to redirect_to("/users/sign-in") |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "a signed in user" do |
|
|
|
context "when a user is signed in" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
sign_in user |
|
|
|
sign_in user |
|
|
|
end |
|
|
|
end |
|
|
@ -50,40 +51,31 @@ RSpec.describe BulkUploadController, type: :request do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
describe "POST #bulk upload" do |
|
|
|
describe "POST #bulk upload" do |
|
|
|
subject { post url, params: { bulk_upload: { case_log_bulk_upload: @file } } } |
|
|
|
context "with a valid file based on the upload template" do |
|
|
|
|
|
|
|
let(:request) { post url, params: { bulk_upload: { case_log_bulk_upload: valid_file } } } |
|
|
|
context "given a valid file based on the upload template" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
@file = fixture_file_upload("2021_22_lettings_bulk_upload.xlsx", "application/vnd.ms-excel") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "creates case logs for each row in the template" do |
|
|
|
it "creates case logs for each row in the template" do |
|
|
|
expect { subject }.to change(CaseLog, :count).by(9) |
|
|
|
expect { request }.to change(CaseLog, :count).by(9) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "redirects to the case log index page" do |
|
|
|
it "redirects to the case log index page" do |
|
|
|
expect(subject).to redirect_to(case_logs_path) |
|
|
|
expect(request).to redirect_to(case_logs_path) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "given an invalid file type" do |
|
|
|
context "with an invalid file type" do |
|
|
|
before do |
|
|
|
before { post url, params: { bulk_upload: { case_log_bulk_upload: invalid_file } } } |
|
|
|
@file = fixture_file_upload("random.txt", "text/plain") |
|
|
|
|
|
|
|
subject |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "displays an error message" do |
|
|
|
it "displays an error message" do |
|
|
|
expect(response.body).to match(/Invalid file type/) |
|
|
|
expect(response.body).to match(/Invalid file type/) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "given an empty file" do |
|
|
|
context "with an empty file" do |
|
|
|
before do |
|
|
|
let(:request) { post url, params: { bulk_upload: { case_log_bulk_upload: empty_file } } } |
|
|
|
@file = fixture_file_upload("2021_22_lettings_bulk_upload_empty.xlsx", "application/vnd.ms-excel") |
|
|
|
|
|
|
|
subject |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "displays an error message" do |
|
|
|
it "displays an error message" do |
|
|
|
|
|
|
|
request |
|
|
|
expect(response.body).to match(/No data found/) |
|
|
|
expect(response.body).to match(/No data found/) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|