@ -108,6 +108,11 @@ RSpec.describe CollectionResourcesController, type: :request do
expect ( page ) . to have_link ( " Change " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " sales " , resource_type : " bulk_upload_template " ) )
expect ( page ) . to have_link ( " Change " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " sales " , resource_type : " bulk_upload_specification " ) )
end
it " displays next year banner " do
expect ( page ) . to have_content ( " The 2025 to 2026 collection resources are not yet available to users. " )
expect ( page ) . to have_link ( " Release the 2025 to 2026 collection resources to users " , href : confirm_mandatory_collection_resources_release_path ( year : 2025 ) )
end
end
context " when files are not on S3 " do
@ -122,6 +127,24 @@ RSpec.describe CollectionResourcesController, type: :request do
it " displays upload links " do
expect ( page ) . to have_selector ( :link_or_button , " Upload " , count : 12 )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " lettings " , resource_type : " paper_form " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " lettings " , resource_type : " bulk_upload_template " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " lettings " , resource_type : " bulk_upload_specification " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " paper_form " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " bulk_upload_template " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " bulk_upload_specification " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " lettings " , resource_type : " paper_form " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " lettings " , resource_type : " bulk_upload_template " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " lettings " , resource_type : " bulk_upload_specification " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " sales " , resource_type : " paper_form " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " sales " , resource_type : " bulk_upload_template " ) )
expect ( page ) . to have_link ( " Upload " , href : edit_mandatory_collection_resource_path ( year : 2025 , log_type : " sales " , resource_type : " bulk_upload_specification " ) )
end
it " displays next year banner " do
expect ( page ) . to have_content ( " The 2025 to 2026 collection resources are not yet available to users. " )
expect ( page ) . to have_content ( " Once you have uploaded all the required 2025 to 2026 collection resources, you will be able to release them to users. " )
end
end
end
@ -243,16 +266,40 @@ RSpec.describe CollectionResourcesController, type: :request do
sign_in user
end
it " displays update collection resources page content " do
get edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " bulk_upload_template " )
context " and the file exists on S3 " do
before do
allow ( storage_service ) . to receive ( :file_exists? ) . and_return ( true )
end
expect ( page ) . to have_content ( " Sales 2024 to 2025 " )
expect ( page ) . to have_content ( " Change the bulk upload template " )
expect ( page ) . to have_content ( " This file will be available for all users to download. " )
expect ( page ) . to have_content ( " Upload file " )
expect ( page ) . to have_button ( " Save changes " )
expect ( page ) . to have_link ( " Back " , href : collection_resources_path )
expect ( page ) . to have_link ( " Cancel " , href : collection_resources_path )
it " displays update collection resources page content " do
get edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " bulk_upload_template " )
expect ( page ) . to have_content ( " Sales 2024 to 2025 " )
expect ( page ) . to have_content ( " Change the bulk upload template " )
expect ( page ) . to have_content ( " This file will be available for all users to download. " )
expect ( page ) . to have_content ( " Upload file " )
expect ( page ) . to have_button ( " Save changes " )
expect ( page ) . to have_link ( " Back " , href : collection_resources_path )
expect ( page ) . to have_link ( " Cancel " , href : collection_resources_path )
end
end
context " and the file does not exist on S3 " do
before do
allow ( storage_service ) . to receive ( :file_exists? ) . and_return ( false )
end
it " displays upload collection resources page content " do
get edit_mandatory_collection_resource_path ( year : 2024 , log_type : " sales " , resource_type : " bulk_upload_template " )
expect ( page ) . to have_content ( " Sales 2024 to 2025 " )
expect ( page ) . to have_content ( " Upload the bulk upload template " )
expect ( page ) . to have_content ( " This file will be available for all users to download. " )
expect ( page ) . to have_content ( " Upload file " )
expect ( page ) . to have_button ( " Upload " )
expect ( page ) . to have_link ( " Back " , href : collection_resources_path )
expect ( page ) . to have_link ( " Cancel " , href : collection_resources_path )
end
end
end
end
@ -299,4 +346,131 @@ RSpec.describe CollectionResourcesController, type: :request do
end
end
end
describe " GET # confirm_mandatory_collection_resources_release " do
context " when user is not signed in " do
it " redirects to the sign in page " do
get confirm_mandatory_collection_resources_release_path ( year : 2025 )
expect ( response ) . to redirect_to ( new_user_session_path )
end
end
context " when user is signed in as a data coordinator " do
let ( :user ) { create ( :user , :data_coordinator ) }
before do
sign_in user
end
it " returns page not found " do
get confirm_mandatory_collection_resources_release_path ( year : 2025 )
expect ( response ) . to have_http_status ( :not_found )
end
end
context " when user is signed in as a data provider " do
let ( :user ) { create ( :user , :data_provider ) }
before do
sign_in user
end
it " returns page not found " do
get confirm_mandatory_collection_resources_release_path ( year : 2025 )
expect ( response ) . to have_http_status ( :not_found )
end
end
context " when user is signed in as a support user " do
let ( :user ) { create ( :user , :support ) }
before do
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of ( CollectionResourcesHelper ) . to receive ( :editable_collection_resource_years ) . and_return ( [ 2025 ] )
# rubocop:enable RSpec/AnyInstance
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
sign_in user
end
it " displays correct page content " do
get confirm_mandatory_collection_resources_release_path ( year : 2025 )
expect ( page ) . to have_content ( " Are you sure you want to release the 2025 to 2026 collection resources? " )
expect ( page ) . to have_content ( " The files uploaded will immediately become available for users to download. " )
expect ( page ) . to have_content ( " You will not be able to undo this action. " )
expect ( page ) . to have_button ( " Release the resources " )
expect ( page ) . to have_link ( " Cancel " , href : collection_resources_path )
expect ( page ) . to have_link ( " Back " , href : collection_resources_path )
end
end
end
describe " PATCH # release_mandatory_collection_resources_path " do
let ( :some_file ) { File . open ( file_fixture ( " blank_bulk_upload_sales.csv " ) ) }
let ( :collection_resource_service ) { instance_double ( CollectionResourcesService ) }
before do
allow ( CollectionResourcesService ) . to receive ( :new ) . and_return ( collection_resource_service )
end
context " when user is not signed in " do
it " redirects to the sign in page " do
patch release_mandatory_collection_resources_path ( year : 2024 )
expect ( response ) . to redirect_to ( new_user_session_path )
end
end
context " when user is signed in as a data coordinator " do
let ( :user ) { create ( :user , :data_coordinator ) }
before do
sign_in user
end
it " returns page not found " do
patch release_mandatory_collection_resources_path ( year : 2024 )
expect ( response ) . to have_http_status ( :not_found )
end
end
context " when user is signed in as a data provider " do
let ( :user ) { create ( :user , :data_provider ) }
before do
sign_in user
end
it " returns page not found " do
patch release_mandatory_collection_resources_path ( year : 2024 )
expect ( response ) . to have_http_status ( :not_found )
end
end
context " when user is signed in as a support user " do
let ( :user ) { create ( :user , :support ) }
before do
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of ( CollectionResourcesHelper ) . to receive ( :editable_collection_resource_years ) . and_return ( [ 2025 ] )
# rubocop:enable RSpec/AnyInstance
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
sign_in user
end
it " saves resources as released to users " do
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true ) . count ) . to eq ( 0 )
patch release_mandatory_collection_resources_path ( year : 2025 )
expect ( CollectionResource . all . count ) . to eq ( 6 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " sales " , resource_type : " paper_form " ) . count ) . to eq ( 1 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " sales " , resource_type : " bulk_upload_template " ) . count ) . to eq ( 1 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " sales " , resource_type : " bulk_upload_specification " ) . count ) . to eq ( 1 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " lettings " , resource_type : " paper_form " ) . count ) . to eq ( 1 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " lettings " , resource_type : " bulk_upload_template " ) . count ) . to eq ( 1 )
expect ( CollectionResource . where ( year : 2025 , mandatory : true , released_to_user : true , log_type : " lettings " , resource_type : " bulk_upload_specification " ) . count ) . to eq ( 1 )
expect ( response ) . to redirect_to ( collection_resources_path )
expect ( flash [ :notice ] ) . to eq ( " The 2025 to 2026 collection resources are now available to users. " )
end
end
end
end