11 changed files with 269 additions and 57 deletions
@ -0,0 +1,12 @@
|
||||
class CollectionResourcesController < ApplicationController |
||||
include CollectionResourcesHelper |
||||
|
||||
before_action :authenticate_user! |
||||
|
||||
def index |
||||
render_not_found unless current_user.support? |
||||
|
||||
@mandatory_lettings_collection_resources_per_year = MandatoryCollectionResourcesService.generate_resources("lettings", editable_collection_resource_years) |
||||
@mandatory_sales_collection_resources_per_year = MandatoryCollectionResourcesService.generate_resources("sales", editable_collection_resource_years) |
||||
end |
||||
end |
||||
@ -0,0 +1,5 @@
|
||||
class CollectionResource |
||||
include ActiveModel::Model |
||||
|
||||
attr_accessor :display_name, :short_display_name, :year, :log_type, :download_filename, :download_path |
||||
end |
||||
@ -0,0 +1,60 @@
|
||||
class MandatoryCollectionResourcesService |
||||
MANDATORY_RESOURCES = %w[paper_form bulk_upload_template bulk_upload_specification].freeze |
||||
|
||||
def self.generate_resources(log_type, collection_years) |
||||
mandatory_resources_per_year = {} |
||||
collection_years.map do |year| |
||||
mandatory_resources_per_year[year] = resources_per_year(year, log_type) |
||||
end |
||||
mandatory_resources_per_year |
||||
end |
||||
|
||||
def self.resources_per_year(year, log_type) |
||||
MANDATORY_RESOURCES.map do |resource| |
||||
CollectionResource.new( |
||||
display_name: display_name(resource, year, log_type), |
||||
short_display_name: resource.humanize, |
||||
year:, |
||||
log_type:, |
||||
download_filename: download_filename(resource, year, log_type), |
||||
download_path: download_path(resource, year, log_type), |
||||
) |
||||
end |
||||
end |
||||
|
||||
def self.display_name(resource, year, log_type) |
||||
year_range = "#{year} to #{year + 1}" |
||||
case resource |
||||
when "paper_form" |
||||
"#{log_type} log for tenants (#{year_range})" |
||||
when "bulk_upload_template" |
||||
"#{log_type} bulk upload template (#{year_range})" |
||||
when "bulk_upload_specification" |
||||
"#{log_type} bulk upload specification (#{year_range})" |
||||
end |
||||
end |
||||
|
||||
def self.download_path(resource, year, log_type) |
||||
year_range = "#{year % 100}_#{(year + 1) % 100}" |
||||
case resource |
||||
when "paper_form" |
||||
"download_#{year_range}_#{log_type}_form_path" |
||||
when "bulk_upload_template" |
||||
"download_#{year_range}_#{log_type}_bulk_upload_template_path" |
||||
when "bulk_upload_specification" |
||||
"download_#{year_range}_#{log_type}_bulk_upload_specification_path" |
||||
end |
||||
end |
||||
|
||||
def self.download_filename(resource, year, log_type) |
||||
year_range = "#{year}_#{(year + 1) % 100}" |
||||
case resource |
||||
when "paper_form" |
||||
"#{year_range}_#{log_type}_paper_form.pdf" |
||||
when "bulk_upload_template" |
||||
"bulk-upload-#{log_type}-template-#{year_range.dasherize}.xlsx" |
||||
when "bulk_upload_specification" |
||||
"bulk-upload-#{log_type}-specification-#{year_range.dasherize}.xlsx" |
||||
end |
||||
end |
||||
end |
||||
@ -0,0 +1,14 @@
|
||||
<%= govuk_summary_list do |summary_list| %> |
||||
<% mandatory_resources.each do |resource| %> |
||||
<% summary_list.with_row do |row| %> |
||||
<% row.with_key { resource.short_display_name } %> |
||||
<% row.with_value do %> |
||||
<%= render DocumentListComponent.new(items: document_list_edit_component_items([resource]), label: "") %> |
||||
<% end %> |
||||
<% row.with_action( |
||||
text: "Change", |
||||
href: "/", |
||||
) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
@ -0,0 +1,23 @@
|
||||
<% title = "Collection resources" %> |
||||
<% content_for :title, title %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link(href: :back) %> |
||||
<% end %> |
||||
|
||||
<h1 class="govuk-heading-l"><%= title %></h1> |
||||
|
||||
<% @mandatory_lettings_collection_resources_per_year.each do |year, mandatory_resources| %> |
||||
<h2 class="govuk-heading-m"> |
||||
Lettings <%= text_year_range_format(year) %> |
||||
</h2> |
||||
<%= render partial: "collection_resource_summary_list", locals: { mandatory_resources: } %> |
||||
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m"> |
||||
<% end %> |
||||
|
||||
<% @mandatory_sales_collection_resources_per_year.each do |year, mandatory_resources| %> |
||||
<h2 class="govuk-heading-m"> |
||||
Sales <%= text_year_range_format(year) %> |
||||
</h2> |
||||
<%= render partial: "collection_resource_summary_list", locals: { mandatory_resources: } %> |
||||
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m"> |
||||
<% end %> |
||||
@ -0,0 +1,86 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe CollectionResourcesController, type: :request do |
||||
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||
|
||||
describe "GET #index" do |
||||
context "when user is not signed in" do |
||||
it "redirects to the sign in page" do |
||||
get collection_resources_path |
||||
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 collection_resources_path |
||||
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 collection_resources_path |
||||
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 |
||||
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 1, 8)) |
||||
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||
sign_in user |
||||
get collection_resources_path |
||||
end |
||||
|
||||
it "displays collection resources" do |
||||
expect(page).to have_content("Lettings 2024 to 2025") |
||||
expect(page).to have_content("Lettings 2025 to 2026") |
||||
expect(page).to have_content("Sales 2024 to 2025") |
||||
expect(page).to have_content("Sales 2025 to 2026") |
||||
end |
||||
|
||||
it "displays mandatory filed" do |
||||
expect(page).to have_content("Paper form") |
||||
expect(page).to have_content("Bulk upload template") |
||||
expect(page).to have_content("Bulk upload specification") |
||||
end |
||||
|
||||
context "when files are on S3" do |
||||
it "displays file names with download links" do |
||||
expect(page).to have_link("2024_25_lettings_paper_form.pdf", href: download_24_25_lettings_form_path) |
||||
expect(page).to have_link("bulk-upload-lettings-template-2024-25.xlsx", href: download_24_25_lettings_bulk_upload_template_path) |
||||
expect(page).to have_link("bulk-upload-lettings-specification-2024-25.xlsx", href: download_24_25_lettings_bulk_upload_specification_path) |
||||
expect(page).to have_link("2024_25_sales_paper_form.pdf", href: download_24_25_sales_form_path) |
||||
expect(page).to have_link("bulk-upload-sales-template-2024-25.xlsx", href: download_24_25_sales_bulk_upload_template_path) |
||||
expect(page).to have_link("bulk-upload-sales-specification-2024-25.xlsx", href: download_24_25_sales_bulk_upload_specification_path) |
||||
|
||||
expect(page).to have_link("2025_26_lettings_paper_form.pdf", href: download_25_26_lettings_form_path) |
||||
expect(page).to have_link("bulk-upload-lettings-template-2025-26.xlsx", href: download_25_26_lettings_bulk_upload_template_path) |
||||
expect(page).to have_link("bulk-upload-lettings-specification-2025-26.xlsx", href: download_25_26_lettings_bulk_upload_specification_path) |
||||
expect(page).to have_link("2025_26_sales_paper_form.pdf", href: download_25_26_sales_form_path) |
||||
expect(page).to have_link("bulk-upload-sales-template-2025-26.xlsx", href: download_25_26_sales_bulk_upload_template_path) |
||||
expect(page).to have_link("bulk-upload-sales-specification-2025-26.xlsx", href: download_25_26_sales_bulk_upload_specification_path) |
||||
end |
||||
|
||||
it "displays change links" do |
||||
expect(page).to have_selector(:link_or_button, "Change", count: 12) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
Loading…
Reference in new issue