feat(export.datetime): ensure to cast date and time

This commit is contained in:
mfo 2024-11-14 14:04:33 +01:00
parent 6cdd801326
commit ac6f5ba025
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
3 changed files with 30 additions and 3 deletions

View file

@ -109,7 +109,7 @@ module ColumnsConcern
def dossier_dates_columns def dossier_dates_columns
['created_at', 'updated_at', 'last_champ_updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at'] ['created_at', 'updated_at', 'last_champ_updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
.map { |column| dossier_col(table: 'self', column:, type: :date) } .map { |column| dossier_col(table: 'self', column:, type: :datetime) }
end end
def email_column def email_column

View file

@ -81,7 +81,7 @@ class DossierFilterService
else else
case table case table
when 'self' when 'self'
if filtered_column.type == :date if filtered_column.type == :date || filtered_column.type == :datetime
dates = values dates = values
.filter_map { |v| Time.zone.parse(v).beginning_of_day rescue nil } .filter_map { |v| Time.zone.parse(v).beginning_of_day rescue nil }

View file

@ -135,12 +135,39 @@ describe ProcedureExportService do
it { expect(dossiers_sheet.data.last.last).to eq 42.0 } it { expect(dossiers_sheet.data.last.last).to eq 42.0 }
end end
context 'with having TypesDeChamp::LinkedDropDownListTypeDeChamp' do context 'with TypesDeChamp::LinkedDropDownListTypeDeChamp' do
let(:types_de_champ_public) { [{ type: :linked_drop_down_list, libelle: "linked_drop_down_list", mandatory: true }] } let(:types_de_champ_public) { [{ type: :linked_drop_down_list, libelle: "linked_drop_down_list", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'linked_drop_down_list', column: procedure.find_column(label: 'linked_drop_down_list'))] } let(:exported_columns) { [ExportedColumn.new(libelle: 'linked_drop_down_list', column: procedure.find_column(label: 'linked_drop_down_list'))] }
before { create(:dossier, :with_populated_champs, procedure:) } before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq "primary / secondary" } it { expect(dossiers_sheet.data.last.last).to eq "primary / secondary" }
end end
context 'with TypesDeChamp::DateTimeTypeDeChamp' do
let(:types_de_champ_public) { [{ type: :datetime, libelle: "datetime", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'datetime', column: procedure.find_column(label: 'datetime'))] }
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
before { dossier }
it do
champ_value = Time.zone.parse(dossier.champs.first.value)
offset = champ_value.utc_offset
sheet_value = Time.zone.at(dossiers_sheet.data.last.last - offset.seconds)
expect(sheet_value).to eq(champ_value.round)
end
end
context 'with TypesDeChamp::Date' do
let(:types_de_champ_public) { [{ type: :date, libelle: "date", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'date', column: procedure.find_column(label: 'date'))] }
before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to be_an_instance_of(Date) }
end
context 'with DossierColumn as datetime' do
let(:types_de_champ_public) { [] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'Date de passage en instruction', column: procedure.find_column(label: 'Date de passage en instruction'))] }
before { create(:dossier, :en_instruction, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to be_an_instance_of(Time) }
end
end end
describe 'Etablissement sheet' do describe 'Etablissement sheet' do