@ -11,6 +11,8 @@ RSpec.describe BulkUpload::Lettings::RowParser do
let ( :owning_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :owning_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :managing_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :managing_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :location ) { create ( :location , :with_old_visible_id , scheme : ) }
let ( :setup_section_params ) do
let ( :setup_section_params ) do
{
{
@ -85,7 +87,7 @@ RSpec.describe BulkUpload::Lettings::RowParser do
{
{
bulk_upload : ,
bulk_upload : ,
field_1 : " 1 " ,
field_1 : " 1 " ,
field_4 : " 1 " ,
field_4 : scheme . old_visible_id ,
field_7 : " 123 " ,
field_7 : " 123 " ,
field_96 : now . day . to_s ,
field_96 : now . day . to_s ,
field_97 : now . month . to_s ,
field_97 : now . month . to_s ,
@ -296,10 +298,90 @@ RSpec.describe BulkUpload::Lettings::RowParser do
context " when matching scheme cannot be found " do
context " when matching scheme cannot be found " do
let ( :attributes ) { { bulk_upload : , field_1 : " 1 " , field_4 : " 123 " } }
let ( :attributes ) { { bulk_upload : , field_1 : " 1 " , field_4 : " 123 " } }
x it " returns an error " do
it " returns an error " do
expect ( parser . errors [ :field_4 ] ) . to be_present
expect ( parser . errors [ :field_4 ] ) . to be_present
end
end
end
end
context " when scheme belongs to someone else " do
let ( :other_scheme ) { create ( :scheme , :with_old_visible_id ) }
let ( :attributes ) { { bulk_upload : , field_1 : " 1 " , field_4 : other_scheme . old_visible_id , field_111 : owning_org . old_visible_id } }
it " returns an error " do
expect ( parser . errors [ :field_4 ] ) . to include ( " This management group code does not belong to your organisation, or any of your stock owners / managing agents " )
end
end
context " when scheme belongs to owning org " do
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :attributes ) { { bulk_upload : , field_1 : " 1 " , field_4 : scheme . old_visible_id , field_111 : owning_org . old_visible_id } }
it " does not return an error " do
expect ( parser . errors [ :field_4 ] ) . to be_blank
end
end
context " when scheme belongs to managing org " do
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : managing_org ) }
let ( :attributes ) { { bulk_upload : , field_1 : " 1 " , field_4 : scheme . old_visible_id , field_113 : managing_org . old_visible_id } }
it " does not return an error " do
expect ( parser . errors [ :field_4 ] ) . to be_blank
end
end
end
describe " # field_5 " do
context " when location does not exist " do
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :attributes ) do
{
bulk_upload : ,
field_1 : " 1 " ,
field_4 : scheme . old_visible_id ,
field_5 : " dontexist " ,
field_111 : owning_org . old_visible_id ,
}
end
it " returns an error " do
expect ( parser . errors [ :field_5 ] ) . to be_present
end
end
context " when location exists " do
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :attributes ) do
{
bulk_upload : ,
field_1 : " 1 " ,
field_4 : scheme . old_visible_id ,
field_5 : location . old_visible_id ,
field_111 : owning_org . old_visible_id ,
}
end
it " does not return an error " do
expect ( parser . errors [ :field_5 ] ) . to be_blank
end
end
context " when location exists but not related " do
let ( :location ) { create ( :scheme , :with_old_visible_id ) }
let ( :attributes ) do
{
bulk_upload : ,
field_1 : " 1 " ,
field_4 : scheme . old_visible_id ,
field_5 : location . old_visible_id ,
field_111 : owning_org . old_visible_id ,
}
end
it " returns an error " do
expect ( parser . errors [ :field_5 ] ) . to be_present
end
end
end
end
describe " # field_7 " do
describe " # field_7 " do
@ -592,6 +674,26 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
describe " # log " do
describe " # log " do
describe " # location " do
context " when lookup is via new core id " do
let ( :attributes ) { { bulk_upload : , field_4 : scheme . old_visible_id , field_5 : location . id , field_111 : owning_org } }
it " assigns the correct location " do
expect ( parser . log . location ) . to eql ( location )
end
end
end
describe " # scheme " do
context " when lookup is via id prefixed with S " do
let ( :attributes ) { { bulk_upload : , field_4 : " S #{ scheme . id } " , field_111 : owning_org } }
it " assigns the correct scheme " do
expect ( parser . log . scheme ) . to eql ( scheme )
end
end
end
describe " # owning_organisation " do
describe " # owning_organisation " do
context " when lookup is via id prefixed with ORG " do
context " when lookup is via id prefixed with ORG " do
let ( :attributes ) { { bulk_upload : , field_111 : " ORG #{ owning_org . id } " } }
let ( :attributes ) { { bulk_upload : , field_111 : " ORG #{ owning_org . id } " } }