-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #2180: enqueue generate BIB when order completed
- Loading branch information
Showing
4 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
app/jobs/spree_cm_commissioner/order_complete_bib_generator_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module SpreeCmCommissioner | ||
class OrderCompleteBibGeneratorJob < ApplicationJob | ||
def perform(order_id) | ||
order = ::Spree::Order.find(order_id) | ||
order.generate_bib_number! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
spec/jobs/spree_cm_commissioner/order_complete_bib_generator_job_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe SpreeCmCommissioner::OrderCompleteBibGeneratorJob, type: :job do | ||
let(:order) { create(:order) } | ||
let(:order_id) { order.id } | ||
|
||
describe '#perform' do | ||
it 'finds the order by id' do | ||
expect(Spree::Order).to receive(:find).with(order_id).and_return(order) | ||
subject.perform(order_id) | ||
end | ||
|
||
it 'generates guest BIB for the order' do | ||
allow(Spree::Order).to receive(:find).with(order_id).and_return(order) | ||
|
||
expect(order).to receive(:generate_bib_number!) | ||
subject.perform(order_id) | ||
end | ||
end | ||
end |
63 changes: 63 additions & 0 deletions
63
spec/models/concerns/spree_cm_commissioner/order_bib_number_concern_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe SpreeCmCommissioner::OrderBibNumberConcern do | ||
let(:taxonomy) { create(:taxonomy, kind: :event) } | ||
let(:event1) { create(:taxon, name: 'BunPhum', taxonomy: taxonomy) } | ||
let(:product_with_bib1) { create(:cm_bib_number_product, product_type: :ecommerce, taxons: [event1]) } | ||
let(:order) { create(:order, completed_at: nil) } | ||
|
||
let(:line_item) { create(:line_item, order: order, variant: product_with_bib1.variants.first) } | ||
let(:line_items) { [line_item] } | ||
let(:guest) { create(:guest, line_item: line_item, seat_number: 1) } | ||
let(:guests) { [guest] } | ||
|
||
describe 'callbacks' do | ||
it 'calls generate_guests_and_bib_numbers after update if state is complete' do | ||
expect(order).to receive(:generate_guests_and_bib_numbers) | ||
order.update(state: 'complete') | ||
end | ||
end | ||
|
||
describe '#generate_guests_and_bib_numbers' do | ||
it 'calls generate_remaining_guests' do | ||
expect(order).to receive(:generate_remaining_guests) | ||
order.send(:generate_guests_and_bib_numbers) | ||
end | ||
|
||
it 'calls generate_bib_number_aysnc' do | ||
expect(order).to receive(:generate_bib_number_aysnc) | ||
order.send(:generate_guests_and_bib_numbers) | ||
end | ||
end | ||
|
||
describe "#generate_remaining_guests" do | ||
it 'calls generate_remaining_guests for each line item' do | ||
allow(order).to receive(:line_items).and_return(line_items) | ||
allow(line_items).to receive(:find_each).and_yield(line_item) | ||
|
||
expect(line_item).to receive(:generate_remaining_guests).once | ||
order.send(:generate_remaining_guests) | ||
end | ||
end | ||
|
||
describe "#generate_bib_number_aysnc" do | ||
it "enque a job with SpreeCmCommissioner::OrderCompleteBibGeneratorJob" do | ||
expect { | ||
order.send(:generate_bib_number_aysnc) | ||
}.to have_enqueued_job(SpreeCmCommissioner::OrderCompleteBibGeneratorJob).with(order.id) | ||
end | ||
end | ||
|
||
describe "#generate_bib_number!" do | ||
it 'calls generate_bib! for each guest with none_bib' do | ||
allow(order).to receive(:line_items).and_return(line_items) | ||
allow(line_items).to receive(:with_bib_prefix).and_return(line_items) | ||
allow(line_items).to receive(:find_each).and_yield(line_item) | ||
allow(line_item).to receive_message_chain(:guests, :none_bib).and_return(guests) | ||
allow(guests).to receive(:find_each).and_yield(guest) | ||
|
||
expect(guest).to receive(:generate_bib!).once | ||
order.generate_bib_number! | ||
end | ||
end | ||
end |