Debian Codegraph @

src/filter/entity_search_results.rs

raw
1 //! Entity search results filter implementation.
2 //!
3 //! Extracts fields from [`crate::response::EntitySearchResults`] RDAP objects.
4 //! Values are aggregated across all search results into arrays.
5 //!
6 //! # Supported Filters
7 //!
8 //! | Filter | Value Type | Description |
9 //! |---|---|---|
10 //! | `Handle` | `StringArray` | Handles from all results |
11 //! | `Status` | `StringArray` | Statuses from all results |
12 //! | `ObjectClassName` | `StringArray` | Object class names from all results |
13 //! | `Event` | `HashMapVal` | Events aggregated from all results |
14 //! | `RdapConformance` | `StringArray` | Conformance URIs from all results |
15 //! | `Role` | `StringArray` | Roles from all results |
16 //! | `Email` | `StringArray` | Email addresses from all results |
17 //! | `FullName` | `StringArray` | Full names from all results |
18 //! | `PublicId` | `HashMapVal` | Public IDs aggregated from all results |
19 //! | `Voice` | `StringArray` | Phone numbers from all results |
20 //! | `Fax` | `StringArray` | Fax numbers from all results |
21 //! | `ContactUri` | `StringArray` | Contact URIs from all results |
22 //! | `CountryName` | `StringArray` | Country names from all results |
23 //! | `CountryCode` | `StringArray` | Country codes from all results |
24 //! | Entity roles | `StringArray` | Role-based fields aggregated from all results |
25
26 use super::*;
27 use crate::response::{CommonFields, EntitySearchResults, ObjectCommonFields};
28
29 impl Filterable for EntitySearchResults {
30 fn filter(&self, filters: &[Filter]) -> FilterResult {
31 filters
32 .iter()
33 .map(|f| match f {
34 Filter::Handle => FilterOutput {
35 filter: *f,
36 value: FilterValue::StringArray(
37 self.results()
38 .iter()
39 .filter_map(|e| e.handle())
40 .map(|h| h.to_string())
41 .collect(),
42 ),
43 },
44 Filter::Status => FilterOutput {
45 filter: *f,
46 value: FilterValue::StringArray(
47 self.results()
48 .iter()
49 .flat_map(|e| e.status())
50 .map(|s| s.to_string())
51 .collect(),
52 ),
53 },
54 Filter::ObjectClassName => FilterOutput {
55 filter: *f,
56 value: FilterValue::StringArray(
57 self.results()
58 .iter()
59 .map(|e| e.object_class_name().to_string())
60 .collect(),
61 ),
62 },
63 Filter::Event => FilterOutput {
64 filter: *f,
65 value: FilterValue::HashMapVal(
66 self.results()
67 .iter()
68 .flat_map(|e| e.events())
69 .filter_map(|e| {
70 let action = e.event_action()?;
71 let date = e.event_date()?;
72 Some((action.to_string(), FilterValue::StringVal(date.to_string())))
73 })
74 .collect(),
75 ),
76 },
77 Filter::RdapConformance => FilterOutput {
78 filter: *f,
79 value: FilterValue::StringArray(
80 self.results()
81 .iter()
82 .filter_map(|e| e.common().rdap_conformance.as_ref())
83 .flatten()
84 .map(|ext| ext.0.clone())
85 .collect(),
86 ),
87 },
88 Filter::Role => FilterOutput {
89 filter: *f,
90 value: FilterValue::StringArray(
91 self.results()
92 .iter()
93 .flat_map(|e| e.roles())
94 .map(|r| r.to_string())
95 .collect(),
96 ),
97 },
98 Filter::Email => FilterOutput {
99 filter: *f,
100 value: FilterValue::StringArray(
101 self.results()
102 .iter()
103 .filter_map(|e| e.contact())
104 .flat_map(|c| {
105 let emails: Vec<String> =
106 c.emails().iter().map(|e| e.email().to_string()).collect();
107 emails
108 })
109 .collect(),
110 ),
111 },
112 Filter::FullName => FilterOutput {
113 filter: *f,
114 value: FilterValue::StringArray(
115 self.results()
116 .iter()
117 .filter_map(|e| e.contact())
118 .filter_map(|c| c.full_name().map(|n| n.to_string()))
119 .collect(),
120 ),
121 },
122 Filter::PublicId => FilterOutput {
123 filter: *f,
124 value: FilterValue::HashMapVal(
125 self.results()
126 .iter()
127 .flat_map(|e| e.public_ids())
128 .filter_map(|p| {
129 let id_type = p.id_type()?;
130 let identifier = p.identifier()?;
131 Some((
132 id_type.to_string(),
133 FilterValue::StringVal(identifier.to_string()),
134 ))
135 })
136 .collect(),
137 ),
138 },
139 Filter::Voice => FilterOutput {
140 filter: *f,
141 value: FilterValue::StringArray(
142 self.results()
143 .iter()
144 .filter_map(|e| e.contact())
145 .filter_map(|c| c.voice_phone().map(|p| p.phone().to_string()))
146 .collect(),
147 ),
148 },
149 Filter::Fax => FilterOutput {
150 filter: *f,
151 value: FilterValue::StringArray(
152 self.results()
153 .iter()
154 .filter_map(|e| e.contact())
155 .filter_map(|c| c.fax_phone().map(|p| p.phone().to_string()))
156 .collect(),
157 ),
158 },
159 Filter::ContactUri => FilterOutput {
160 filter: *f,
161 value: FilterValue::StringArray(
162 self.results()
163 .iter()
164 .filter_map(|e| e.contact())
165 .flat_map(|c| {
166 let uris: Vec<String> =
167 c.contact_uris().iter().map(|u| u.to_string()).collect();
168 uris
169 })
170 .collect(),
171 ),
172 },
173 Filter::CountryName => FilterOutput {
174 filter: *f,
175 value: FilterValue::StringArray(
176 self.results()
177 .iter()
178 .filter_map(|e| e.contact())
179 .flat_map(|c| {
180 let names: Vec<String> = c
181 .postal_addresses()
182 .iter()
183 .filter_map(|a| a.country_name())
184 .map(|n| n.to_string())
185 .collect();
186 names
187 })
188 .collect(),
189 ),
190 },
191 Filter::CountryCode => FilterOutput {
192 filter: *f,
193 value: FilterValue::StringArray(
194 self.results()
195 .iter()
196 .filter_map(|e| e.contact())
197 .flat_map(|c| {
198 let codes: Vec<String> = c
199 .postal_addresses()
200 .iter()
201 .filter_map(|a| a.country_code())
202 .map(|c| c.to_string())
203 .collect();
204 codes
205 })
206 .collect(),
207 ),
208 },
209 _ => entity_role_filter_output_search(self.results().iter(), *f),
210 })
211 .collect()
212 }
213 }
214
215 #[cfg(test)]
216 mod tests {
217 use super::*;
218 use crate::contact::Contact;
219 use crate::prelude::{Email, Event, ExtensionId};
220 use crate::response::Entity as EntityType;
221
222 fn make_test_entity_1() -> Entity {
223 let contact = Contact::builder()
224 .full_name("Entity One")
225 .emails(vec![Email::builder().email("[email protected]").build()])
226 .build();
227
228 let child_registrant_contact = Contact::builder()
229 .full_name("Child Registrant One")
230 .emails(vec![
231 Email::builder().email("[email protected]").build(),
232 ])
233 .build();
234 let child_abuse_contact = Contact::builder()
235 .full_name("Child Abuse One")
236 .emails(vec![
237 Email::builder().email("[email protected]").build(),
238 ])
239 .build();
240 let child_tech_contact = Contact::builder()
241 .full_name("Child Tech One")
242 .emails(vec![
243 Email::builder().email("[email protected]").build(),
244 ])
245 .build();
246 let child_registrar_contact = Contact::builder()
247 .full_name("Child Registrar One")
248 .emails(vec![
249 Email::builder().email("[email protected]").build(),
250 ])
251 .build();
252
253 let child_registrant = EntityType::response_obj()
254 .handle("CHILD-REGISTRANT-1")
255 .role("registrant")
256 .contact(child_registrant_contact)
257 .build();
258 let child_abuse = EntityType::response_obj()
259 .handle("CHILD-ABUSE-1")
260 .role("abuse")
261 .contact(child_abuse_contact)
262 .build();
263 let child_tech = EntityType::response_obj()
264 .handle("CHILD-TECH-1")
265 .role("technical")
266 .contact(child_tech_contact)
267 .build();
268 let child_registrar = EntityType::response_obj()
269 .handle("CHILD-REGISTRAR-1")
270 .role("registrar")
271 .contact(child_registrar_contact)
272 .build();
273
274 EntityType::response_obj()
275 .handle("ENTITY-ONE")
276 .role("admin")
277 .contact(contact)
278 .statuses(vec!["active".to_string()])
279 .entity(child_registrant)
280 .entity(child_abuse)
281 .entity(child_tech)
282 .entity(child_registrar)
283 .event(
284 Event::builder()
285 .event_action("last changed")
286 .event_date("2021-06-15T00:00:00Z")
287 .build(),
288 )
289 .build()
290 }
291
292 fn make_test_entity_2() -> Entity {
293 let contact = Contact::builder()
294 .full_name("Entity Two")
295 .emails(vec![Email::builder().email("[email protected]").build()])
296 .build();
297
298 let child_registrant_contact = Contact::builder()
299 .full_name("Child Registrant Two")
300 .emails(vec![
301 Email::builder().email("[email protected]").build(),
302 ])
303 .build();
304 let child_abuse_contact = Contact::builder()
305 .full_name("Child Abuse Two")
306 .emails(vec![
307 Email::builder().email("[email protected]").build(),
308 ])
309 .build();
310 let child_tech_contact = Contact::builder()
311 .full_name("Child Tech Two")
312 .emails(vec![
313 Email::builder().email("[email protected]").build(),
314 ])
315 .build();
316 let child_registrar_contact = Contact::builder()
317 .full_name("Child Registrar Two")
318 .emails(vec![
319 Email::builder().email("[email protected]").build(),
320 ])
321 .build();
322
323 let child_registrant = EntityType::response_obj()
324 .handle("CHILD-REGISTRANT-2")
325 .role("registrant")
326 .contact(child_registrant_contact)
327 .build();
328 let child_abuse = EntityType::response_obj()
329 .handle("CHILD-ABUSE-2")
330 .role("abuse")
331 .contact(child_abuse_contact)
332 .build();
333 let child_tech = EntityType::response_obj()
334 .handle("CHILD-TECH-2")
335 .role("technical")
336 .contact(child_tech_contact)
337 .build();
338 let child_registrar = EntityType::response_obj()
339 .handle("CHILD-REGISTRAR-2")
340 .role("registrar")
341 .contact(child_registrar_contact)
342 .build();
343
344 EntityType::response_obj()
345 .handle("ENTITY-TWO")
346 .role("admin")
347 .contact(contact)
348 .statuses(vec![
349 "active".to_string(),
350 "clientDeleteProhibited".to_string(),
351 ])
352 .entity(child_registrant)
353 .entity(child_abuse)
354 .entity(child_tech)
355 .entity(child_registrar)
356 .event(
357 Event::builder()
358 .event_action("registration")
359 .event_date("2022-03-10T08:00:00Z")
360 .build(),
361 )
362 .build()
363 }
364
365 fn make_test_entity_search_results() -> EntitySearchResults {
366 let extensions = vec![
367 ExtensionId::RdapLevel0.to_extension(),
368 ExtensionId::IcannRdapResponseProfile1.to_extension(),
369 ];
370 EntitySearchResults::response_obj()
371 .results(vec![make_test_entity_1(), make_test_entity_2()])
372 .extensions(extensions)
373 .build()
374 }
375
376 #[test]
377 fn filter_handle() {
378 // GIVEN
379 let search_results = make_test_entity_search_results();
380 let filters = vec![Filter::Handle];
381
382 // WHEN
383 let results = extract(&search_results, &filters);
384
385 // THEN
386 assert_eq!(results.len(), 1);
387 assert_eq!(results[0].filter, Filter::Handle);
388 match &results[0].value {
389 FilterValue::StringArray(s) => {
390 assert_eq!(s.len(), 2);
391 assert!(s.contains(&"ENTITY-ONE".to_string()));
392 assert!(s.contains(&"ENTITY-TWO".to_string()));
393 }
394 _ => panic!("Expected StringArray"),
395 }
396 }
397
398 #[test]
399 fn filter_status() {
400 // GIVEN
401 let search_results = make_test_entity_search_results();
402 let filters = vec![Filter::Status];
403
404 // WHEN
405 let results = extract(&search_results, &filters);
406
407 // THEN
408 assert_eq!(results.len(), 1);
409 assert_eq!(results[0].filter, Filter::Status);
410 match &results[0].value {
411 FilterValue::StringArray(s) => {
412 assert!(s.len() >= 2);
413 assert!(s.contains(&"active".to_string()));
414 assert!(s.contains(&"clientDeleteProhibited".to_string()));
415 }
416 _ => panic!("Expected StringArray"),
417 }
418 }
419
420 #[test]
421 fn filter_object_class_name() {
422 // GIVEN
423 let search_results = make_test_entity_search_results();
424 let filters = vec![Filter::ObjectClassName];
425
426 // WHEN
427 let results = extract(&search_results, &filters);
428
429 // THEN
430 assert_eq!(results.len(), 1);
431 assert_eq!(results[0].filter, Filter::ObjectClassName);
432 match &results[0].value {
433 FilterValue::StringArray(s) => {
434 assert_eq!(s.len(), 2);
435 assert!(s.contains(&"entity".to_string()));
436 }
437 _ => panic!("Expected StringArray"),
438 }
439 }
440
441 #[test]
442 fn filter_event() {
443 // GIVEN
444 let search_results = make_test_entity_search_results();
445 let filters = vec![Filter::Event];
446
447 // WHEN
448 let results = extract(&search_results, &filters);
449
450 // THEN
451 assert_eq!(results.len(), 1);
452 assert_eq!(results[0].filter, Filter::Event);
453 match &results[0].value {
454 FilterValue::HashMapVal(hm) => {
455 assert_eq!(hm.len(), 2);
456 assert!(hm.contains_key("last changed"));
457 assert!(hm.contains_key("registration"));
458 }
459 _ => panic!("Expected HashMapVal"),
460 }
461 }
462
463 #[test]
464 fn filter_rdap_conformance() {
465 // GIVEN
466 let search_results = make_test_entity_search_results();
467 let filters = vec![Filter::RdapConformance];
468
469 // WHEN
470 let results = extract(&search_results, &filters);
471
472 // THEN
473 assert_eq!(results.len(), 1);
474 assert_eq!(results[0].filter, Filter::RdapConformance);
475 match &results[0].value {
476 FilterValue::StringArray(s) => {
477 // rdap_level_0 comes from Common::level0() used by Entity::response_obj()
478 assert!(s.contains(&"rdap_level_0".to_string()));
479 }
480 _ => panic!("Expected StringArray"),
481 }
482 }
483
484 #[test]
485 fn filter_role() {
486 // GIVEN
487 let search_results = make_test_entity_search_results();
488 let filters = vec![Filter::Role];
489
490 // WHEN
491 let results = extract(&search_results, &filters);
492
493 // THEN
494 assert_eq!(results.len(), 1);
495 assert_eq!(results[0].filter, Filter::Role);
496 match &results[0].value {
497 FilterValue::StringArray(s) => {
498 // Top-level entities have role "admin"
499 assert!(s.contains(&"admin".to_string()));
500 }
501 _ => panic!("Expected StringArray"),
502 }
503 }
504
505 #[test]
506 fn filter_voice() {
507 // GIVEN
508 let search_results = make_test_entity_search_results();
509 let filters = vec![Filter::Voice];
510
511 // WHEN
512 let results = extract(&search_results, &filters);
513
514 // THEN
515 assert_eq!(results.len(), 1);
516 assert_eq!(results[0].filter, Filter::Voice);
517 // Entity One and Two have no voice phone, so should be empty
518 match &results[0].value {
519 FilterValue::StringArray(s) => {
520 assert_eq!(s.len(), 0);
521 }
522 _ => panic!("Expected StringArray"),
523 }
524 }
525
526 #[test]
527 fn filter_fax() {
528 // GIVEN
529 let search_results = make_test_entity_search_results();
530 let filters = vec![Filter::Fax];
531
532 // WHEN
533 let results = extract(&search_results, &filters);
534
535 // THEN
536 assert_eq!(results.len(), 1);
537 assert_eq!(results[0].filter, Filter::Fax);
538 // Entity One and Two have no fax phone, so should be empty
539 match &results[0].value {
540 FilterValue::StringArray(s) => {
541 assert_eq!(s.len(), 0);
542 }
543 _ => panic!("Expected StringArray"),
544 }
545 }
546
547 #[test]
548 fn filter_contact_uri() {
549 // GIVEN
550 let search_results = make_test_entity_search_results();
551 let filters = vec![Filter::ContactUri];
552
553 // WHEN
554 let results = extract(&search_results, &filters);
555
556 // THEN
557 assert_eq!(results.len(), 1);
558 assert_eq!(results[0].filter, Filter::ContactUri);
559 // Entity One and Two have no contact URIs, so should be empty
560 match &results[0].value {
561 FilterValue::StringArray(s) => {
562 assert_eq!(s.len(), 0);
563 }
564 _ => panic!("Expected StringArray"),
565 }
566 }
567
568 #[test]
569 fn filter_country_name() {
570 // GIVEN
571 let search_results = make_test_entity_search_results();
572 let filters = vec![Filter::CountryName];
573
574 // WHEN
575 let results = extract(&search_results, &filters);
576
577 // THEN
578 assert_eq!(results.len(), 1);
579 assert_eq!(results[0].filter, Filter::CountryName);
580 // Entity One and Two have no postal addresses, so should be empty
581 match &results[0].value {
582 FilterValue::StringArray(s) => {
583 assert_eq!(s.len(), 0);
584 }
585 _ => panic!("Expected StringArray"),
586 }
587 }
588
589 #[test]
590 fn filter_country_code() {
591 // GIVEN
592 let search_results = make_test_entity_search_results();
593 let filters = vec![Filter::CountryCode];
594
595 // WHEN
596 let results = extract(&search_results, &filters);
597
598 // THEN
599 assert_eq!(results.len(), 1);
600 assert_eq!(results[0].filter, Filter::CountryCode);
601 // Entity One and Two have no postal addresses, so should be empty
602 match &results[0].value {
603 FilterValue::StringArray(s) => {
604 assert_eq!(s.len(), 0);
605 }
606 _ => panic!("Expected StringArray"),
607 }
608 }
609
610 #[test]
611 fn filter_email() {
612 // GIVEN
613 let search_results = make_test_entity_search_results();
614 let filters = vec![Filter::Email];
615
616 // WHEN
617 let results = extract(&search_results, &filters);
618
619 // THEN
620 assert_eq!(results.len(), 1);
621 assert_eq!(results[0].filter, Filter::Email);
622 match &results[0].value {
623 FilterValue::StringArray(s) => {
624 assert_eq!(s.len(), 2);
625 assert!(s.contains(&"[email protected]".to_string()));
626 assert!(s.contains(&"[email protected]".to_string()));
627 }
628 _ => panic!("Expected StringArray"),
629 }
630 }
631
632 #[test]
633 fn filter_full_name() {
634 // GIVEN
635 let search_results = make_test_entity_search_results();
636 let filters = vec![Filter::FullName];
637
638 // WHEN
639 let results = extract(&search_results, &filters);
640
641 // THEN
642 assert_eq!(results.len(), 1);
643 assert_eq!(results[0].filter, Filter::FullName);
644 match &results[0].value {
645 FilterValue::StringArray(s) => {
646 assert_eq!(s.len(), 2);
647 assert!(s.contains(&"Entity One".to_string()));
648 assert!(s.contains(&"Entity Two".to_string()));
649 }
650 _ => panic!("Expected StringArray"),
651 }
652 }
653
654 #[test]
655 fn filter_registrant_email() {
656 // GIVEN
657 let search_results = make_test_entity_search_results();
658 let filters = vec![Filter::RegistrantEmail];
659
660 // WHEN
661 let results = extract(&search_results, &filters);
662
663 // THEN
664 assert_eq!(results.len(), 1);
665 assert_eq!(results[0].filter, Filter::RegistrantEmail);
666 match &results[0].value {
667 FilterValue::StringArray(s) => {
668 assert_eq!(s.len(), 2);
669 assert!(s.contains(&"[email protected]".to_string()));
670 assert!(s.contains(&"[email protected]".to_string()));
671 }
672 _ => panic!("Expected StringArray"),
673 }
674 }
675
676 #[test]
677 fn filter_registrant_full_name() {
678 // GIVEN
679 let search_results = make_test_entity_search_results();
680 let filters = vec![Filter::RegistrantFullName];
681
682 // WHEN
683 let results = extract(&search_results, &filters);
684
685 // THEN
686 assert_eq!(results.len(), 1);
687 assert_eq!(results[0].filter, Filter::RegistrantFullName);
688 match &results[0].value {
689 FilterValue::StringArray(s) => {
690 assert_eq!(s.len(), 2);
691 assert!(s.contains(&"Child Registrant One".to_string()));
692 assert!(s.contains(&"Child Registrant Two".to_string()));
693 }
694 _ => panic!("Expected StringArray"),
695 }
696 }
697
698 #[test]
699 fn filter_abuse_email() {
700 // GIVEN
701 let search_results = make_test_entity_search_results();
702 let filters = vec![Filter::AbuseEmail];
703
704 // WHEN
705 let results = extract(&search_results, &filters);
706
707 // THEN
708 assert_eq!(results.len(), 1);
709 assert_eq!(results[0].filter, Filter::AbuseEmail);
710 match &results[0].value {
711 FilterValue::StringArray(s) => {
712 assert_eq!(s.len(), 2);
713 assert!(s.contains(&"[email protected]".to_string()));
714 assert!(s.contains(&"[email protected]".to_string()));
715 }
716 _ => panic!("Expected StringArray"),
717 }
718 }
719
720 #[test]
721 fn filter_abuse_full_name() {
722 // GIVEN
723 let search_results = make_test_entity_search_results();
724 let filters = vec![Filter::AbuseFullName];
725
726 // WHEN
727 let results = extract(&search_results, &filters);
728
729 // THEN
730 assert_eq!(results.len(), 1);
731 assert_eq!(results[0].filter, Filter::AbuseFullName);
732 match &results[0].value {
733 FilterValue::StringArray(s) => {
734 assert_eq!(s.len(), 2);
735 assert!(s.contains(&"Child Abuse One".to_string()));
736 assert!(s.contains(&"Child Abuse Two".to_string()));
737 }
738 _ => panic!("Expected StringArray"),
739 }
740 }
741
742 #[test]
743 fn filter_technical_email() {
744 // GIVEN
745 let search_results = make_test_entity_search_results();
746 let filters = vec![Filter::TechnicalEmail];
747
748 // WHEN
749 let results = extract(&search_results, &filters);
750
751 // THEN
752 assert_eq!(results.len(), 1);
753 assert_eq!(results[0].filter, Filter::TechnicalEmail);
754 match &results[0].value {
755 FilterValue::StringArray(s) => {
756 assert_eq!(s.len(), 2);
757 assert!(s.contains(&"[email protected]".to_string()));
758 assert!(s.contains(&"[email protected]".to_string()));
759 }
760 _ => panic!("Expected StringArray"),
761 }
762 }
763
764 #[test]
765 fn filter_technical_full_name() {
766 // GIVEN
767 let search_results = make_test_entity_search_results();
768 let filters = vec![Filter::TechnicalFullName];
769
770 // WHEN
771 let results = extract(&search_results, &filters);
772
773 // THEN
774 assert_eq!(results.len(), 1);
775 assert_eq!(results[0].filter, Filter::TechnicalFullName);
776 match &results[0].value {
777 FilterValue::StringArray(s) => {
778 assert_eq!(s.len(), 2);
779 assert!(s.contains(&"Child Tech One".to_string()));
780 assert!(s.contains(&"Child Tech Two".to_string()));
781 }
782 _ => panic!("Expected StringArray"),
783 }
784 }
785
786 #[test]
787 fn filter_registrar_email() {
788 // GIVEN
789 let search_results = make_test_entity_search_results();
790 let filters = vec![Filter::RegistrarEmail];
791
792 // WHEN
793 let results = extract(&search_results, &filters);
794
795 // THEN
796 assert_eq!(results.len(), 1);
797 assert_eq!(results[0].filter, Filter::RegistrarEmail);
798 match &results[0].value {
799 FilterValue::StringArray(s) => {
800 assert_eq!(s.len(), 2);
801 assert!(s.contains(&"[email protected]".to_string()));
802 assert!(s.contains(&"[email protected]".to_string()));
803 }
804 _ => panic!("Expected StringArray"),
805 }
806 }
807
808 #[test]
809 fn filter_registrar_full_name() {
810 // GIVEN
811 let search_results = make_test_entity_search_results();
812 let filters = vec![Filter::RegistrarFullName];
813
814 // WHEN
815 let results = extract(&search_results, &filters);
816
817 // THEN
818 assert_eq!(results.len(), 1);
819 assert_eq!(results[0].filter, Filter::RegistrarFullName);
820 match &results[0].value {
821 FilterValue::StringArray(s) => {
822 assert_eq!(s.len(), 2);
823 assert!(s.contains(&"Child Registrar One".to_string()));
824 assert!(s.contains(&"Child Registrar Two".to_string()));
825 }
826 _ => panic!("Expected StringArray"),
827 }
828 }
829
830 #[test]
831 fn filter_unknown_returns_null() {
832 // GIVEN
833 let search_results = make_test_entity_search_results();
834 let filters = vec![Filter::LdhName];
835
836 // WHEN
837 let results = extract(&search_results, &filters);
838
839 // THEN
840 assert_eq!(results.len(), 1);
841 assert_eq!(results[0].filter, Filter::LdhName);
842 assert_eq!(results[0].value, FilterValue::Null);
843 }
844
845 #[test]
846 fn filter_multiple_filters_at_once() {
847 // GIVEN
848 let search_results = make_test_entity_search_results();
849 let filters = vec![
850 Filter::Handle,
851 Filter::Status,
852 Filter::ObjectClassName,
853 Filter::Role,
854 Filter::RegistrantEmail,
855 Filter::AbuseEmail,
856 Filter::TechnicalEmail,
857 Filter::RegistrarEmail,
858 ];
859
860 // WHEN
861 let results = extract(&search_results, &filters);
862
863 // THEN
864 assert_eq!(results.len(), 8);
865 assert_eq!(results[0].filter, Filter::Handle);
866 assert_eq!(results[1].filter, Filter::Status);
867 assert_eq!(results[2].filter, Filter::ObjectClassName);
868 assert_eq!(results[3].filter, Filter::Role);
869 assert_eq!(results[4].filter, Filter::RegistrantEmail);
870 assert_eq!(results[5].filter, Filter::AbuseEmail);
871 assert_eq!(results[6].filter, Filter::TechnicalEmail);
872 assert_eq!(results[7].filter, Filter::RegistrarEmail);
873 }
874 }