<commit_before># frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::Orphans::Reaper do
  let(:service)  { redis { |conn| described_class.new(conn) } }
  let(:digest)   { "uniquejobs:digest" }
  let(:job_id)   { "job_id" }
  let(:item)     { raw_item }
  let(:lock)     { SidekiqUniqueJobs::Lock.create(digest, job_id, lock_info) }
  let(:raw_item) { { "class" => MyUniqueJob, "args" => [], "jid" => job_id, "lock_digest" => digest } }
  let(:lock_info) do
    {
      "job_id" => job_id,
      "limit" => 1,
      "lock" => :while_executing,
      "time" => now_f,
      "timeout" => nil,
      "ttl" => nil,
      "lock_args" => [],
      "worker" => "MyUniqueJob",
    }
  end

  before do
    SidekiqUniqueJobs.disable!
    lock
  end

  after do
    SidekiqUniqueJobs.enable!
  end

  describe ".call" do
    subject(:call) { described_class.call }

    around do |example|
      SidekiqUniqueJobs.use_config(reaper: reaper) do
        example.run
      end
    end

    shared_examples "deletes orphans" do
      context "when scheduled" do
        let(:item) { raw_item.merge("at" => Time.now.to_f + 3_600) }

        context "without scheduled job" do
          it "deletes the digest" do<commit_msg>Add comment about test setup<commit_after># frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::Orphans::Reaper do
  let(:service)  { redis { |conn| described_class.new(conn) } }
  let(:digest)   { "uniquejobs:digest" }
  let(:job_id)   { "job_id" }
  let(:item)     { raw_item }
  let(:lock)     { SidekiqUniqueJobs::Lock.create(digest, job_id, lock_info) }
  let(:raw_item) { { "class" => MyUniqueJob, "args" => [], "jid" => job_id, "lock_digest" => digest } }
  let(:lock_info) do
    {
      "job_id" => job_id,
      "limit" => 1,
      "lock" => :while_executing,
      "time" => now_f,
      "timeout" => nil,
      "ttl" => nil,
      "lock_args" => [],
      "worker" => "MyUniqueJob",
    }
  end

  before do
    # Create the lock key without having a matching digest in a job hash
    #   (this is needed because we want to setup the test conditions manually)
    #   (find this to be more sensible defaults)
    SidekiqUniqueJobs.disable!
    lock
  end

  after do
    SidekiqUniqueJobs.enable!
  end

  describe ".call" do
    subject(:call) { described_class.call }

    around do |example|
      SidekiqUniqueJobs.use_config(reaper: reaper) do
        example.run
      end
    end

    shared_examples "deletes orphans" do
      context "when scheduled" do
        let(:item) { raw_item.merge("at" => Time.now.to_f + 3_600) }

        context "without scheduled job" do
          it "deletes the digest" do
{'fraction_non_alphanumeric': 0.1345139412207988, 'fraction_numerical': 0.0037678975131876413, 'mean_word_length': 2.7928571428571427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6431802', 'n_tokens_mistral': 964, 'n_tokens_neox': 925, 'n_words': 217}