2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-25 17:57:55 +02:00
|
|
|
RSpec.describe DossierIndexSearchTermsJob, type: :job do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :text }] }
|
|
|
|
let(:types_de_champ_private) { [{ type: :text }] }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
|
|
|
let(:champ_siret) { dossier.champs.first }
|
2023-04-22 19:54:41 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
subject(:perform_job) { described_class.perform_now(dossier.reload) }
|
2023-04-22 19:54:41 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
before do
|
2024-07-01 15:31:32 +02:00
|
|
|
dossier.champs_public.first.update_column(:value, "un nouveau champ")
|
|
|
|
dossier.champs_private.first.update_column(:value, "private champ")
|
2024-04-03 10:21:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "update search terms columns" do
|
|
|
|
perform_job
|
|
|
|
|
|
|
|
sql = "SELECT search_terms, private_search_terms FROM dossiers WHERE id = :id"
|
|
|
|
sanitized_sql = Dossier.sanitize_sql_array([sql, id: dossier.id])
|
|
|
|
result = Dossier.connection.execute(sanitized_sql).first
|
2023-04-22 19:54:41 +02:00
|
|
|
|
2024-04-03 10:21:50 +02:00
|
|
|
expect(result['search_terms']).to match(/un nouveau champ/)
|
|
|
|
expect(result['private_search_terms']).to match(/private champ/)
|
2023-04-22 19:54:41 +02:00
|
|
|
end
|
|
|
|
end
|