Sha256: 0c87d8719bbe2a8fd3baf90e4b88b300de933b74b62ef33960ba521a0d5c48f3

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

require 'rails_helper'
RSpec.describe Spree::PromotionCodeBatchJob, type: :job do
  let(:email) { "test@email.com" }
  let(:promotion_code_batch) do
    Spree::PromotionCodeBatch.create!(
      promotion_id: create(:promotion).id,
      base_code: "test",
      number_of_codes: 10,
      email: email
    )
  end

  context "with a successful build" do
    before do
      allow(Spree::PromotionCodeBatchMailer)
        .to receive(:promotion_code_batch_finished)
        .and_call_original
    end
    context "with an email address" do
      it "sends an email" do
        subject.perform(promotion_code_batch)
        expect(Spree::PromotionCodeBatchMailer)
          .to have_received(:promotion_code_batch_finished)
      end
    end
    context "with no email address" do
      let(:email) { nil }
      it "sends an email" do
        subject.perform(promotion_code_batch)
        expect(Spree::PromotionCodeBatchMailer)
          .to_not have_received(:promotion_code_batch_finished)
      end
    end
  end

  context "with a failed build" do
    before do
      allow_any_instance_of(Spree::PromotionCode::BatchBuilder)
        .to receive(:build_promotion_codes)
        .and_raise("Error")

      allow(Spree::PromotionCodeBatchMailer)
        .to receive(:promotion_code_batch_errored)
        .and_call_original

      expect { subject.perform(promotion_code_batch) }
        .to raise_error RuntimeError
    end

    context "with an email address" do
      it "sends an email" do
        expect(Spree::PromotionCodeBatchMailer)
          .to have_received(:promotion_code_batch_errored)
      end
    end

    context "with no email address" do
      let(:email) { nil }
      it "sends an email" do
        expect(Spree::PromotionCodeBatchMailer)
          .to_not have_received(:promotion_code_batch_errored)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
solidus_core-2.5.2 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.5.1 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.5.0 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.5.0.rc1 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.5.0.beta2 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.5.0.beta1 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.4.2 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.4.1 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.4.0 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.4.0.rc1 spec/jobs/promotion_code_batch_job_spec.rb
solidus_core-2.4.0.beta1 spec/jobs/promotion_code_batch_job_spec.rb