add withdrawl and deposit to FiatBalance and Balance
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: admin_users
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email :string default(""), not null
|
||||
# encrypted_password :string default(""), not null
|
||||
# remember_created_at :datetime
|
||||
# reset_password_sent_at :datetime
|
||||
# reset_password_token :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_admin_users_on_email (email) UNIQUE
|
||||
# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE
|
||||
#
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe(AdminUser, type: :model) do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -32,4 +32,32 @@ RSpec.describe(Balance, type: :model) do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
it { is_expected.to(belong_to(:currency)) }
|
||||
end
|
||||
|
||||
describe ".withdrwal!" do
|
||||
context "when value is greater than the balance" do
|
||||
it "raise ActiveRecord::RecordInvalid" do
|
||||
balance = build(:balance, amount: 70.342)
|
||||
|
||||
expect { balance.withdrawal!(80) }.to(
|
||||
raise_error(ActiveRecord::RecordInvalid, "A validação falhou: Quantia saldo insuficiente")
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when value is equals to the balance" do
|
||||
it "returns true" do
|
||||
balance = build(:balance, amount: 70.342)
|
||||
|
||||
expect(balance.withdrawal!(70.342)).to(eq(true))
|
||||
end
|
||||
end
|
||||
|
||||
context "when value is smaller than the balance" do
|
||||
it "returns true" do
|
||||
balance = build(:balance, amount: 70.342)
|
||||
|
||||
expect(balance.withdrawal!(20)).to(eq(true))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,4 +25,32 @@ RSpec.describe(FiatBalance, type: :model) do
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
end
|
||||
|
||||
describe ".withdrwal!" do
|
||||
context "when value is greater than the balance" do
|
||||
it "raise ActiveRecord::RecordInvalid" do
|
||||
balance = build(:fiat_balance, amount_cents: 100_00)
|
||||
|
||||
expect { balance.withdrawal!(100_50) }.to(
|
||||
raise_error(ActiveRecord::RecordInvalid, "A validação falhou: Quantia saldo insuficiente")
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when value is equals to the balance" do
|
||||
it "returns true" do
|
||||
balance = build(:fiat_balance, amount_cents: 100_00)
|
||||
|
||||
expect(balance.withdrawal!(100_00)).to(eq(true))
|
||||
end
|
||||
end
|
||||
|
||||
context "when value is smaller than the balance" do
|
||||
it "returns true" do
|
||||
balance = build(:fiat_balance, amount_cents: 100_00)
|
||||
|
||||
expect(balance.withdrawal!(90_00)).to(eq(true))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user