Skip to content

Commit d30f277

Browse files
Merge pull request #44 from Purple-Stock/feat/add-items-to-count
Feat/add items to count
2 parents 4dddd44 + 9cec09e commit d30f277

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

app/jobs/order_items_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class OrderItemsJob < ApplicationJob
33
retry_on StandardError, attempts: 5, wait: :exponentially_longer
44

55
def perform(record)
6+
return unless record.items.empty?
7+
68
account_id = record.account_id
79
items_attributes = []
810
order = Services::Bling::FindOrder.call(id: record.bling_order_id, order_command: 'find_order', tenant: account_id)

spec/factories/items.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# == Schema Information
2+
#
3+
# Table name: items
4+
#
5+
# id :bigint not null, primary key
6+
# description :string
7+
# discount :decimal(, )
8+
# ipi_tax :decimal(, )
9+
# long_description :string
10+
# quantity :integer
11+
# sku :string
12+
# unity :integer
13+
# value :decimal(, )
14+
# created_at :datetime not null
15+
# updated_at :datetime not null
16+
# account_id :integer
17+
# bling_order_item_id :bigint
18+
# product_id :bigint
19+
#
20+
FactoryBot.define do
21+
factory :item do
22+
sku { "MyString" }
23+
unity { 1 }
24+
quantity { 1 }
25+
discount { "9.99" }
26+
value { "9.99" }
27+
ipi_tax { "9.99" }
28+
description { "MyString" }
29+
long_description { "MyString" }
30+
product_id { 1 }
31+
account_id { 1 }
32+
end
33+
end

spec/models/bling_order_item_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@
6060
it 'has quantity 1' do
6161
expect(order.items.first.quantity).to eq(1)
6262
end
63+
64+
context 'when perform twice' do
65+
it 'still counts 1' do
66+
VCR.use_cassette('find_order', erb: true) do
67+
order.synchronize_items
68+
end
69+
70+
expect(order.items.count).to eq(1)
71+
end
72+
end
73+
74+
context 'when perform in order with different account' do
75+
let(:second_user) { FactoryBot.create(:user) }
76+
let(:second_order) do
77+
FactoryBot.create(:bling_order_item, bling_order_id: 19_449_352_383, account_id: second_user.account.id)
78+
end
79+
80+
before { FactoryBot.create(:bling_datum, account_id: second_user.account.id) }
81+
82+
it 'counts 1 item created' do
83+
84+
VCR.use_cassette('find_second_order', erb: true) do
85+
second_order.synchronize_items
86+
end
87+
88+
expect(second_order.items.count).to eq(1)
89+
end
90+
end
6391
end
6492

6593
describe '#store_name' do

spec/vcr/find_second_order.yml

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)