Skip to content

Commit

Permalink
Re-enable BackupMitgliederExportJob, fix phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-illi committed Jan 10, 2025
1 parent 5ec38a8 commit 635714d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/domain/export/tabular/people/sac_mitglied_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def phone_number(label)
entry.phone_numbers.find { |p| p.label.downcase == label.to_s }&.number
end

def phone_number_main
phone_number("haupt-telefon")
end

def postfach
entry.postbox
end
Expand Down
6 changes: 3 additions & 3 deletions app/domain/export/tabular/people/sac_mitglieder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def attributes # rubocop:disable Metrics/MethodLength
:town,
:country,
:birthday,
:phone_number_direkt,
:phone_number_main,
:phone_number_privat,
:empty, # 1 leere Spalte
:phone_number_mobil,
Expand Down Expand Up @@ -65,9 +65,9 @@ def mitglieder
Person
.where(roles: {
group_id: non_layer_children_ids,
type: (SacCas::MITGLIED_ROLES - SacCas::NEUANMELDUNG_ROLES).map(&:sti_name)
type: SacCas::MITGLIED_ROLES.map(&:sti_name)
})
.joins(:roles_unscoped)
.joins(:roles)
.includes(:phone_numbers, :roles, roles: :group)
.distinct
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/export/backup_mitglieder_schedule_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class Export::BackupMitgliederScheduleJob < RecurringJob

ROLE_TYPES_TO_BACKUP = [Group::Sektion, Group::Ortsgruppe].map(&:sti_name)

# Job is temporarily disabled (https://github.com/hitobito/hitobito_sac_cas/issues/1426)
# When re-enabling, also un-skip the corresponding specs.
def perform_internal_DISABLED
def perform_internal
relevant_groups.find_each do |group|
Export::BackupMitgliederExportJob.new(group.id).enqueue!
end
Expand Down
5 changes: 5 additions & 0 deletions spec/domain/export/tabular/people/sac_mitglied_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@
expect(row.phone_number("mobile")).to eq(mobile1.number).or eq(mobile2.number)
end

it "#phone_number_main returns number with label Haupt-Telefon" do
main = Fabricate(:phone_number, contactable: person, label: "Haupt-Telefon", number: "0311234567")
expect(row.phone_number_main).to eq main.number
end

it "#phone_number_mobile returns any number with label mobile" do
mobile = Fabricate(:phone_number, contactable: person, label: "mobile", number: "0781234567")
expect(row.phone_number_mobile).to eq mobile.number
Expand Down
11 changes: 10 additions & 1 deletion spec/domain/export/tabular/people/sac_mitglieder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
:town,
:country,
:birthday,
:phone_number_direkt,
:phone_number_main,
:phone_number_privat,
:empty, # 1 leere Spalte
:phone_number_mobil,
Expand Down Expand Up @@ -73,6 +73,15 @@
roles(:familienmitglied_kind).person
)
end

it "former mitglieder are not included" do
roles(:mitglied).update!(end_on: 1.day.ago)
expect(tabular.list).to contain_exactly(
roles(:familienmitglied).person,
roles(:familienmitglied2).person,
roles(:familienmitglied_kind).person
)
end
end

context "zusatzsektion mitglieder of the layer" do
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/export/backup_mitglieder_schedule_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

require "spec_helper"

xdescribe Export::BackupMitgliederScheduleJob do
describe Export::BackupMitgliederScheduleJob do
subject(:job) { described_class.new }

let(:relevant_groups) { Group.where(type: [Group::Sektion, Group::Ortsgruppe].map(&:sti_name)) }
Expand Down
8 changes: 8 additions & 0 deletions spec/jobs/sac_cas/export/mitglieder_export_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
expect { job.perform }.to change { AsyncDownloadFile.count }.by(1)
expect(contents).to match(/\$#{person.last_name}\$"#{person.first_name}"\$/)
end

it "has quotation marks for strings containing col_sep" do
person = people(:mitglied)
person.update!(first_name: "Hello$World")
Person.where.not(id: people(:mitglied, :admin).map(&:id)).destroy_all
expect { job.perform }.to change { AsyncDownloadFile.count }.by(1)
expect(contents).to include %($#{person.last_name}$"#{person.first_name}"$)
end
end

it "file name" do
Expand Down

0 comments on commit 635714d

Please sign in to comment.