Skip to content

Commit

Permalink
fix count_quantity_spec.rb, duplicate_spec.rb, product_spec.rb, purch…
Browse files Browse the repository at this point in the history
…ase_product_spec.rb, stock_spec.rb, update_status_spec.rb: #7

skip after create Product since it will get request stocks. We are not testing the integration in models level for some cases.
  • Loading branch information
Pauloparakleto committed Dec 22, 2023
1 parent 65b4b31 commit f81a336
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
31 changes: 11 additions & 20 deletions spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
end

describe '#count_month_purchase_product' do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it 'returns the sum of quantities for purchase products in the given month' do
year = Time.zone.now.year
month = Time.zone.now.month
Expand All @@ -135,18 +137,19 @@
end

describe '#datatable_filter' do
let(:search_value) { 'Widget' }
let(:search_columns) { { '1' => { 'searchable' => true } } }
let(:product_1) { create(:product, name: 'Widget') }
let(:product_2) { create(:product, name: 'Gadget') }
let!(:products) { [product_1, product_2] }
let(:products) { [product_1, product_2] }

before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it 'returns products matching the given search value for the given search columns' do
result = Product.datatable_filter(search_value, search_columns)
result = Product.datatable_filter('Widget', search_columns)
expect(result).to contain_exactly(product_1)
end

xit 'returns all products if the search value is blank' do
it 'returns all products if the search value is blank' do
result = Product.datatable_filter('', search_columns)
expect(result).to contain_exactly(*products)
end
Expand All @@ -155,6 +158,8 @@
describe '#count_month_sale_product' do
let(:account) { create(:account) }

before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it 'returns the sum of quantities for sale products in the given month' do
year = Time.zone.now.year
month = Time.zone.now.month
Expand All @@ -174,6 +179,8 @@
# end

context 'when create' do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it 'is valid' do
expect(product).to be_valid
end
Expand All @@ -194,20 +201,4 @@
expect(product.image).not_to be_nil
end
end

context 'when update' do
let(:product) { create(:product) }

it 'is valid' do
expect(product).to be_valid
end
end

context 'when destroy' do
let(:product) { create(:product) }

it 'is valid' do
expect(product).to be_valid
end
end
end
2 changes: 2 additions & 0 deletions spec/models/purchase_product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
require 'rails_helper'

RSpec.describe PurchaseProduct, type: :model do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it { is_expected.to belong_to(:product) }

context 'when create' do
Expand Down
8 changes: 2 additions & 6 deletions spec/models/services/product/count_quantity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rails_helper'

RSpec.describe Services::Product::CountQuantity, type: :services do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

context 'when call the service' do
let(:product) { create(:product) }
let(:purchase_product) { create(:purchase_product, product_id: product.id) }
Expand All @@ -12,11 +14,5 @@
result = described_class.call(product: product, product_command: 'purchase_product')
expect(purchase_product.quantity).to eq(result.to_i)
end

xit 'verify count sale product' do
end

xit 'verify balance product' do
end
end
end
2 changes: 2 additions & 0 deletions spec/models/services/product/duplicate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rails_helper'

RSpec.describe Services::Product::Duplicate, type: :services do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

context 'when call the service' do
let(:product) { create(:product) }

Expand Down
2 changes: 2 additions & 0 deletions spec/models/services/product/update_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rails_helper'

RSpec.describe Services::Product::UpdateStatus, type: :services do
before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

context 'when call the service' do
let(:product) { create(:product) }

Expand Down
9 changes: 7 additions & 2 deletions spec/models/stock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
end

describe '#save' do
let!(:product) { FactoryBot.create(:product) }
let(:product) { FactoryBot.create(:product) }

before { allow_any_instance_of(Product).to receive(:create_stock).and_return(true) }

it 'is true' do
stock = described_class.new
Expand All @@ -47,7 +49,10 @@
let(:product_ids) { [bling_product_id] }

include_context 'with bling token'
before { FactoryBot.create(:product, bling_id: bling_product_id, account_id: user.account.id) }
before do
allow_any_instance_of(Product).to receive(:create_stock).and_return(true)
FactoryBot.create(:product, bling_id: bling_product_id, account_id: user.account.id)
end

context 'with products' do
it 'creates stock' do
Expand Down

0 comments on commit f81a336

Please sign in to comment.