|
|
@ -1,9 +1,9 @@ |
|
|
|
require "rails_helper" |
|
|
|
require "rails_helper" |
|
|
|
|
|
|
|
|
|
|
|
RSpec.describe CaseLogsController, type: :request do |
|
|
|
RSpec.describe CaseLogsController, type: :request do |
|
|
|
let(:owning_organisation) { FactoryBot.create(:organisation) } |
|
|
|
|
|
|
|
let(:managing_organisation) { owning_organisation } |
|
|
|
|
|
|
|
let(:user) { FactoryBot.create(:user) } |
|
|
|
let(:user) { FactoryBot.create(:user) } |
|
|
|
|
|
|
|
let(:owning_organisation) { user.organisation } |
|
|
|
|
|
|
|
let(:managing_organisation) { owning_organisation } |
|
|
|
let(:api_username) { "test_user" } |
|
|
|
let(:api_username) { "test_user" } |
|
|
|
let(:api_password) { "test_password" } |
|
|
|
let(:api_password) { "test_password" } |
|
|
|
let(:basic_credentials) do |
|
|
|
let(:basic_credentials) do |
|
|
@ -198,15 +198,18 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
context "when filtering" do |
|
|
|
context "when filtering" do |
|
|
|
context "with status filter" do |
|
|
|
context "with status filter" do |
|
|
|
let(:organisation_2) { FactoryBot.create(:organisation) } |
|
|
|
let(:organisation_2) { FactoryBot.create(:organisation) } |
|
|
|
|
|
|
|
let(:user_2) { FactoryBot.create(:user, organisation: organisation_2) } |
|
|
|
let!(:in_progress_case_log) do |
|
|
|
let!(:in_progress_case_log) do |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
managing_organisation: organisation) |
|
|
|
managing_organisation: organisation, |
|
|
|
|
|
|
|
created_by: user) |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:completed_case_log) do |
|
|
|
let!(:completed_case_log) do |
|
|
|
FactoryBot.create(:case_log, :completed, |
|
|
|
FactoryBot.create(:case_log, :completed, |
|
|
|
owning_organisation: organisation_2, |
|
|
|
owning_organisation: organisation_2, |
|
|
|
managing_organisation: organisation) |
|
|
|
managing_organisation: organisation, |
|
|
|
|
|
|
|
created_by: user_2) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows case logs for multiple selected statuses" do |
|
|
|
it "shows case logs for multiple selected statuses" do |
|
|
@ -272,7 +275,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
startdate: Time.zone.local(2022, 3, 1), |
|
|
|
startdate: Time.zone.local(2022, 3, 1), |
|
|
|
managing_organisation: organisation) |
|
|
|
managing_organisation: organisation, |
|
|
|
|
|
|
|
created_by: user) |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:case_log_2022) do |
|
|
|
let!(:case_log_2022) do |
|
|
|
FactoryBot.create(:case_log, :completed, |
|
|
|
FactoryBot.create(:case_log, :completed, |
|
|
@ -280,7 +284,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
mrcdate: Time.zone.local(2022, 2, 1), |
|
|
|
mrcdate: Time.zone.local(2022, 2, 1), |
|
|
|
startdate: Time.zone.local(2022, 12, 1), |
|
|
|
startdate: Time.zone.local(2022, 12, 1), |
|
|
|
tenancy: 6, |
|
|
|
tenancy: 6, |
|
|
|
managing_organisation: organisation) |
|
|
|
managing_organisation: organisation, |
|
|
|
|
|
|
|
created_by: user) |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:case_log_2022_in_progress) do |
|
|
|
let!(:case_log_2022_in_progress) do |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
|
FactoryBot.create(:case_log, :in_progress, |
|
|
@ -289,7 +294,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
startdate: Time.zone.local(2022, 12, 1), |
|
|
|
startdate: Time.zone.local(2022, 12, 1), |
|
|
|
tenancy: 6, |
|
|
|
tenancy: 6, |
|
|
|
managing_organisation: organisation, |
|
|
|
managing_organisation: organisation, |
|
|
|
tenancycode: nil) |
|
|
|
tenancycode: nil, |
|
|
|
|
|
|
|
created_by: user) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows case logs for multiple selected statuses and years" do |
|
|
|
it "shows case logs for multiple selected statuses and years" do |
|
|
@ -321,8 +327,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when using a search query" do |
|
|
|
context "when using a search query" do |
|
|
|
let(:logs) { FactoryBot.create_list(:case_log, 3, :completed, owning_organisation: user.organisation) } |
|
|
|
let(:logs) { FactoryBot.create_list(:case_log, 3, :completed, owning_organisation: user.organisation, created_by: user) } |
|
|
|
let(:log_to_search) { FactoryBot.create(:case_log, :completed, owning_organisation: user.organisation) } |
|
|
|
let(:log_to_search) { FactoryBot.create(:case_log, :completed, owning_organisation: user.organisation, created_by: user) } |
|
|
|
let(:log_total_count) { CaseLog.where(owning_organisation: user.organisation).count } |
|
|
|
let(:log_total_count) { CaseLog.where(owning_organisation: user.organisation).count } |
|
|
|
|
|
|
|
|
|
|
|
it "has search results in the title" do |
|
|
|
it "has search results in the title" do |
|
|
@ -377,7 +383,7 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
|
|
|
|
|
|
|
|
context "when there are more than 1 page of search results" do |
|
|
|
context "when there are more than 1 page of search results" do |
|
|
|
let(:postcode) { "XX11YY" } |
|
|
|
let(:postcode) { "XX11YY" } |
|
|
|
let(:logs) { FactoryBot.create_list(:case_log, 30, :completed, owning_organisation: user.organisation, postcode_full: postcode) } |
|
|
|
let(:logs) { FactoryBot.create_list(:case_log, 30, :completed, owning_organisation: user.organisation, postcode_full: postcode, created_by: user) } |
|
|
|
let(:log_total_count) { CaseLog.where(owning_organisation: user.organisation).count } |
|
|
|
let(:log_total_count) { CaseLog.where(owning_organisation: user.organisation).count } |
|
|
|
|
|
|
|
|
|
|
|
it "has title with pagination details for page 1" do |
|
|
|
it "has title with pagination details for page 1" do |
|
|
@ -414,7 +420,7 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
context "when search and filter is present" do |
|
|
|
context "when search and filter is present" do |
|
|
|
let(:matching_postcode) { log_to_search.postcode_full } |
|
|
|
let(:matching_postcode) { log_to_search.postcode_full } |
|
|
|
let(:matching_status) { "in_progress" } |
|
|
|
let(:matching_status) { "in_progress" } |
|
|
|
let!(:log_matching_filter_and_search) { FactoryBot.create(:case_log, :in_progress, owning_organisation: user.organisation, postcode_full: matching_postcode) } |
|
|
|
let!(:log_matching_filter_and_search) { FactoryBot.create(:case_log, :in_progress, owning_organisation: user.organisation, postcode_full: matching_postcode, created_by: user) } |
|
|
|
|
|
|
|
|
|
|
|
it "shows only logs matching both search and filters" do |
|
|
|
it "shows only logs matching both search and filters" do |
|
|
|
get "/logs?search=#{matching_postcode}&status[]=#{matching_status}", headers: headers, params: {} |
|
|
|
get "/logs?search=#{matching_postcode}&status[]=#{matching_status}", headers: headers, params: {} |
|
|
@ -732,7 +738,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
FactoryBot.create(:case_log, |
|
|
|
:completed, |
|
|
|
:completed, |
|
|
|
owning_organisation: organisation, |
|
|
|
owning_organisation: organisation, |
|
|
|
managing_organisation: organisation) |
|
|
|
managing_organisation: organisation, |
|
|
|
|
|
|
|
created_by: user) |
|
|
|
get "/logs", headers:, params: {} |
|
|
|
get "/logs", headers:, params: {} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -768,8 +775,8 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
let(:postcode) { "XX1 1TG" } |
|
|
|
let(:postcode) { "XX1 1TG" } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
FactoryBot.create(:case_log, :in_progress, postcode_full: postcode, owning_organisation: organisation) |
|
|
|
FactoryBot.create(:case_log, :in_progress, postcode_full: postcode, owning_organisation: organisation, created_by: user) |
|
|
|
FactoryBot.create(:case_log, :completed, postcode_full: postcode, owning_organisation: organisation) |
|
|
|
FactoryBot.create(:case_log, :completed, postcode_full: postcode, owning_organisation: organisation, created_by: user) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "downloads logs matching both csv and filter logs" do |
|
|
|
it "downloads logs matching both csv and filter logs" do |
|
|
|