Add BillSignature Service
This commit is contained in:
parent
f355f849a6
commit
ad3553f0be
2 changed files with 53 additions and 0 deletions
16
app/services/bill_signature_service.rb
Normal file
16
app/services/bill_signature_service.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class BillSignatureService
|
||||
def self.grouped_unsigned_operation_until(date)
|
||||
unsigned_operations = DossierOperationLog
|
||||
.where(bill_signature: nil)
|
||||
.where('executed_at < ?', date)
|
||||
|
||||
unsigned_operations.group_by { |e| e.executed_at.to_date }
|
||||
end
|
||||
|
||||
def self.sign_operations(operations, day)
|
||||
bill = BillSignature.build_with_operations(operations, day)
|
||||
signature = Universign::API.timestamp(bill.digest)
|
||||
bill.set_signature(signature, day)
|
||||
bill.save!
|
||||
end
|
||||
end
|
37
spec/services/bill_signature_service_spec.rb
Normal file
37
spec/services/bill_signature_service_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe BillSignatureService do
|
||||
describe ".grouped_unsigned_operation_until" do
|
||||
subject { BillSignatureService.grouped_unsigned_operation_until(date).length }
|
||||
|
||||
let(:date) { Date.today }
|
||||
|
||||
context "when operations of several days need to be signed" do
|
||||
before do
|
||||
create :dossier_operation_log, executed_at: 3.days.ago
|
||||
create :dossier_operation_log, executed_at: 2.days.ago
|
||||
create :dossier_operation_log, executed_at: 1.day.ago
|
||||
end
|
||||
|
||||
it { is_expected.to eq 3 }
|
||||
end
|
||||
|
||||
context "when operations on a single day need to be signed" do
|
||||
before do
|
||||
create :dossier_operation_log, executed_at: 1.day.ago
|
||||
create :dossier_operation_log, executed_at: 1.day.ago
|
||||
end
|
||||
|
||||
it { is_expected.to eq 1 }
|
||||
end
|
||||
|
||||
context "when there are no operations to be signed" do
|
||||
before do
|
||||
create :dossier_operation_log, created_at: 1.day.ago, bill_signature: build(:bill_signature)
|
||||
create :dossier_operation_log, created_at: 1.day.from_now
|
||||
end
|
||||
|
||||
it { is_expected.to eq 0 }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue