Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/serializers/v1/wallet_transaction_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def serialize
payload = {
lago_id: model.id,
lago_wallet_id: model.wallet_id,
lago_invoice_id: model.invoice_id,
lago_credit_note_id: model.credit_note_id,
status: model.status,
source: model.source,
transaction_status: model.transaction_status,
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/wallet_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@

invoice { association(:invoice, customer:, organization: customer.organization) }
end

trait :with_credit_note do
transient do
customer { association(:customer) }
end

credit_note { association(:credit_note, customer:, invoice:, organization: customer.organization) }
end
end
end
18 changes: 16 additions & 2 deletions spec/serializers/v1/wallet_transaction_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
end

let(:wallet_transaction) { create(:wallet_transaction) }
let(:includes) { [] }

context "when includes is empty" do
let(:includes) { [] }

it "serializes the object" do
result = JSON.parse(serializer.to_json)

expect(result["wallet_transaction"]).to include(
"lago_id" => wallet_transaction.id,
"lago_wallet_id" => wallet_transaction.wallet_id,
"lago_invoice_id" => nil,
"lago_credit_note_id" => nil,
"status" => wallet_transaction.status,
"source" => wallet_transaction.source,
"transaction_status" => wallet_transaction.transaction_status,
Expand All @@ -34,6 +35,19 @@
end
end

context "when transaction has an invoice and a credit note" do
let(:wallet_transaction) { create(:wallet_transaction, :with_invoice, :with_credit_note) }

it "serializes the invoice id" do
result = JSON.parse(serializer.to_json)

expect(result["wallet_transaction"]).to include(
"lago_invoice_id" => wallet_transaction.invoice.id,
"lago_credit_note_id" => wallet_transaction.credit_note.id
)
end
end

context "when includes wallet is set" do
let(:includes) { %i[wallet] }
let(:wallet) { wallet_transaction.wallet }
Expand Down
Loading