Class: ODDB::Doctors::TestDoctorPlugin

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/zdoctor.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'test/test_plugin/zdoctor.rb', line 18

def setup
  @app = Mock.new('Application')
  @config = Mock.new('Config')
  @app.__next(:config) {
    @config
  }
  @plugin = DoctorPlugin.new(@app)
  @hash =  {
    :exam            =>"1970", 
    :firstname     =>"Happy Camper", 
    :language        =>"deutsch", 
    :name            =>"Testdoctor", 
    :addresses     => [],
    :praxis          =>"Ja", 
    :salutation      =>"Herrn", 
    :skills          => "SuperLabor RTZ",
    :specialities    =>  "GrossLap Medizin", 
    :abilities     =>  "Mangel- und Seisemedizin", 
    :title         =>"Dr. med.", 
  }
end

- (Object) teardown



39
40
41
42
# File 'test/test_plugin/zdoctor.rb', line 39

def teardown
  @app.__verify
  DoctorPlugin::PARSER.__verify
end

- (Object) test_get_doctor_data



43
44
45
46
47
48
# File 'test/test_plugin/zdoctor.rb', line 43

def test_get_doctor_data
  DoctorPlugin::PARSER.__next(:doc_data_add_ean) { |arg|
    assert_equal(5, arg)
  }
  @plugin.get_doctor_data(5)
end

- (Object) test_merge_addresses



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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'test/test_plugin/zdoctor.rb', line 113

def test_merge_addresses
  input = [
    {
      :plz    =>  '6500',
      :city   => 'Bellinzona',
      :fon    =>  '091 811 91 11',
      :fax    =>  '091 811 91 60',
      :lines  => [
        'Ospedale San Giovanni',
        'Soleggio',
        '6500 Bellinzona',
        '',
      ],
    },
    {
      :plz    =>  '6597',
      :city   =>  'Agarone',
      :fon    =>  '092 64 11 41',
      :fax    =>  '',
      :lines  => [
        'Clinica Sassariente',
        '6597 Agarone',
        '',
      ],
    },
    {
      :plz    =>  '6500',
      :city   =>  'Bellinzona',
      :fon    =>  '091 811 91 09',
      :fax    =>  '091 811 87 99',
      :lines  => [
        "Ospedale San Giovanni",
        "Soleggio",
        "6500 Bellinzona",
        "",
      ],
    },
    {
      :plz    =>  '6500',
      :city   =>  'Bellinzona',
      :fon    =>  '091 811 91 11',
      :fax    =>  '',
      :lines  => [
        "Ospedale San Giovanni",
        "Soleggio",
        "6500 Bellinzona",
        "",
      ],
    },
  ]
  expected = [
    {
      :plz    =>  '6500',
      :city   => 'Bellinzona',
      :fon    =>  [
        '091 811 91 11',
        '091 811 91 09',
      ],
      :fax    =>  [
        '091 811 91 60',
        '091 811 87 99',
      ],
      :lines  => [
        'Ospedale San Giovanni',
        'Soleggio',
        '6500 Bellinzona',
        '',
      ],
    },
    {
      :plz    =>  '6597',
      :city   =>  'Agarone',
      :fon    =>  ['092 64 11 41'],
      :fax    =>  [],
      :lines  => [
        'Clinica Sassariente',
        '6597 Agarone',
        '',
      ],
    },
  ]
  result = @plugin.merge_addresses(input)
  assert_equal(expected, result)
end

- (Object) test_prepare_addresses



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'test/test_plugin/zdoctor.rb', line 197

def test_prepare_addresses
  input = {
    :addresses =>  {
      :plz    =>  '6500',
      :city   =>  'Bellinzona',
      :fon    =>  '091 811 91 09',
      :fax    =>  '091 811 87 99',
      :lines  => [
        "Ospedale San Giovanni",
        "Soleggio",
        "6500 Bellinzona",
        "",
      ],
      :type => :work,
    }
  }
  result = nil
  assert_nothing_raised {
    result = @plugin.prepare_addresses(input)
  }
  assert_instance_of(Array, result)
  assert_equal(1, result.size)
  addr = result.first
  assert_equal('6500', addr.plz)
  assert_equal('Bellinzona', addr.city)
  assert_equal(['091 811 91 09'], addr.fon)
  assert_equal(['091 811 87 99'], addr.fax)
  assert_equal(:work, addr.type)
end

- (Object) test_prepare_addresses__2



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'test/test_plugin/zdoctor.rb', line 226

def test_prepare_addresses__2
  input = {
    :addresses =>  [
      {
        :plz   =>  '6500',
        :city   =>  'Bellinzona',
        :fax    =>  '',
        :fon   => '091 820 91 11',
        :lines =>  [
          'Egregio Prof.',
          'Claudio Marone',
          'Studio medico',
          'Ospedale San Giovanni',
          '6500 Bellinzona',
          '',
        ],
        :type  => :praxis,
      },
      {
        :plz   =>  '6500',
        :city   =>  'Bellinzona',
        :fon   => '091 811 91 09',
        :fax    =>  '091 811 87 99',
        :lines  => [
          "Ospedale San Giovanni",
          "Soleggio",
          "6500 Bellinzona",
          "",
        ],
        :type  => :work,
      },
    ]
  }
  result = nil
  assert_nothing_raised {
    result = @plugin.prepare_addresses(input)
  }
  assert_instance_of(Array, result)
  assert_equal(2, result.size)
  assert_equal(:praxis, result.first.type)
  assert_equal(:work, result.last.type)
end

- (Object) test_store_doctor



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
# File 'test/test_plugin/zdoctor.rb', line 49

def test_store_doctor
  doc_id = 14478
  @app.__next(:doctor_by_origin) { |origin_db, origin_id| 
    assert_equal(:ch, origin_db)
    assert_equal(14478, origin_id)
    nil
  }
  doctor = Mock.new('Doctor')
  doctor.__next(:pointer) { 'docpointer' }
  @app.__next(:update) { |pointer, update_hash|
    test_p = Persistence::Pointer.new(:doctor)
    expected = {
      :exam       => '1970',
      :firstname  => 'Happy Camper',
      :language   => 'deutsch',
      :name       => 'Testdoctor',
      :addresses  =>  [],
      :praxis     =>  true,
      :specialities =>  ["GrossLap Medizin"], 
      #:abilities   => ["Mangel- und Seisemedizin"], 
      #:skills      => ["SuperLabor RTZ"],
      :title      => 'Dr. med.',
      :salutation =>  'Herrn',
      :origin_id  => 14478,
      :origin_db  => :ch,
    }  
    assert_equal(expected, update_hash)
    assert_equal(test_p.creator, pointer)
    doctor
  }
  res = @plugin.store_doctor(doc_id, @hash)
  assert_equal(doctor, res)
end

- (Object) test_store_doctor__update



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
# File 'test/test_plugin/zdoctor.rb', line 82

def test_store_doctor__update
  doc_id = 14478
  doctor = Mock.new('Doctor')
  @app.__next(:doctor_by_origin) { |origin, origin_id| 
    assert_equal(:ch, origin)
    assert_equal(14478, origin_id)
    doctor
  }
  doctor.__next(:pointer) { 'docpointer' }
  @app.__next(:update) { |pointer, update_hash|
    expected = {
      :exam       => '1970',
      :title      => 'Dr. med.',
      :salutation =>  'Herrn',
      :title      =>"Dr. med.", 
      :language   =>"deutsch", 
      :addresses  => [],
      :specialities =>  ["GrossLap Medizin"], 
      :praxis     => true, 
      :firstname  => "Happy Camper", 
      :name       => "Testdoctor", 
      :origin_id  => 14478,
      #:abilities   => ["Mangel- und Seisemedizin"], 
      :origin_db  => :ch,
      #:skills      => ["SuperLabor RTZ"],         
    }  
    assert_equal(expected, update_hash)
    assert_equal('docpointer', pointer)
  }
  @plugin.store_doctor(doc_id, @hash)
end