|
215 | 215 | "type" => my_type |
216 | 216 | } |
217 | 217 | end |
| 218 | + let :my_incomplete_struct_v1 do |
| 219 | + { |
| 220 | + "data" => my_json_data, |
| 221 | + "datacontenttype" => my_content_type_string, |
| 222 | + "dataschema" => nil, |
| 223 | + "id" => my_id, |
| 224 | + "source" => my_source_string, |
| 225 | + "specversion" => spec_version_v1, |
| 226 | + "time" => nil, |
| 227 | + "type" => my_type |
| 228 | + } |
| 229 | + end |
218 | 230 | let(:my_json_struct_v1_string) { JSON.dump my_json_struct_v1 } |
219 | 231 | let(:my_batch_v1_string) { JSON.dump [my_base64_struct_v1, my_json_struct_v1] } |
| 232 | + let :my_compacted_incomplete_struct_v1 do |
| 233 | + my_incomplete_struct_v1.delete_if { |_k, v| v.nil? } |
| 234 | + end |
220 | 235 |
|
221 | 236 | it "decodes and encodes a struct with string data" do |
222 | 237 | event = json_format.decode_hash_structure my_string_struct_v1 |
|
304 | 319 | string = json_format.encode_batch events, sort: true |
305 | 320 | assert_equal my_batch_v1_string, string |
306 | 321 | end |
| 322 | + |
| 323 | + it "decodes and encodes json with nulls" do |
| 324 | + event = json_format.decode_hash_structure my_incomplete_struct_v1 |
| 325 | + assert_equal my_id, event.id |
| 326 | + assert_equal my_source, event.source |
| 327 | + assert_equal my_type, event.type |
| 328 | + assert_equal spec_version_v1, event.spec_version |
| 329 | + assert_equal my_json_data, event.data |
| 330 | + assert_equal my_content_type, event.data_content_type |
| 331 | + assert_nil event.data_schema |
| 332 | + assert_nil event.subject |
| 333 | + assert_nil event.time |
| 334 | + hash = event.to_h |
| 335 | + refute hash.include? "subject" |
| 336 | + refute hash.include? "time" |
| 337 | + struct = json_format.encode_hash_structure event |
| 338 | + assert_equal my_compacted_incomplete_struct_v1, struct |
| 339 | + end |
307 | 340 | end |
308 | 341 | end |
0 commit comments