Skip to content

A platform for community discussion. Free, open, simple.

1.0 KB
Raw Blame
# frozen_string_literal: true

describe "TopicExtensions" do
  before { freeze_time }

  fab!(:user_1) { Fabricate(:user, admin: true) }
  fab!(:topic_1) { Fabricate(:topic, user: user_1) }

  context "when an enabled category is set on the topic" do
    fab!(:category_1, :category)

    before { SiteSetting.zendesk_autogenerate_categories = "#{category_1.id}" }

    it "queues a sync job" do
      expect_enqueued_with(
        job: :zendesk_job,
        args: {
          topic_id: topic_1.id,
        },
        at: 5.seconds.from_now,
      ) do
        topic_1.category = category_1
        topic_1.save!
      end
    end

    context "when the category is removed" do
      before do
        topic_1.category = category_1
        topic_1.save!
      end

      it "queues a sync job" do
        expect_enqueued_with(
          job: :zendesk_job,
          args: {
            topic_id: topic_1.id,
          },
          at: 5.seconds.from_now,
        ) do
          topic_1.category = nil
          topic_1.save!
        end
      end
    end
  end
end