/
event_participations_export_job_spec.rb
169 lines (143 loc) · 4.89 KB
/
event_participations_export_job_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# encoding: utf-8
# Copyright (c) 2017, Jungwacht Blauring Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.
require 'spec_helper'
describe Export::EventParticipationsExportJob do
subject { Export::EventParticipationsExportJob.new(format,
user.id,
event_participation_filter,
params) }
let(:user) { people(:top_leader) }
let(:other_user) { people(:bottom_member) }
let(:course) { events(:top_course) }
let(:person) { ndbjs_person }
let(:group) { course.groups.first }
let(:event_role) { Fabricate(:event_role, type: Event::Role::Leader.sti_name) }
let(:participation) { Fabricate(:event_participation, person: person, event: course, roles: [event_role], active: true) }
let(:event_participation_filter) { Event::ParticipationFilter.new(course, user, params) }
before do
SeedFu.quiet = true
SeedFu.seed [Rails.root.join('db', 'seeds')]
participation
end
context 'exports csv files' do
let(:format) { :csv }
let(:params) { { filter: 'all' } }
it 'and sends it via mail' do
expect do
subject.perform
end.to change { ActionMailer::Base.deliveries.size }.by 1
expect(last_email.subject).to eq('Export der Event-Teilnehmer')
lines = last_email.attachments.first.body.to_s.split("\n")
expect(lines.size).to eq(4)
expect(lines[0]).to match(/^Vorname;Nachname/)
expect(lines[0].split(';').count).to match(18)
end
end
context 'exports csv ndbjs' do
let(:format) { :csv }
let(:params) { { filter: 'all', ndbjs: true } }
it 'and sends it via mail' do
expect do
subject.perform
end.to change { ActionMailer::Base.deliveries.size }.by 1
expect(last_email.subject).to eq('Export der Event-Teilnehmer')
lines = last_email.attachments.first.body.to_s.split("\n")
expect(lines.size).to eq(4)
expect(lines[0]).to match(/#{ndbjs_csv_header}/)
expect(lines[3]).to match(/#{person_ndbjs_csv_row}/)
expect(lines[0].split(';').count).to match(24)
end
end
context 'exports csv sportdb' do
let(:format) { :csv }
let(:params) { { filter: 'all', sportdb: true } }
it 'and sends it via mail' do
expect do
subject.perform
end.to change { ActionMailer::Base.deliveries.size }.by 1
expect(last_email.subject).to eq('Export der Event-Teilnehmer')
lines = last_email.attachments.first.body.to_s.split("\n")
expect(lines.size).to eq(4)
expect(lines[0]).to match(/#{sportdb_csv_header}/)
expect(lines[3]).to match(/#{person_sportdb_csv_row}/)
expect(lines[0].split(';').count).to match(12)
end
end
private
def ndbjs_person
person = Fabricate(:person,
email: 'foo@e.com',
first_name: 'Peter',
last_name: 'Muster',
birthday: '11.06.1980',
gender: 'm',
j_s_number: '123',
ahv_number: '789',
address: 'Str',
zip_code: '4000',
town: 'Basel',
country: 'CH',
nationality_j_s: 'FL'
)
create_contactables(person)
person
end
def create_contactables(person)
Fabricate(:phone_number, contactable: person, label: 'Privat', number: '11')
Fabricate(:phone_number, contactable: person, label: 'Arbeit', number: '42')
Fabricate(:phone_number, contactable: person, label: 'Mobil', number: '99')
Fabricate(:phone_number, contactable: person, label: 'Fax', number: '33')
end
def ndbjs_csv_header
%w( NDS_PERSONEN_NR
GESCHLECHT
NAME
VORNAME
GEBURTSDATUM
AHV_NUMMER
STRASSE
PLZ
ORT
KANTON
LAND
TELEFON_PRIVAT
TELEFON_GESCHAEFT
TELEFON_MOBIL
FAX
EMAIL
NATIONALITAET
ERSTSPRACHE
ZWEITSPRACHE
BERUF
VERPFLICHT_ORG
VERPFLICHT_VERB
TAETIGKEIT
BEILAGEN
).join(';')
end
def sportdb_csv_header
%w( NDBJS_PERS_NR
GESCHLECHT
NAME
VORNAME
GEB_DATUM
STRASSE
PLZ
ORT
LAND
NATIONALITAET
ERSTSPRACHE
KLASSE/GRUPPE
).join(';')
end
def person_ndbjs_csv_row
(%w(123 1 Muster Peter 11.06.1980 789 Str 4000 Basel BS CH 11 42 99 33 foo@e.com FL D) +
['', '3', '', '', '1', '1']).join(';')
end
def person_sportdb_csv_row
%w(123 1 Muster Peter 11.06.1980 Str 4000 Basel CH FL D).join(';')
end
end