<commit_before>require 'spec_helper'


describe SubmitDirtyAnswersJob do

  let(:answers) do
    5.times.map { |i| double("Asnwer", {}) }
  end

  let(:run_stubs) do
    {
      key: "run-key",
      dirty_answers: answers,
      id: run_id,
      send_to_portal: true,
      set_answers_clean: true,
      reload: true,
      abort_job_and_requeue: true
    }
  end

  let(:run_id) { 7 }

  let(:run) { double("Run", run_stubs) }
  let(:report_service_configured) { false}
  let(:submit_time) { Time.now }
  let(:job) { SubmitDirtyAnswersJob.new(run_id, submit_time) }

  before(:each) do
    allow(ReportService)
      .to receive(:configured?)
      .and_return report_service_configured

    allow(Run).to receive(:find).with(run_id).and_return(run)
  end

  describe "#send_to_report_service" do
    describe "when the report service is not configured" do
      let(:report_service_configured) { false }
      it "we shouldn't send data to the report service" do
        expect(job).not_to receive(:send_to_report_service)
        expect { job.perform }.not_to raise_error
      end
    end

    describe "When the report service is configured" do
      let(:report_service_configured) { true }
      it "should send data to the report service" do
        expect(job).to receive(:send_to_report_service).with(run)
        expect { job.perform }.not_to raise_error
      end
      describe "When something goes wrong while sending" do
        before(:each) do
          allow_any_instance_of(ReportService::RunSender)
            .to receive(:send)
            .and_raise("bang")
        end
        it "should report an error without halting" do
          expect(Rails.logger).to receive(:error).at_least(:once)
          expect { job.perform }.not_to raise_error
        end
      end
    end
  end
end<commit_msg>Update specs<commit_after>require 'spec_helper'


describe SubmitDirtyAnswersJob do

  let(:answers) do
    5.times.map { |i| double("Asnwer", {}) }
  end

  let(:run_stubs) do
    {
      key: "run-key",
      dirty_answers: answers,
      id: run_id,
      send_to_portal: true,
      set_answers_clean: true,
      reload: true,
      abort_job_and_requeue: true
    }
  end

  let(:run_id) { 7 }

  let(:run) { double("Run", run_stubs) }
  let(:report_service_configured) { false}
  let(:submit_time) { Time.now }
  let(:job) { SubmitDirtyAnswersJob.new(run_id, submit_time) }

  before(:each) do
    allow(ReportService)
      .to receive(:configured?)
      .and_return report_service_configured

    allow(Run).to receive(:find).with(run_id).and_return(run)
  end

  describe "#send_to_report_service" do
    describe "when the report service is not configured" do
      let(:report_service_configured) { false }
      it "we shouldn't send data to the report service" do
        expect(job).not_to receive(:send_to_report_service)
        expect { job.perform }.not_to raise_error
      end
    end

    describe "When the report service is configured" do
      let(:report_service_configured) { true }
      it "should send data to the report service" do
        expect(job).to receive(:send_to_report_service).with(run)
        expect { job.perform }.not_to raise_error
      end
      describe "When something goes wrong while sending" do
        before(:each) do
          allow_any_instance_of(ReportService::RunSender)
            .to receive(:send)
            .and_raise("bang")
        end
        it "should raise error to re-run job" do
          expect { job.perform }.to raise_error
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09823182711198428, 'fraction_numerical': 0.001122649452708392, 'mean_word_length': 2.7754237288135593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '245487', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1130, 'n_words': 282}