Skip to content

Commit

Permalink
Merge pull request #71 from Purple-Stock/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Pauloparakleto authored Jan 12, 2024
2 parents 74566c2 + 9f9b932 commit f69fab7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/jobs/bling_order_job_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def perform(record, account_id)
result = Services::Bling::FindOrder.call(id: record.bling_order_id, order_command: 'find_order', tenant: account_id)
raise StandardError if result['error'].present?

record.update({ value: result['data']['total'], situation_id: result['data']['situacao']['id'] })
record.situation_id = result['data']['situacao']['id']
record.value = result['data']['total']
record.alteration_date = Time.zone.today
return unless record.situation_id_changed?

record.save!
end
end
9 changes: 7 additions & 2 deletions app/models/bling_order_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ def self.group_order_items(base_query)
def self.update_yourself(self_collection)
account_id = self_collection.first.account_id

self_collection.each do |record|
BlingOrderJobUpdater.perform_later(record, account_id)
self_collection.find_in_batches(batch_size: 100) do |sub_collection|
GoodJob::Bulk.enqueue do
sub_collection.each do |record|
BlingOrderJobUpdater.perform_later(record, account_id)
end
end
sleep 10 if Rails.env.eql?('production') || Rails.env.eql?('staging')
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/models/bling_order_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@
expect(collection.first.reload.value.to_f).to eq(69.9)
end
end

it 'updates status situation' do
VCR.use_cassette('find_checked_order', erb: true) do
described_class.update_yourself(collection)
expect(collection.first.reload.situation_id.to_i).to eq(BlingOrderItem::Status::IN_PROGRESS)
end
end

it 'updates alteration date' do
VCR.use_cassette('find_checked_order', erb: true) do
described_class.update_yourself(collection)
expect(collection.first.reload.alteration_date.strftime('%Y-%m-%d')).to eq(Time.zone.today.strftime)
end
end
end

context 'when there are too many requests error in the response' do
Expand Down

0 comments on commit f69fab7

Please sign in to comment.