@ -78,7 +78,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
before do
before do
file . write ( BulkUpload :: LogToCsv . new ( log : , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . rewind
file . close
end
end
it " creates validation errors " do
it " creates validation errors " do
@ -112,4 +112,148 @@ RSpec.describe BulkUpload::Lettings::Validator do
end
end
end
end
end
end
describe " # create_logs? " do
context " when a log is not valid? " do
let ( :log_1 ) { build ( :lettings_log , :completed , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , :completed , created_by : user ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 , overrides : { illness : 100 } ) . to_csv_row )
file . close
end
it " returns false " do
validator . call
expect ( validator ) . not_to be_create_logs
end
end
context " when all logs valid? " do
let ( :log_1 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns true " do
validator . call
expect ( validator ) . to be_create_logs
end
end
context " when a log has incomplete setup secion " do
let ( :log ) { build ( :lettings_log , :in_progress , created_by : user , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns false " do
validator . call
expect ( validator ) . not_to be_create_logs
end
end
context " when a column has error rate below absolute threshold " do
context " when a column is over 60% error threshold " do
let ( :log_1 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_3 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_4 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_5 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_3 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_4 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_5 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns true " do
validator . call
expect ( validator ) . to be_create_logs
end
end
context " when a column is under 60% error threshold " do
let ( :log_1 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_3 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_4 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_5 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_3 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_4 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_5 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns true " do
validator . call
expect ( validator ) . to be_create_logs
end
end
end
context " when a column has error rate above absolute threshold " do
before do
stub_const ( " BulkUpload::Lettings::Validator::COLUMN_ABSOLUTE_ERROR_THRESHOLD " , 1 )
end
context " when a column is over 60% error threshold " do
let ( :log_1 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_3 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_4 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_5 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_3 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_4 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_5 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns false " do
validator . call
expect ( validator ) . not_to be_create_logs
end
end
context " when a column is under 60% error threshold " do
let ( :log_1 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_2 ) { build ( :lettings_log , :completed , renttype : 1 , created_by : user ) }
let ( :log_3 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_4 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
let ( :log_5 ) { build ( :lettings_log , renttype : 2 , created_by : user , builtype : nil , startdate : Time . zone . local ( 2022 , 5 , 1 ) ) }
before do
file . write ( BulkUpload :: LogToCsv . new ( log : log_1 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_2 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_3 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_4 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . write ( BulkUpload :: LogToCsv . new ( log : log_5 , line_ending : " \r \n " , col_offset : 0 ) . to_csv_row )
file . close
end
it " returns true " do
validator . call
expect ( validator ) . to be_create_logs
end
end
end
end
end
end