<commit_before>require 'spec_helper'

describe Backoffice::Dossiers::ProcedureController, type: :controller do
  let(:gestionnaire) { create :gestionnaire }
  let(:procedure) { create :procedure }

  before do
    create :assign_to, gestionnaire: gestionnaire, procedure: procedure
    sign_in gestionnaire
    gestionnaire.build_default_preferences_list_dossier procedure.id
  end

  describe 'GET #index' do
    let(:procedure_id) { procedure.id }

    subject { get :index, params: {id: procedure_id} }

    it { expect(subject.status).to eq 200 }

    context 'when procedure id is not found' do
      let(:procedure_id) { 100000 }

      before do
        subject
      end

      it { expect(response.status).to eq 302 }
      it { is_expected.to redirect_to backoffice_dossiers_path }
      it { expect(flash[:alert]).to be_present}
    end
  end

  describe 'GET #filter' do
    subject { get :filter, params: {id: procedure.id, filter_input: {"entreprise.raison_sociale" => "plop"}} }

    it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure.id) }
  end
end<commit_msg>Tests for display archived dossiers<commit_after>require 'spec_helper'

describe Backoffice::Dossiers::ProcedureController, type: :controller do
  let(:gestionnaire) { create :gestionnaire }
  let(:procedure) { create :procedure }
  let(:archived) { false }
  let(:dossier) { create :dossier, procedure: procedure, archived: archived, state: 'initiated'}

  before do
    create :assign_to, gestionnaire: gestionnaire, procedure: procedure
    sign_in gestionnaire
    gestionnaire.build_default_preferences_list_dossier procedure.id
  end

  describe 'GET #index' do
    let(:procedure_id) { procedure.id }

    subject { get :index, params: {id: procedure_id} }

    it { expect(subject.status).to eq 200 }

    context 'when procedure id is not found' do
      let(:procedure_id) { 100000 }

      before do
        subject
      end

      it { expect(response.status).to eq 302 }
      it { is_expected.to redirect_to backoffice_dossiers_path }
      it { expect(flash[:alert]).to be_present}
    end

    context 'when procedure contains a dossier' do
      render_views

      before do
        dossier
        subject
      end

      it { expect(response.body).to have_content('Tous les dossiers 1 dossier') }

      context 'archived' do
        let(:archived) { true }

        it { expect(response.body).to have_content('Tous les dossiers 0 dossiers') }
        it { expect(response.body).to have_content('Dossiers archivés 1 dossier') }
      end
    end
  end

  describe 'GET #filter' do
    subject { get :filter, params: {id: procedure.id, filter_input: {"entreprise.raison_sociale" => "plop"}} }

    it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure.id) }
  end
end
{'fraction_non_alphanumeric': 0.09709425939050319, 'fraction_numerical': 0.00956768249468462, 'mean_word_length': 3.4667721518987342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6345911', 'n_tokens_mistral': 933, 'n_tokens_neox': 856, 'n_words': 232}