14 changed files with 295 additions and 130 deletions
@ -1,5 +1,10 @@ |
|||||||
class CollectionResource |
class CollectionResource |
||||||
include ActiveModel::Model |
include ActiveModel::Model |
||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
attr_accessor :display_name, :short_display_name, :year, :log_type, :download_filename, :download_path |
attr_accessor :resource_type, :display_name, :short_display_name, :year, :log_type, :download_filename |
||||||
|
|
||||||
|
def download_path |
||||||
|
download_mandatory_collection_resource_path(log_type:, year:, resource_type:) |
||||||
|
end |
||||||
end |
end |
||||||
|
|||||||
@ -0,0 +1,10 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :collection_resource, class: "CollectionResource" do |
||||||
|
resource_type { "paper_form" } |
||||||
|
display_name { "lettings log for tenants (2021 to 2022)" } |
||||||
|
short_display_name { "Paper Form" } |
||||||
|
year { 2024 } |
||||||
|
log_type { "lettings" } |
||||||
|
download_filename { "24_25_lettings_paper_form.pdf" } |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
describe MandatoryCollectionResourcesService do |
||||||
|
let(:service) { described_class } |
||||||
|
|
||||||
|
describe "#generate_resource" do |
||||||
|
it "returns a CollectionResource object" do |
||||||
|
resource = service.generate_resource("lettings", 2024, "paper_form") |
||||||
|
expect(resource).to be_a(CollectionResource) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns nil if resource type is not in the MANDATORY_RESOURCES list" do |
||||||
|
resource = service.generate_resource("lettings", 2024, "invalid_resource") |
||||||
|
expect(resource).to be_nil |
||||||
|
end |
||||||
|
|
||||||
|
it "returns a CollectionResource object with the correct attributes" do |
||||||
|
resource = service.generate_resource("lettings", 2024, "paper_form") |
||||||
|
expect(resource.resource_type).to eq("paper_form") |
||||||
|
expect(resource.display_name).to eq("lettings log for tenants (2024 to 2025)") |
||||||
|
expect(resource.short_display_name).to eq("Paper form") |
||||||
|
expect(resource.year).to eq(2024) |
||||||
|
expect(resource.log_type).to eq("lettings") |
||||||
|
expect(resource.download_filename).to eq("2024_25_lettings_paper_form.pdf") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#generate_resources" do |
||||||
|
it "generates all mandatory resources for given years" do |
||||||
|
resources = service.generate_resources("lettings", [2024, 2025]) |
||||||
|
expect(resources[2024].map(&:resource_type)).to eq(%w[paper_form bulk_upload_template bulk_upload_specification]) |
||||||
|
expect(resources[2025].map(&:resource_type)).to eq(%w[paper_form bulk_upload_template bulk_upload_specification]) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#resources_per_year" do |
||||||
|
it "generates all mandatory resources for a specific year" do |
||||||
|
resources = service.resources_per_year(2024, "lettings") |
||||||
|
expect(resources.map(&:resource_type)).to eq(%w[paper_form bulk_upload_template bulk_upload_specification]) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
Loading…
Reference in new issue