Skip to content

Commit

Permalink
Merge branch 'main' into feat/pfpmp-validation-constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl committed Apr 5, 2024
2 parents 467d61d + 208761a commit baf43a1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/pfmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Pfmp < ApplicationRecord
only_integer: true,
allow_nil: true,
greater_than: 0,
less_than_or_equal_to: ->(pfmp) { (pfmp.end_date - pfmp.start_date).to_i }
less_than_or_equal_to: ->(pfmp) { (pfmp.end_date - pfmp.start_date).to_i + 1 }
}

scope :finished, -> { where("pfmps.end_date <= (?)", Time.zone.today) }
Expand Down
16 changes: 8 additions & 8 deletions app/services/asp/file_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module ASP
class FileHandler
include Errors

attr_reader :filepath, :filename
attr_reader :filepath, :filename_noext

FILE_TYPES = %i[rejects integrations payments].freeze

def initialize(filepath)
@filepath = filepath
@filename = File.basename(filepath, ".*")
@filename_noext = File.basename(filepath, ".*")
end

def parse!
Expand All @@ -21,13 +21,13 @@ def parse!
begin
reader.process!
rescue StandardError => e
raise ResponseFileParsingError, "couldn't parse #{filename}: #{e}"
raise ResponseFileParsingError, "couldn't parse #{filename_noext}: #{e}"
end
end

def file_saved?
if payments_file?
ASP::PaymentReturn.exists?(filename: filename)
ASP::PaymentReturn.exists?(filename: "#{filename_noext}.xml")
else
target_attachment.attached?
end
Expand All @@ -42,7 +42,7 @@ def file_saved?
end

def kind
case filename
case filename_noext
when /^rejets_integ_idp/
:rejects
when /^identifiants_generes/
Expand All @@ -56,9 +56,9 @@ def original_filename
return if payments_file?

name = if rejects_file?
filename.split("integ_idp_").last
filename_noext.split("integ_idp_").last
elsif integrations_file?
filename.split("generes_").last
filename_noext.split("generes_").last
end

"#{name}.xml"
Expand Down Expand Up @@ -89,7 +89,7 @@ def persist_file!
end

def persist_payment_file!
ASP::PaymentReturn.create_with_file!(io: File.read(filepath), filename: "#{filename}.xml")
ASP::PaymentReturn.create_with_file!(io: File.read(filepath), filename: "#{filename_noext}.xml")
end

def attach_to_request!
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Aplypro
VERSION = "1.13"
VERSION = "1.13.1"
end
10 changes: 8 additions & 2 deletions spec/models/pfmp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
end

describe "day count" do
subject(:pfmp) { build(:pfmp, start_date: Time.zone.now, end_date: 7.days.from_now) }
subject(:pfmp) do
build(
:pfmp,
start_date: Time.zone.now.next_week(:monday),
end_date: Time.zone.now.next_week(:friday)
)
end

context "when the number of days doesn't fit in the date range" do
before { pfmp.day_count = 8 }
Expand All @@ -62,7 +68,7 @@
end

context "when the number fits exactly in the day range" do
before { pfmp.day_count = 7 }
before { pfmp.day_count = 5 }

it { is_expected.to be_valid }
end
Expand Down
11 changes: 9 additions & 2 deletions spec/services/asp/file_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@

expect(request.send("#{type}_file")).to be_attached
end

it "can tell the file was attached correctly" do
expect { reader.parse! }.to change(reader, :file_saved?).from(false).to(true)
end
end
# rubocop:enable Rspec/MultipleMemoizedHelpers

%i[rejects integrations].each do |type|
%i[integrations rejects].each do |type|
context "when the file is #{type} file" do
it_behaves_like "a reader for the ASP integration process", type
end
Expand All @@ -60,6 +64,9 @@

expect(ASP::PaymentReturn.last.filename).to eq basename
end

it "knows whether the file was saved" do
expect { reader.parse! }.to change(reader, :file_saved?).from(false).to(true)
end
end
end
# frozen_string_literal: true

0 comments on commit baf43a1

Please sign in to comment.