From c39e324a553ea9f126186a4bfdfe38ce3b8cb8c8 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 15 Oct 2024 16:54:12 +0200 Subject: [PATCH 1/3] add possibility to record credit_note_id when voiding credits --- app/services/wallet_transactions/void_service.rb | 8 +++++--- .../wallet_transactions/void_service_spec.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/services/wallet_transactions/void_service.rb b/app/services/wallet_transactions/void_service.rb index 2a31d4c7dcd..1d7ada13263 100644 --- a/app/services/wallet_transactions/void_service.rb +++ b/app/services/wallet_transactions/void_service.rb @@ -2,11 +2,12 @@ module WalletTransactions class VoidService < BaseService - def initialize(wallet:, credits_amount:, from_source: :manual, metadata: {}) + def initialize(wallet:, credits_amount:, from_source: :manual, metadata: {}, credit_note_id: nil) @wallet = wallet @credits_amount = credits_amount @from_source = from_source @metadata = metadata + @credit_note_id = credit_note_id super end @@ -23,7 +24,8 @@ def call settled_at: Time.current, source: from_source, transaction_status: :voided, - metadata: + metadata:, + credit_note_id: ) Wallets::Balance::DecreaseService.new(wallet:, credits_amount:).call result.wallet_transaction = wallet_transaction @@ -34,6 +36,6 @@ def call private - attr_reader :wallet, :credits_amount, :from_source, :metadata + attr_reader :wallet, :credits_amount, :from_source, :metadata, :credit_note_id end end diff --git a/spec/services/wallet_transactions/void_service_spec.rb b/spec/services/wallet_transactions/void_service_spec.rb index 641a1031dcd..da7439fc24b 100644 --- a/spec/services/wallet_transactions/void_service_spec.rb +++ b/spec/services/wallet_transactions/void_service_spec.rb @@ -78,5 +78,17 @@ expect(wallet.balance_cents).to eq(0) expect(wallet.credits_balance).to eq(0.0) end + + context 'when credit_note_id is passed' do + let(:credit_note_id) { create(:credit_note, organization: organization).id } + subject(:void_service) { described_class.call(wallet:, credits:, credit_note_id:) } + + it 'saves credit_note_id in wallet_transaction' do + result = void_service + wallet_transaction = result.wallet_transaction + + expect(wallet_transaction.credit_note_id).to eq(credit_note_id) + end + end end end From c2242f1a0026fd0da17185e04225c0805d6948ab Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 15 Oct 2024 17:31:32 +0200 Subject: [PATCH 2/3] fix-linter --- spec/services/wallet_transactions/void_service_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/services/wallet_transactions/void_service_spec.rb b/spec/services/wallet_transactions/void_service_spec.rb index da7439fc24b..fd1af6fd22c 100644 --- a/spec/services/wallet_transactions/void_service_spec.rb +++ b/spec/services/wallet_transactions/void_service_spec.rb @@ -80,9 +80,10 @@ end context 'when credit_note_id is passed' do - let(:credit_note_id) { create(:credit_note, organization: organization).id } subject(:void_service) { described_class.call(wallet:, credits:, credit_note_id:) } + let(:credit_note_id) { create(:credit_note, organization: organization).id } + it 'saves credit_note_id in wallet_transaction' do result = void_service wallet_transaction = result.wallet_transaction From aebea783f5b348982f2be68443dd71cec4ab55d7 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 21 Oct 2024 12:25:26 +0200 Subject: [PATCH 3/3] update test for service as a variable has been renamed --- spec/services/wallet_transactions/void_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/wallet_transactions/void_service_spec.rb b/spec/services/wallet_transactions/void_service_spec.rb index fd1af6fd22c..acc9ebf22aa 100644 --- a/spec/services/wallet_transactions/void_service_spec.rb +++ b/spec/services/wallet_transactions/void_service_spec.rb @@ -80,7 +80,7 @@ end context 'when credit_note_id is passed' do - subject(:void_service) { described_class.call(wallet:, credits:, credit_note_id:) } + subject(:void_service) { described_class.call(wallet:, credits_amount:, credit_note_id:) } let(:credit_note_id) { create(:credit_note, organization: organization).id }