Skip to content

Commit

Permalink
Merge pull request #213 from felixefelip/product-specs
Browse files Browse the repository at this point in the history
test: #count_month_sale_product
  • Loading branch information
puppe1990 authored Jul 24, 2023
2 parents 05816b3 + c320c20 commit c7e17f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions spec/factories/sale_product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
value { Faker::Commerce.price }
created_at { Faker::Time.between(from: DateTime.now - 1, to: DateTime.now) }
updated_at { Faker::Time.between(from: DateTime.now - 1, to: DateTime.now) }
account_id { Faker::Number.between(1, 100) }
product_id { Faker::Number.between(1, 100) }
sale_id { create(:sale).id }
account
product
sale
end
end
end
21 changes: 12 additions & 9 deletions spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@
end
end

# describe '#count_month_sale_product' do
# it 'returns the sum of quantities for sale products in the given month' do
# year = Time.zone.now.year
# month = Time.zone.now.month
# create(:sale_product, product: product, quantity: 5, created_at: Time.zone.local(year, month, 15))
# create(:sale_product, product: product, quantity: 3, created_at: Time.zone.local(year, month, 20))
# expect(product.count_month_sale_product(year, month)).to eq(8)
# end
# end
describe '#count_month_sale_product' do
let(:account) { create(:account) }

it 'returns the sum of quantities for sale products in the given month' do
year = Time.zone.now.year
month = Time.zone.now.month
create(:sale_product, product:, account:, quantity: 5, created_at: Time.zone.local(year, month, 15))
create(:sale_product, product:, account:, quantity: 3, created_at: Time.zone.local(year, month, 20))

expect(product.count_month_sale_product(year, month)).to eq(8)
end
end

# describe '#sum_simplo_items' do
# it 'returns the sum of quantities for simplo items' do
Expand Down

0 comments on commit c7e17f0

Please sign in to comment.