remove currency model and all references
This commit is contained in:
@@ -4,27 +4,23 @@
|
||||
#
|
||||
# Table name: balances
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_balances_on_currency_id (currency_id)
|
||||
# index_balances_on_user_id (user_id)
|
||||
# index_balances_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :balance do
|
||||
association :user
|
||||
association :currency
|
||||
amount { (rand * (10000 - 0) + 0) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,23 +10,19 @@
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_buy_crypto_orders_on_currency_id (currency_id)
|
||||
# index_buy_crypto_orders_on_user_id (user_id)
|
||||
# index_buy_crypto_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :buy_crypto_order do
|
||||
association :user
|
||||
association :currency
|
||||
status { :processing }
|
||||
paid_amount_cents { rand(10000) }
|
||||
received_amount { rand * 10000 }
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: currencies
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :currency do
|
||||
name { "CAKE" }
|
||||
end
|
||||
end
|
||||
@@ -10,23 +10,19 @@
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_sell_crypto_orders_on_currency_id (currency_id)
|
||||
# index_sell_crypto_orders_on_user_id (user_id)
|
||||
# index_sell_crypto_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
factory :sell_crypto_order do
|
||||
association :user
|
||||
association :currency
|
||||
status { :processing }
|
||||
received_amount_cents { rand(10000) }
|
||||
paid_amount { rand * 10000 }
|
||||
|
||||
@@ -4,23 +4,20 @@
|
||||
#
|
||||
# Table name: stake_orders
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# pool_name :string not null
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint
|
||||
# user_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# pool_name :string not null
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_stake_orders_on_currency_id (currency_id)
|
||||
# index_stake_orders_on_user_id (user_id)
|
||||
# index_stake_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
FactoryBot.define do
|
||||
|
||||
@@ -6,7 +6,6 @@ describe Inputs::CreateBuyCryptoOrderAttributesInput do
|
||||
subject { described_class }
|
||||
|
||||
describe "fields" do
|
||||
it { is_expected.to(accept_argument("currency_id").of_type("ID!")) }
|
||||
it { is_expected.to(accept_argument("amount_cents").of_type("Int!")) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,6 @@ describe Inputs::CreateSellCryptoOrderAttributesInput do
|
||||
subject { described_class }
|
||||
|
||||
describe "fields" do
|
||||
it { is_expected.to(accept_argument("currency_id").of_type("ID!")) }
|
||||
it { is_expected.to(accept_argument("amount").of_type("String!")) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,10 +5,9 @@ require "rails_helper"
|
||||
RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
let(:query_string) do
|
||||
<<~GQL
|
||||
mutation($currencyId: ID!, $amountCents: Int!) {
|
||||
mutation($amountCents: Int!) {
|
||||
createBuyCryptoOrder(input: {
|
||||
order: {
|
||||
currencyId: $currencyId,
|
||||
amountCents: $amountCents,
|
||||
}
|
||||
}) {
|
||||
@@ -22,9 +21,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
status
|
||||
paidAmountCents
|
||||
receivedAmount
|
||||
currency {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +29,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
|
||||
context "when the user has enough balance" do
|
||||
it "withdraws from his account and creates a buy order" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
fiat_balance: build(
|
||||
@@ -42,10 +37,7 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
),
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amountCents": 90_00,
|
||||
}
|
||||
|
||||
@@ -65,9 +57,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
"status" => "PROCESSING",
|
||||
"paidAmountCents" => 90_00,
|
||||
"receivedAmount" => "0.0",
|
||||
"currency" => {
|
||||
"name" => "CAKE",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -79,7 +68,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
|
||||
context "when the user does not have enough balance" do
|
||||
it "returns withdrawl error" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
fiat_balance: build(
|
||||
@@ -88,10 +76,7 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do
|
||||
),
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amountCents": 90_00,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@ require "rails_helper"
|
||||
RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do
|
||||
let(:query_string) do
|
||||
<<~GQL
|
||||
mutation($currencyId: ID!, $amount: String!) {
|
||||
mutation($amount: String!) {
|
||||
createSellCryptoOrder(input: {
|
||||
order: {
|
||||
currencyId: $currencyId,
|
||||
amount: $amount,
|
||||
}
|
||||
}) {
|
||||
@@ -22,9 +21,6 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do
|
||||
status
|
||||
paidAmount
|
||||
receivedAmountCents
|
||||
currency {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,18 +29,12 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do
|
||||
|
||||
context "when the user has enough balance" do
|
||||
it "withdraws from his account and creates a buy order" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 1.0034),
|
||||
]
|
||||
balance: build(:balance, amount: 1.0034)
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "0.80",
|
||||
}
|
||||
|
||||
@@ -64,32 +54,23 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do
|
||||
"status" => "PROCESSING",
|
||||
"paidAmount" => "0.8",
|
||||
"receivedAmountCents" => 0,
|
||||
"currency" => {
|
||||
"name" => "CAKE",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
expect(user.balances.first.reload.amount.to_s).to(eq("0.2034"))
|
||||
expect(user.balance.reload.amount.to_s).to(eq("0.2034"))
|
||||
end
|
||||
end
|
||||
|
||||
context "when the user does not have enough balance" do
|
||||
it "returns withdrawl error" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 0.0034),
|
||||
]
|
||||
balance: build(:balance, amount: 0.0034)
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "0.80",
|
||||
}
|
||||
|
||||
@@ -115,7 +96,7 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do
|
||||
},
|
||||
}))
|
||||
|
||||
expect(user.balances.first.reload.amount.to_s).to(eq("0.0034"))
|
||||
expect(user.balance.reload.amount.to_s).to(eq("0.0034"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,12 +33,9 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
|
||||
context "when the user has enough balance" do
|
||||
it "withdraws from his account and creates a buy order" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 1.0034),
|
||||
]
|
||||
balance: build(:balance, amount: 1.0034)
|
||||
)
|
||||
|
||||
variables = {
|
||||
@@ -68,18 +65,15 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
},
|
||||
}))
|
||||
|
||||
expect(user.balances.first.reload.amount.to_s).to(eq("0.2034"))
|
||||
expect(user.balance.reload.amount.to_s).to(eq("0.2034"))
|
||||
end
|
||||
end
|
||||
|
||||
context "when the user does not have enough balance" do
|
||||
it "returns withdrawl error" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 0.0034),
|
||||
]
|
||||
balance: build(:balance, amount: 0.0034)
|
||||
)
|
||||
|
||||
variables = {
|
||||
@@ -109,7 +103,7 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
},
|
||||
}))
|
||||
|
||||
expect(user.balances.first.reload.amount.to_s).to(eq("0.0034"))
|
||||
expect(user.balance.reload.amount.to_s).to(eq("0.0034"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,12 +33,9 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do
|
||||
|
||||
context "when the user has enough balance" do
|
||||
it "withdraws from his account and creates a buy order" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 0),
|
||||
]
|
||||
balance: build(:balance, amount: 0)
|
||||
)
|
||||
|
||||
variables = {
|
||||
@@ -72,15 +69,12 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do
|
||||
|
||||
context "when it repeats the mutation with a request in `processing`" do
|
||||
it "update amount from the order" do
|
||||
currency = create(:currency)
|
||||
user = create(
|
||||
:user,
|
||||
balances: [
|
||||
build(:balance, currency: currency, amount: 0),
|
||||
]
|
||||
balance: build(:balance, amount: 0)
|
||||
)
|
||||
|
||||
create(:stake_order, amount: -200.8, user: user, pool_name: "CAKE/BNB", currency: currency)
|
||||
create(:stake_order, amount: -200.8, user: user, pool_name: "CAKE/BNB")
|
||||
|
||||
variables = {
|
||||
"amount": "200.80",
|
||||
|
||||
@@ -6,7 +6,6 @@ RSpec.describe(Types::BuyCryptoOrderType) do
|
||||
|
||||
describe "arguments" do
|
||||
it { is_expected.to(have_a_field(:id).of_type("ID!")) }
|
||||
it { is_expected.to(have_a_field(:currency).of_type("Currency!")) }
|
||||
it { is_expected.to(have_a_field(:paid_amount_cents).of_type("Int!")) }
|
||||
it { is_expected.to(have_a_field(:received_amount).of_type("String")) }
|
||||
it { is_expected.to(have_a_field(:status).of_type("ProcessStatus!")) }
|
||||
|
||||
@@ -6,7 +6,6 @@ RSpec.describe(Types::SellCryptoOrderType) do
|
||||
|
||||
describe "arguments" do
|
||||
it { is_expected.to(have_a_field(:id).of_type("ID!")) }
|
||||
it { is_expected.to(have_a_field(:currency).of_type("Currency!")) }
|
||||
it { is_expected.to(have_a_field(:paid_amount).of_type("String!")) }
|
||||
it { is_expected.to(have_a_field(:received_amount_cents).of_type("Int")) }
|
||||
it { is_expected.to(have_a_field(:status).of_type("ProcessStatus!")) }
|
||||
|
||||
@@ -4,21 +4,18 @@
|
||||
#
|
||||
# Table name: balances
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_balances_on_currency_id (currency_id)
|
||||
# index_balances_on_user_id (user_id)
|
||||
# index_balances_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
require "rails_helper"
|
||||
@@ -30,7 +27,6 @@ RSpec.describe(Balance, type: :model) do
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
it { is_expected.to(belong_to(:currency)) }
|
||||
end
|
||||
|
||||
describe ".withdrwal!" do
|
||||
|
||||
@@ -10,17 +10,14 @@
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_buy_crypto_orders_on_currency_id (currency_id)
|
||||
# index_buy_crypto_orders_on_user_id (user_id)
|
||||
# index_buy_crypto_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
require "rails_helper"
|
||||
@@ -51,6 +48,5 @@ RSpec.describe(BuyCryptoOrder, type: :model) do
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
it { is_expected.to(belong_to(:currency)) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: currencies
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe(Currency, type: :model) do
|
||||
describe "validations" do
|
||||
it { is_expected.to(validate_presence_of(:name)) }
|
||||
end
|
||||
end
|
||||
@@ -10,17 +10,14 @@
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_sell_crypto_orders_on_currency_id (currency_id)
|
||||
# index_sell_crypto_orders_on_user_id (user_id)
|
||||
# index_sell_crypto_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
require "rails_helper"
|
||||
@@ -51,6 +48,5 @@ RSpec.describe(SellCryptoOrder, type: :model) do
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
it { is_expected.to(belong_to(:currency)) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,23 +4,20 @@
|
||||
#
|
||||
# Table name: stake_orders
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# pool_name :string not null
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# currency_id :bigint
|
||||
# user_id :bigint not null
|
||||
# id :bigint not null, primary key
|
||||
# amount :decimal(20, 10) default(0.0), not null
|
||||
# pool_name :string not null
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_stake_orders_on_currency_id (currency_id)
|
||||
# index_stake_orders_on_user_id (user_id)
|
||||
# index_stake_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (currency_id => currencies.id)
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
require "rails_helper"
|
||||
@@ -33,6 +30,5 @@ RSpec.describe(StakeOrder, type: :model) do
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to(belong_to(:user)) }
|
||||
it { is_expected.to(belong_to(:currency)) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ RSpec.describe(User, type: :model) do
|
||||
describe "associations" do
|
||||
it { is_expected.to(have_many(:documents)) }
|
||||
it { is_expected.to(have_many(:stake_orders)) }
|
||||
it { is_expected.to(have_many(:balances)) }
|
||||
it { is_expected.to(have_one(:balance)) }
|
||||
it { is_expected.to(have_one(:fiat_balance)) }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user