Skip to content

Commit

Permalink
Add test for promotion duplication job
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdonarski committed Nov 13, 2023
1 parent 4a4d0ca commit ea5495f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/jobs/duplicate_promotion_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class DuplicatePromotionJob
include Sidekiq::Job

def perform(params)
promotion = find_promotion(params[:promotion_id])
Spree::PromotionHandler::PromotionDuplicator.new(promotion).duplicate
end

private

def find_promotion(id)
Spree::Promotion.find(id)
end
end
32 changes: 32 additions & 0 deletions spec/jobs/duplicate_promotion_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe DuplicatePromotionJob do
describe "#perform" do
subject(:execute_job) { described_class.new.perform(params) }

let(:promotion) { build(:promotion) }

let(:params) do
{ promotion_id: promotion.id }
end

let(:double) { instance_double(Spree::PromotionHandler::PromotionDuplicator) }

before do
allow(Spree::Promotion)
.to receive(:find)
.and_return(promotion)
end

it "sends #duplicate to the duplicator service" do
expect(Spree::PromotionHandler::PromotionDuplicator)
.to receive(:new)
.with(promotion)
.and_return(double)
expect(double)
.to receive(:duplicate)

execute_job
end
end
end

0 comments on commit ea5495f

Please sign in to comment.