Skip to content

Commit

Permalink
fix pf champ specs
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Jun 28, 2024
1 parent fd64604 commit ab8280e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3841,7 +3841,7 @@ type PfCommune {
"""
Le code postal
"""
postalCode: String
postalCode: Int
}

type PhoneChampDescriptor implements ChampDescriptor {
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17280,7 +17280,7 @@
],
"type": {
"kind": "SCALAR",
"name": "String",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
Expand Down
2 changes: 1 addition & 1 deletion app/models/champs/numero_dn_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def blank?
end

def search_terms
[numero_dn, date_de_naissance]
[numero_dn, displayed_date_de_naissance]
end

private
Expand Down
1 change: 0 additions & 1 deletion app/models/champs/piece_justificative_champ.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Champs::PieceJustificativeChamp < Champ
include ActionView::Helpers::TagHelper
FILE_MAX_SIZE = 200.megabytes

has_many_attached :piece_justificative_file do |attachable|
Expand Down
36 changes: 4 additions & 32 deletions app/models/types_de_champ/numero_dn_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,14 @@ def paths
paths = super
paths.push({
libelle: "#{libelle} (Date de naissance)",
description: "#{description} (Date de naissance)",
path: :date_de_naissance,
example: Date.today,
maybe_null: public? && !mandatory?
description: "#{description} (Date de naissance)",
path: :date_de_naissance,
example: Date.today,
maybe_null: public? && !mandatory?
})
paths
end

def tags_for_template
tags = super
tdc = @type_de_champ
tags.push(
{
libelle: "#{libelle}/numero_dn",
description: "#{description} (Numero DN)",
lambda: -> (champs) {
champs
.find { |champ| champ.type_de_champ == tdc }
&.numero_dn
}
}
)
tags.push(
{
libelle: "#{libelle}/date_de_naissance",
description: "#{description} (date de naissance)",
lambda: -> (champs) {
champs
.find { |champ| champ.type_de_champ == tdc }
&.date_de_naissance
}
}
)
tags
end

class << self
def champ_value(champ)
champ.numero_dn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBase
extend ActionView::Helpers::TagHelper
def estimated_fill_duration(revision)
FILL_DURATION_LONG
end
Expand All @@ -8,11 +9,11 @@ def estimated_fill_duration(revision)

class << self
def champ_value_for_tag(champ, path = nil)
return nil unless piece_justificative_file.attached?
return nil unless champ.piece_justificative_file.attached?

piece_justificative_file.each_with_index.filter_map do |attachment, i|
champ.piece_justificative_file.each_with_index.filter_map do |attachment, i|
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
url = Rails.application.routes.url_helpers.champs_piece_justificative_download_url({ champ_id: id, h: encoded_date(:created_at), i: })
url = Rails.application.routes.url_helpers.champs_piece_justificative_download_url({ champ_id: champ.id, h: champ.encoded_date(:created_at), i: })
display = attachment.filename
if attachment.image?
tag.img '', src: url, width: '100', id: attachment.id, display: display
Expand Down
4 changes: 3 additions & 1 deletion spec/factories/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@

factory :champ_numero_dn, class: 'Champs::NumeroDnChamp' do
type_de_champ { association :type_de_champ_numero_dn, procedure: dossier.procedure }
value { '["1234567", null]' }
# value { '["1234567", "2000-01-01"]' }
numero_dn { "1234567" }
date_de_naissance { "2000-01-01" }
end

factory :champ_multiple_drop_down_list, class: 'Champs::MultipleDropDownListChamp' do
Expand Down
60 changes: 53 additions & 7 deletions spec/models/champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,53 @@

it { expect(champ.for_export).to eq('Crétinier, Mousserie') }
end

# pf displays links for PJs
context 'when type_de_champ is piece_justificative' do
let(:champ) { create(:champ_piece_justificative) }

it { expect(champ.for_export).to eq('toto.txt') }
end
end

describe '#for_tag' do
# pf displays links for PJs
context 'when type_de_champ is piece_justificative' do
let(:champ) { create(:champ_piece_justificative) }

it { expect(champ.for_tag).to include('<a href="http://') }
end

context 'when type_de_champ is numero_dn' do
let(:champ) { create(:champ_numero_dn) }

it do
expect(champ.for_tag).to eq("1234567")
expect(champ.for_tag(:date_de_naissance)).to eq('01 janvier 2000')
end
end

context 'when type_de_champ is commune de polynesie' do
let(:champ) { create(:champ_commune_de_polynesie) }

it do
expect(champ.for_tag).to eq("Arue")
expect(champ.for_tag(:ile)).to eq('Tahiti')
expect(champ.for_tag(:archipel)).to eq('Iles Du Vent')
expect(champ.for_tag(:code_postal)).to eq(98701)
end
end

context 'when type_de_champ is code postal de polynesie' do
let(:champ) { create(:champ_code_postal_de_polynesie) }

it do
expect(champ.for_tag).to eq(98701)
expect(champ.for_tag(:ile)).to eq('Tahiti')
expect(champ.for_tag(:archipel)).to eq('Iles Du Vent')
expect(champ.for_tag(:commune)).to eq('Arue')
end
end
end

describe '#search_terms' do
Expand Down Expand Up @@ -243,7 +290,7 @@
end

context 'for nationalités champ' do
let(:champ) { create(:champ_nationalite, value:) }
let(:champ) { create(:champ_nationalites, value:) }
let(:value) { "Française" }

it { is_expected.to eq([value]) }
Expand All @@ -253,14 +300,14 @@
let(:champ) { create(:champ_commune_de_polynesie, value:) }
let(:value) { "Arue - Tahiti - 98701" }

it { is_expected.to eq([value]) }
it { is_expected.to eq(["Arue"]) }
end

context 'for code postal de polynésie champ' do
let(:champ) { create(:champ_code_postal_de_polynesie, value:) }
let(:value) { "98701 - Arue - Tahiti" }

it { is_expected.to eq([value]) }
it { is_expected.to eq(["98701"]) }
end

context 'for dossier link champ' do
Expand Down Expand Up @@ -303,10 +350,9 @@
end

context 'for numero dn champ' do
let(:champ) { create(:champ_numero_dn, value:) }
let(:value) { JSON.generate([numero_dn: "1234567", date_de_naissance: nil]) }
let(:champ) { create(:champ_numero_dn, numero_dn: "1234567", date_de_naissance: "2000-01-01") }

it { is_expected.to eq(["1234567", nil]) }
it { is_expected.to eq(["1234567", "01/01/2000"]) }
end

context 'for multiple drop down list champ' do
Expand Down Expand Up @@ -340,7 +386,7 @@
end

context 'for nationalites champ' do
let(:type_de_champ) { build(:type_de_champ_nationalites) }
let(:champ) { build(:champ_nationalites) }
let(:value) { "Française" }

it { is_expected.to eq([value]) }
Expand Down
8 changes: 4 additions & 4 deletions spec/models/champs/numero_dn_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

describe '#to_s' do
let(:champ) { described_class.new(numero_dn: numero_dn, date_de_naissance: date_de_naissance) }
let(:champ) { build(:champ_numero_dn, numero_dn:, date_de_naissance:) }
let(:numero_dn) { nil }
let(:date_de_naissance) { nil }

Expand Down Expand Up @@ -40,19 +40,19 @@
subject { champ.for_export }

context 'with no value' do
let(:champ) { described_class.new }
let(:champ) { build(:champ_numero_dn, numero_dn: nil, date_de_naissance: nil) }

it { is_expected.to be_nil }
end

context 'with dn value' do
let(:champ) { described_class.new(numero_dn: dn) }
let(:champ) { build(:champ_numero_dn, numero_dn: dn, date_de_naissance: nil) }

it { is_expected.to be_nil }
end

context 'with dn & ddn values' do
let(:champ) { described_class.new(numero_dn: dn, date_de_naissance: ddn) }
let(:champ) { build(:champ_numero_dn, numero_dn: dn, date_de_naissance: ddn) }

it { is_expected.to eq(dn) }
end
Expand Down

0 comments on commit ab8280e

Please sign in to comment.