diff --git a/app/operations/event_procedures/total_amount_cents.rb b/app/operations/event_procedures/total_amount_cents.rb index 4457212..6fc194d 100644 --- a/app/operations/event_procedures/total_amount_cents.rb +++ b/app/operations/event_procedures/total_amount_cents.rb @@ -15,7 +15,7 @@ def call end def convert_money(amount_cents) - Money.new(amount_cents, "BRL").format + Money.new(amount_cents, "BRL").format(thousands_separator: ".", decimal_mark: ",") end def calculate_amount(filtered_event_procedures) diff --git a/app/operations/medical_shifts/total_amount_cents.rb b/app/operations/medical_shifts/total_amount_cents.rb index eead48c..0772ce9 100644 --- a/app/operations/medical_shifts/total_amount_cents.rb +++ b/app/operations/medical_shifts/total_amount_cents.rb @@ -9,9 +9,15 @@ class TotalAmountCents < Actor output :unpaid, type: String def call - self.total = Money.new(medical_shifts.sum(&:amount_cents), "BRL").format - self.paid = Money.new(medical_shifts.select(&:paid).sum(&:amount_cents), "BRL").format - self.unpaid = Money.new(medical_shifts.reject(&:paid).sum(&:amount_cents), "BRL").format + self.total = formatted_amount(medical_shifts.sum(&:amount_cents)) + self.paid = formatted_amount(medical_shifts.select(&:paid).sum(&:amount_cents)) + self.unpaid = formatted_amount(medical_shifts.reject(&:paid).sum(&:amount_cents)) + end + + private + + def formatted_amount(value) + Money.new(value, "BRL").format(thousands_separator: ".", decimal_mark: ",") end end end diff --git a/spec/operations/event_procedures/total_amount_cents_spec.rb b/spec/operations/event_procedures/total_amount_cents_spec.rb index d5ba170..11f4c40 100644 --- a/spec/operations/event_procedures/total_amount_cents_spec.rb +++ b/spec/operations/event_procedures/total_amount_cents_spec.rb @@ -33,9 +33,9 @@ event_procedures = paid_event_procedures + unpaid_event_procedures total_amount_cents = described_class.call(event_procedures: event_procedures) - expect(total_amount_cents.total).to eq("R$190.00") - expect(total_amount_cents.paid).to eq("R$150.00") - expect(total_amount_cents.unpaid).to eq("R$40.00") + expect(total_amount_cents.total).to eq("R$190,00") + expect(total_amount_cents.paid).to eq("R$150,00") + expect(total_amount_cents.unpaid).to eq("R$40,00") end end end diff --git a/spec/operations/medical_shifts/total_amount_cents_spec.rb b/spec/operations/medical_shifts/total_amount_cents_spec.rb index 96a7a54..986481f 100644 --- a/spec/operations/medical_shifts/total_amount_cents_spec.rb +++ b/spec/operations/medical_shifts/total_amount_cents_spec.rb @@ -29,9 +29,9 @@ ] ) - expect(result.total).to eq("R$45.00") - expect(result.paid).to eq("R$30.00") - expect(result.unpaid).to eq("R$15.00") + expect(result.total).to eq("R$45,00") + expect(result.paid).to eq("R$30,00") + expect(result.unpaid).to eq("R$15,00") end end end diff --git a/spec/requests/api/v1/event_procedures_request_spec.rb b/spec/requests/api/v1/event_procedures_request_spec.rb index c5d58e5..6571818 100644 --- a/spec/requests/api/v1/event_procedures_request_spec.rb +++ b/spec/requests/api/v1/event_procedures_request_spec.rb @@ -131,7 +131,7 @@ end it "returns total values without consider page and per_page params" do - expect(response.parsed_body["total"]).to eq("R$400.00") + expect(response.parsed_body["total"]).to eq("R$400,00") end end end diff --git a/spec/requests/api/v1/medical_shifts_request_spec.rb b/spec/requests/api/v1/medical_shifts_request_spec.rb index 7aaf04d..4857f94 100644 --- a/spec/requests/api/v1/medical_shifts_request_spec.rb +++ b/spec/requests/api/v1/medical_shifts_request_spec.rb @@ -93,9 +93,9 @@ get path, params: { month: "2" }, headers: headers - expect(response.parsed_body["total"]).to eq("R$30.00") - expect(response.parsed_body["total_paid"]).to eq("R$10.00") - expect(response.parsed_body["total_unpaid"]).to eq("R$20.00") + expect(response.parsed_body["total"]).to eq("R$30,00") + expect(response.parsed_body["total_paid"]).to eq("R$10,00") + expect(response.parsed_body["total_unpaid"]).to eq("R$20,00") end end @@ -207,9 +207,9 @@ expect(response.parsed_body.symbolize_keys).to eq( { - total: "R$0.00", - total_paid: "R$0.00", - total_unpaid: "R$0.00", + total: "R$0,00", + total_paid: "R$0,00", + total_unpaid: "R$0,00", medical_shifts: [] } )