Skip to content
Merged
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: 1 addition & 1 deletion app/operations/event_procedures/total_amount_cents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions app/operations/medical_shifts/total_amount_cents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/operations/event_procedures/total_amount_cents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/operations/medical_shifts/total_amount_cents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/requests/api/v1/event_procedures_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/requests/api/v1/medical_shifts_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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: []
}
)
Expand Down