Skip to content

Commit

Permalink
Detection plus precise des solicitations Entreprendre
Browse files Browse the repository at this point in the history
  • Loading branch information
clairezed committed Feb 5, 2025
1 parent 351ce43 commit c3ead12
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/controllers/solicitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def redirect_entreprendre_solicitations
end

def from_entreprendre_via_view_params
query_params[:mtm_campaign] == 'entreprendre' && !(view_params[:redirected] == 'entreprendre')
QueryFromEntreprendre.new(campaign: query_params[:mtm_campaign], kwd: query_params[:mtm_kwd]).call
&& !(view_params[:redirected] == 'entreprendre')
end

def from_entreprendre_via_referer
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/solicitation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def link_to_diagnosis(diagnosis)
end

def display_solicitation_attribute(solicitation, attribute)
if attribute == :provenance_detail && solicitation.campaign == 'entreprendre'
if attribute == :provenance_detail && solicitation.from_entreprendre
link_to solicitation.send(attribute), partner_url(solicitation, full: true), title: "#{to_new_window_title(t('needs.show.origin_source_title'))}", target: '_blank', rel: 'noopener', data: { turbo: false }
elsif attribute == :siret
link_to(solicitation.normalized_siret, show_with_siret_companies_path(solicitation.siret), data: { turbo: false })
Expand All @@ -79,7 +79,7 @@ def partner_title(solicitation)
def partner_url(solicitation, full: false)
return if solicitation.nil?
return solicitation.origin_url if solicitation.origin_url.present?
return entreprendre_url(solicitation, full: full) if (solicitation.campaign == 'entreprendre' && solicitation.kwd.present?)
return entreprendre_url(solicitation, full: full) if (solicitation.from_entreprendre && solicitation.kwd.present?)
return landing_partner_url(solicitation, full: full)
end

Expand Down
13 changes: 10 additions & 3 deletions app/models/solicitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# location :string
# phone_number :string
# prepare_diagnosis_errors_details :jsonb
# provenance_detail :string
# requested_help_amount :string
# siret :string
# status :integer default("step_contact")
Expand Down Expand Up @@ -74,7 +75,7 @@ class Solicitation < ApplicationRecord
attr_accessor :certify_being_company_boss

before_create :set_uuid
before_create :set_cooperation_from_landing
before_create :set_cooperation

after_update :update_diagnosis

Expand Down Expand Up @@ -206,8 +207,8 @@ def step_unmodifiable?
## Callbacks
#

def set_cooperation_from_landing
self.cooperation ||= landing&.cooperation || Cooperation.find_by(mtm_campaign: form_info&.fetch('mtm_campaign', nil))
def set_cooperation
self.cooperation ||= landing&.cooperation || Cooperation.find_by(mtm_campaign: form_info&.fetch('mtm_campaign', nil)) || (Cooperation.find_by(mtm_campaign: 'entreprendre') if self.from_entreprendre)
end

def set_uuid
Expand All @@ -228,6 +229,12 @@ def formatted_email
self.email&.squeeze('.')
end

# Format fiche : F1234..
def from_entreprendre
self.cooperation&.mtm_campaign == 'entreprendre' ||
QueryFromEntreprendre.new(campaign: self.campaign, kwd: self.kwd).call
end

## Scopes
#
scope :omnisearch, -> (query) do
Expand Down
20 changes: 20 additions & 0 deletions app/services/query_from_entreprendre.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class QueryFromEntreprendre
def initialize(campaign: nil, kwd: nil)
@campaign = campaign
@kwd = kwd
end

def call
entreprendre_campaign || entreprendre_kwd
end

private

def entreprendre_campaign
@campaign.present? && @campaign == 'entreprendre'
end

def entreprendre_kwd
@kwd.present? && !!@kwd.match(/^F+[0-9]+/)
end
end
16 changes: 15 additions & 1 deletion spec/models/solicitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
end

describe 'callbacks' do
describe 'set_cooperation_from_landing' do
describe 'set_cooperation' do
subject { solicitation.cooperation }

context 'with cooperation from a landing page' do
Expand All @@ -184,12 +184,26 @@
it { is_expected.to eq cooperation }
end

context 'with entreprendre mtm_kwd in the query_params' do
let!(:cooperation) { create :cooperation, mtm_campaign: 'entreprendre' }
let(:solicitation) { create :solicitation, form_info: { mtm_kwd: 'F12345' } }

it { is_expected.to eq cooperation }
end

context 'with no cooperation' do
let(:landing) { build :landing, cooperation: nil }
let(:solicitation) { create :solicitation, landing: landing, form_info: {} }

it { is_expected.to be_nil }
end

context 'with random mtm_kwd' do
let!(:cooperation) { create :cooperation, mtm_campaign: 'entreprendre' }
let(:solicitation) { create :solicitation, form_info: { mtm_kwd: 'FrouFrou' } }

it { is_expected.to be_nil }
end
end

describe 'format_solicitation' do
Expand Down
43 changes: 43 additions & 0 deletions spec/services/query_from_entreprendre_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'rails_helper'
describe QueryFromEntreprendre do
describe 'call' do
subject { described_class.new(campaign: campaign, kwd: kwd).call }

context 'with nil values' do
let(:campaign) { nil }
let(:kwd) { nil }

it{ is_expected.to be(false) }
end

context 'with entreprendre campaign' do
let(:campaign) { 'entreprendre' }
let(:kwd) { nil }

it{ is_expected.to be(true) }
end

context 'with not entreprendre campaign' do
let(:campaign) { 'fructifier' }
let(:kwd) { nil }

it{ is_expected.to be(false) }
end

context 'with entreprendre kwd' do
let(:campaign) { nil }
let(:kwd) { 'F1234' }

it{ is_expected.to be(true) }
end

context 'with not entreprendre kwd' do
let(:campaign) { nil }
let(:kwd) { '123-bois' }

it{ is_expected.to be(false) }
end
end
end

0 comments on commit c3ead12

Please sign in to comment.