Class: ODDB::State::Drugs::TestFachinfoConfirmState

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_state/drugs/fachinfoconfirm.rb

Defined Under Namespace

Classes: StubApp, StubFachinfo, StubFachinfoDocument, StubRegistration, StubSession

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



74
75
76
77
78
79
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 74

def setup
  @session = StubSession.new
  @app = StubApp.new
  @session.app = @app
  @state = State::Drugs::FachinfoConfirm.new(@session, []) 
end

- (Object) test_iksnrs1



152
153
154
155
156
157
158
159
160
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 152

def test_iksnrs1
  doc = StubFachinfoDocument.new('12345,67890, 54321')
  expected = [
    '12345',
    '67890',
    '54321',
  ]
  assert_equal(expected, @state.iksnrs(doc))
end

- (Object) test_iksnrs2



161
162
163
164
165
166
167
168
169
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 161

def test_iksnrs2
  doc = StubFachinfoDocument.new('2345,7890, 4321')
  expected = [
    '02345',
    '07890',
    '04321',
  ]
  assert_equal(expected, @state.iksnrs(doc))
end

- (Object) test_iksnrs3



170
171
172
173
174
175
176
177
178
179
180
181
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 170

def test_iksnrs3
  chapter = ODDB::Text::Chapter.new
  section = chapter.next_section  
  section.subheading = "2345,7890, 4'321"
  doc = StubFachinfoDocument.new(section)
  expected = [
    '02345',
    '07890',
    '04321',
  ]
  assert_equal(expected, @state.iksnrs(doc))
end

- (Object) test_iksnrs4



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 182

def test_iksnrs4
  chapter = ODDB::Text::Chapter.new
  section = chapter.next_section  
  paragraph = section.next_paragraph
  paragraph << "2345,7890, 4'321"
  doc = StubFachinfoDocument.new(section)
  expected = [
    '02345',
    '07890',
    '04321',
  ]
  assert_equal(expected, @state.iksnrs(doc))
end

- (Object) test_update1



195
196
197
198
199
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 195

def test_update1
  newstate = @state.update
  assert(@state.error?, "No error condition!")
  assert_equal(@state, newstate)
end

- (Object) test_update2



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
226
227
228
229
230
231
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 200

def test_update2
  fi_doc1 = StubFachinfoDocument.new('98765, 12345')
  fi_doc2 = StubFachinfoDocument.new('98765, 12345')
  @state.model = [ fi_doc2, fi_doc1 ]
  @session.user_input = {
    :language_select =>  { "0"=>"fr", '1'=>'de' }
  }
  @session.user_equiv = true
  reg_pointer = Persistence::Pointer.new([:registration, '12345'])
  reg = StubRegistration.new
  reg.iksnr = '12345'
  reg.pointer = reg_pointer
  @app.registration = reg
  fi_pointer = Persistence::Pointer.new(:fachinfo)
  fachinfo = StubFachinfo.new
  fachinfo.pointer = fi_pointer
  @app.update_result = fachinfo
  @state.update
  assert_equal(false, @state.error?, @state.errors)
  pointers = @app.update_pointers
  assert_equal(1, pointers.size)    
  assert_equal(fi_pointer.creator, pointers.first)
  values = @app.update_values
  assert_equal(1, values.size)
  expected = {
    'de' =>  fi_doc1,
    'fr' =>  fi_doc2,
  }
  assert_equal(expected, values.first)
  assert_equal(["12345"], @app.replace_iksnrs)
  assert_equal([fi_pointer], @app.replace_pointers)
end

- (Object) test_validate_iksnrs1



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 80

def test_validate_iksnrs1
  # erkennt Registration nicht
  @state.model = [
    StubFachinfoDocument.new('1234567')
  ]
  @state.validate_iksnrs
  assert_equal([], @state.valid_iksnrs)
  assert_equal(1, @state.warnings.size)
  assert_equal(1, @state.errors.size)
  warn = @state.warnings.first
  assert_instance_of(SBSM::Warning, warn)
  assert_equal(:w_unknown_iksnr, warn.message)
  err = @state.error(:iksnrs)
  assert_instance_of(SBSM::ProcessingError, err)
  assert_equal('e_no_valid_iksnrs', err.message)
end

- (Object) test_validate_iksnrs2



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 96

def test_validate_iksnrs2
  # erkennt Registration
  # nicht berechtigt
  reg = StubRegistration.new
  reg.iksnr = '1234567'
  @app.registration = reg
  @state.model = [
    StubFachinfoDocument.new('1234567')
  ]
  @state.validate_iksnrs
  assert_equal([], @state.valid_iksnrs)
  assert_equal(1, @state.warnings.size)
  assert_equal(1, @state.errors.size)
  warn = @state.warnings.first
  assert_instance_of(SBSM::Warning, warn)
  assert_equal(:w_access_denied_iksnr, warn.message)
  err = @state.error(:iksnrs)
  assert_instance_of(SBSM::ProcessingError, err)
  assert_equal('e_no_valid_iksnrs', err.message)
end

- (Object) test_validate_iksnrs3



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 116

def test_validate_iksnrs3
  # erkennt Registration
  # berechtigt
  reg = StubRegistration.new
  reg.iksnr = '12345'
  @app.registration = reg
  @session.user_equiv = true
  @state.model = [
    StubFachinfoDocument.new('12345'),
    StubFachinfoDocument.new('12345'),
  ]
  @state.validate_iksnrs
  assert_equal(['12345'], @state.valid_iksnrs)
  assert_equal(false, @state.warning?)
  assert_equal(false, @state.error?)
end

- (Object) test_validate_iksnrs4



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'test/test_state/drugs/fachinfoconfirm.rb', line 132

def test_validate_iksnrs4
  # erkennt Registration
  # nicht berechtigt
  reg = StubRegistration.new
  reg.iksnr = '12345'
  @app.registration = reg
  @session.user_equiv = true
  @state.model = [
    StubFachinfoDocument.new('1234567,12345')
  ]
  @state.validate_iksnrs
  assert_equal(['12345'], @state.valid_iksnrs)
  assert_equal(1, @state.warnings.size)
  assert_equal(0, @state.errors.size)
  warn = @state.warnings.first
  assert_instance_of(SBSM::Warning, warn)
  assert_equal(:w_unknown_iksnr, warn.message)
  assert_equal(true, @state.warning?)
  assert_equal(false, @state.error?)
end