Sha256: 377f02f1ae124ceae2a59d53917c212e44d7ecbdbb512dadeb33c570d534ec33

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe NewsletterJob do
      let!(:newsletter) { create(:newsletter, organization: organization, total_deliveries: 0) }
      let!(:organization) { create(:organization) }
      let!(:deliverable_user) { create(:user, :confirmed, newsletter_notifications: true, organization: organization) }
      let!(:undeliverable_user) { create(:user, newsletter_notifications: true, organization: organization) }
      let!(:non_deliverable_user) { create(:user, :confirmed, newsletter_notifications: false, organization: organization) }

      it "delivers a newsletter to a the eligible users" do
        expect(NewsletterDeliveryJob).to receive(:perform_later).with(deliverable_user, newsletter)
        expect(NewsletterDeliveryJob).not_to receive(:perform_later).with(undeliverable_user, newsletter)

        NewsletterJob.perform_now(newsletter)
      end

      it "updates the recipients count" do
        NewsletterJob.perform_now(newsletter)
        expect(newsletter.reload.total_recipients).to eq(1)
      end

      it "updates the deliveries count" do
        NewsletterJob.perform_now(newsletter)
        expect(newsletter.reload.total_deliveries).to eq(0)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-0.3.2 decidim-admin/spec/jobs/newsletter_job_spec.rb
decidim-0.3.1 decidim-admin/spec/jobs/newsletter_job_spec.rb
decidim-0.3.0 decidim-admin/spec/jobs/newsletter_job_spec.rb
decidim-0.2.0 decidim-admin/spec/jobs/newsletter_job_spec.rb