1include!(concat!(env!("OUT_DIR"), "/scopes.rs"));
2
3#[cfg(test)]
4pub(super) mod test {
5 use std::{collections::VecDeque, sync::OnceLock, time::Duration};
6
7 use tokio::sync::mpsc;
8
9 use crate::{
10 executor::{ExecutorExt, ReqwestClient},
11 models::{
12 AttackCode, FactionSelectionName, PersonalStatsCategoryEnum, PersonalStatsStatName,
13 UserListEnum,
14 },
15 };
16
17 use super::*;
18
19 static TICKETS: OnceLock<mpsc::Sender<mpsc::Sender<ReqwestClient>>> = OnceLock::new();
20
21 pub(crate) async fn test_client() -> ReqwestClient {
22 let (tx, mut rx) = mpsc::channel(1);
23
24 let ticket_tx = TICKETS
25 .get_or_init(|| {
26 let (tx, mut rx) = mpsc::channel(1);
27 std::thread::spawn(move || {
28 let mut queue = VecDeque::<mpsc::Sender<ReqwestClient>>::new();
29
30 let rt = tokio::runtime::Builder::new_current_thread()
31 .enable_time()
32 .build()
33 .unwrap();
34
35 rt.block_on(async move {
36 loop {
37 tokio::select! {
38 recv_result = rx.recv() => {
39 match recv_result {
40 Some(ticket) => queue.push_back(ticket),
41 None => break,
42 }
43 }
44 _ = tokio::time::sleep(Duration::from_secs(1)) => {
45 if let Some(next) = queue.pop_front() {
46 next.send(ReqwestClient::new(&std::env::var("API_KEY").unwrap())).await.unwrap()
47 }
48 }
49 }
50 }
51 });
52 });
53
54 tx
55 })
56 .clone();
57
58 ticket_tx.send(tx).await.unwrap();
59
60 rx.recv().await.unwrap()
61 }
62
63 #[tokio::test]
64 async fn faction() {
65 let client = test_client().await;
66
67 let r = client
68 .faction()
69 .for_selections(|b| {
70 b.selections([FactionSelectionName::Basic, FactionSelectionName::Balance])
71 })
72 .await
73 .unwrap();
74
75 r.faction_basic_response().unwrap();
76 }
77
78 #[tokio::test]
79 async fn faction_applications() {
80 let client = test_client().await;
81
82 let faction_scope = FactionScope(&client);
83
84 faction_scope.applications(|b| b).await.unwrap();
85 }
86
87 #[tokio::test]
88 async fn faction_attacks() {
89 let client = test_client().await;
90
91 let faction_scope = FactionScope(&client);
92
93 faction_scope.attacks(|b| b).await.unwrap();
94 }
95
96 #[tokio::test]
97 async fn faction_attacksfull() {
98 let client = test_client().await;
99
100 let faction_scope = FactionScope(&client);
101
102 faction_scope.attacksfull(|b| b).await.unwrap();
103 }
104
105 #[tokio::test]
106 async fn faction_balance() {
107 let client = test_client().await;
108
109 let faction_scope = FactionScope(&client);
110
111 faction_scope.balance(|b| b).await.unwrap();
112 }
113
114 #[tokio::test]
115 async fn faction_basic() {
116 let client = test_client().await;
117
118 let faction_scope = FactionScope(&client);
119
120 faction_scope.basic(|b| b).await.unwrap();
121 }
122
123 #[tokio::test]
124 async fn faction_basic_for_id() {
125 let client = test_client().await;
126
127 let faction_scope = FactionScope(&client);
128
129 faction_scope.basic_for_id(19.into(), |b| b).await.unwrap();
130 }
131
132 #[tokio::test]
133 async fn faction_chain() {
134 let client = test_client().await;
135
136 let faction_scope = FactionScope(&client);
137
138 faction_scope.chain(|b| b).await.unwrap();
139 }
140
141 #[tokio::test]
142 async fn faction_chain_for_id() {
143 let client = test_client().await;
144
145 let faction_scope = FactionScope(&client);
146
147 faction_scope.chain_for_id(19.into(), |b| b).await.unwrap();
148 }
149
150 #[tokio::test]
151 async fn faction_chains() {
152 let client = test_client().await;
153
154 let faction_scope = FactionScope(&client);
155
156 faction_scope.chains(|b| b).await.unwrap();
157 }
158
159 #[tokio::test]
160 async fn factions_chains_for_id() {
161 let client = test_client().await;
162
163 let faction_scope = FactionScope(&client);
164
165 faction_scope.chains_for_id(19.into(), |b| b).await.unwrap();
166 }
167
168 #[tokio::test]
169 async fn faction_chain_report() {
170 let client = test_client().await;
171
172 let faction_scope = FactionScope(&client);
173
174 faction_scope.chainreport(|b| b).await.unwrap();
175 }
176
177 #[tokio::test]
178 async fn faction_chain_report_for_id() {
179 let client = test_client().await;
180
181 let faction_scope = FactionScope(&client);
182
183 faction_scope
184 .chainreport_for_chain_id(47004769.into(), |b| b)
185 .await
186 .unwrap();
187 }
188
189 #[tokio::test]
190 async fn faction_contributors() {
191 let client = test_client().await;
192
193 let faction_scope = FactionScope(&client);
194
195 faction_scope
196 .contributors(|b| b.stat(crate::models::FactionStatEnum::Revives))
197 .await
198 .unwrap();
199 }
200
201 #[tokio::test]
202 async fn faction_crimes() {
203 let client = test_client().await;
204
205 let faction_scope = FactionScope(&client);
206
207 faction_scope.crimes(|b| b).await.unwrap();
208 }
209
210 #[tokio::test]
211 async fn faction_crime_for_id() {
212 let client = test_client().await;
213
214 let faction_scope = FactionScope(&client);
215
216 faction_scope
217 .crime_for_crime_id(468347.into(), |b| b)
218 .await
219 .unwrap();
220 }
221
222 #[tokio::test]
223 async fn faction_hof() {
224 let client = test_client().await;
225
226 let faction_scope = FactionScope(&client);
227
228 faction_scope.hof(|b| b).await.unwrap();
229 }
230
231 #[tokio::test]
232 async fn faction_hof_for_id() {
233 let client = test_client().await;
234
235 let faction_scope = FactionScope(&client);
236
237 faction_scope.hof_for_id(19.into(), |b| b).await.unwrap();
238 }
239
240 #[tokio::test]
241 async fn faction_members() {
242 let client = test_client().await;
243
244 let faction_scope = FactionScope(&client);
245
246 faction_scope.members(|b| b).await.unwrap();
247 }
248
249 #[tokio::test]
250 async fn faction_members_for_id() {
251 let client = test_client().await;
252
253 let faction_scope = FactionScope(&client);
254
255 faction_scope
256 .members_for_id(19.into(), |b| b)
257 .await
258 .unwrap();
259 }
260
261 #[tokio::test]
262 async fn faction_news() {
263 let client = test_client().await;
264
265 let faction_scope = FactionScope(&client);
266
267 faction_scope
268 .news(|b| b.cat(crate::models::FactionNewsCategory::Attack))
269 .await
270 .unwrap();
271 }
272
273 #[tokio::test]
274 async fn faction_ranked_wars() {
275 let client = test_client().await;
276
277 let faction_scope = FactionScope(&client);
278
279 faction_scope.rankedwars(|b| b).await.unwrap();
280 }
281
282 #[tokio::test]
283 async fn faction_ranked_war_for_id() {
284 let client = test_client().await;
285
286 let faction_scope = FactionScope(&client);
287
288 faction_scope
289 .rankedwars_for_id(19.into(), |b| b)
290 .await
291 .unwrap();
292 }
293
294 #[tokio::test]
295 async fn faction_ranked_war_report_for_id() {
296 let client = test_client().await;
297
298 let faction_scope = FactionScope(&client);
299
300 faction_scope
301 .rankedwarreport_for_ranked_war_id(24424.into(), |b| b)
302 .await
303 .unwrap();
304 }
305
306 #[tokio::test]
307 async fn faction_revives() {
308 let client = test_client().await;
309
310 let faction_scope = FactionScope(&client);
311
312 faction_scope.revives(|b| b).await.unwrap();
313 }
314
315 #[tokio::test]
316 async fn faction_revives_full() {
317 let client = test_client().await;
318
319 let faction_scope = FactionScope(&client);
320
321 faction_scope.revives_full(|b| b).await.unwrap();
322 }
323
324 #[tokio::test]
325 async fn faction_stats() {
326 let client = test_client().await;
327
328 let faction_scope = FactionScope(&client);
329
330 faction_scope.stats(|b| b).await.unwrap();
331 }
332
333 #[tokio::test]
334 async fn faction_upgrades() {
335 let client = test_client().await;
336
337 let faction_scope = FactionScope(&client);
338
339 faction_scope.upgrades(|b| b).await.unwrap();
340 }
341
342 #[tokio::test]
343 async fn faction_wars() {
344 let client = test_client().await;
345
346 let faction_scope = FactionScope(&client);
347
348 faction_scope.wars(|b| b).await.unwrap();
349 }
350
351 #[tokio::test]
352 async fn faction_wars_for_id() {
353 let client = test_client().await;
354
355 let faction_scope = FactionScope(&client);
356
357 faction_scope.wars_for_id(19.into(), |b| b).await.unwrap();
358 }
359
360 #[tokio::test]
361 async fn faction_lookup() {
362 let client = test_client().await;
363
364 let faction_scope = FactionScope(&client);
365
366 faction_scope.lookup(|b| b).await.unwrap();
367 }
368
369 #[tokio::test]
370 async fn forum_categories() {
371 let client = test_client().await;
372
373 let forum_scope = ForumScope(&client);
374
375 forum_scope.categories(|b| b).await.unwrap();
376 }
377
378 #[tokio::test]
379 async fn forum_posts_for_thread_id() {
380 let client = test_client().await;
381
382 let forum_scope = ForumScope(&client);
383
384 forum_scope
385 .posts_for_thread_id(16129703.into(), |b| b)
386 .await
387 .unwrap();
388 }
389
390 #[tokio::test]
391 async fn forum_thread_for_thread_id() {
392 let client = test_client().await;
393
394 let forum_scope = ForumScope(&client);
395
396 forum_scope
397 .thread_for_thread_id(16129703.into(), |b| b)
398 .await
399 .unwrap();
400 }
401
402 #[tokio::test]
403 async fn forum_threads() {
404 let client = test_client().await;
405
406 let forum_scope = ForumScope(&client);
407
408 forum_scope.threads(|b| b).await.unwrap();
409 }
410
411 #[tokio::test]
412 async fn forum_threads_for_category_ids() {
413 let client = test_client().await;
414
415 let forum_scope = ForumScope(&client);
416
417 forum_scope
418 .threads_for_category_ids("2".to_owned(), |b| b)
419 .await
420 .unwrap();
421 }
422
423 #[tokio::test]
424 async fn forum_lookup() {
425 let client = test_client().await;
426
427 let forum_scope = ForumScope(&client);
428
429 forum_scope.lookup(|b| b).await.unwrap();
430 }
431
432 #[tokio::test]
433 async fn forum_timestamp() {
434 let client = test_client().await;
435
436 let forum_scope = ForumScope(&client);
437
438 forum_scope.timestamp(|b| b).await.unwrap();
439 }
440
441 #[tokio::test]
442 async fn market_itemmarket_for_id() {
443 let client = test_client().await;
444
445 let market_scope = MarketScope(&client);
446
447 market_scope
448 .itemmarket_for_id(1.into(), |b| b)
449 .await
450 .unwrap();
451 }
452
453 #[tokio::test]
454 async fn market_lookup() {
455 let client = test_client().await;
456
457 let market_scope = MarketScope(&client);
458
459 market_scope.lookup(|b| b).await.unwrap();
460 }
461
462 #[tokio::test]
463 async fn market_timestamp() {
464 let client = test_client().await;
465
466 let market_scope = MarketScope(&client);
467
468 market_scope.timestamp(|b| b).await.unwrap();
469 }
470
471 #[tokio::test]
472 async fn racing_cars() {
473 let client = test_client().await;
474
475 let racing_scope = RacingScope(&client);
476
477 racing_scope.cars(|b| b).await.unwrap();
478 }
479
480 #[tokio::test]
481 async fn racing_carupgrades() {
482 let client = test_client().await;
483
484 let racing_scope = RacingScope(&client);
485
486 racing_scope.carupgrades(|b| b).await.unwrap();
487 }
488
489 #[tokio::test]
490 async fn racing_races() {
491 let client = test_client().await;
492
493 let racing_scope = RacingScope(&client);
494
495 racing_scope.races(|b| b).await.unwrap();
496 }
497
498 #[tokio::test]
499 async fn racing_race_for_race_id() {
500 let client = test_client().await;
501
502 let racing_scope = RacingScope(&client);
503
504 racing_scope
505 .race_for_race_id(14650821.into(), |b| b)
506 .await
507 .unwrap();
508 }
509
510 #[tokio::test]
511 async fn racing_tracks() {
512 let client = test_client().await;
513
514 let racing_scope = RacingScope(&client);
515
516 racing_scope.tracks(|b| b).await.unwrap();
517 }
518
519 #[tokio::test]
520 async fn racing_lookup() {
521 let client = test_client().await;
522
523 let racing_scope = RacingScope(&client);
524
525 racing_scope.lookup(|b| b).await.unwrap();
526 }
527
528 #[tokio::test]
529 async fn racing_timestamp() {
530 let client = test_client().await;
531
532 let racing_scope = RacingScope(&client);
533
534 racing_scope.timestamp(|b| b).await.unwrap();
535 }
536
537 #[tokio::test]
538 async fn torn_attacklog() {
539 let client = test_client().await;
540
541 let racing_scope = TornScope(&client);
542
543 racing_scope
544 .attacklog(|b| b.log(AttackCode("ec987a60a22155cbfb7c1625cbb2092f".to_owned())))
545 .await
546 .unwrap();
547 }
548
549 #[tokio::test]
550 async fn torn_bounties() {
551 let client = test_client().await;
552
553 let torn_scope = TornScope(&client);
554
555 torn_scope.bounties(|b| b).await.unwrap();
556 }
557
558 #[tokio::test]
559 async fn torn_calendar() {
560 let client = test_client().await;
561
562 let torn_scope = TornScope(&client);
563
564 torn_scope.calendar(|b| b).await.unwrap();
565 }
566
567 #[tokio::test]
568 async fn torn_crimes() {
569 let client = test_client().await;
570
571 let torn_scope = TornScope(&client);
572
573 torn_scope.crimes(|b| b).await.unwrap();
574 }
575
576 #[tokio::test]
577 async fn torn_factionhof() {
578 let client = test_client().await;
579
580 let torn_scope = TornScope(&client);
581
582 torn_scope
583 .factionhof(|b| b.cat(crate::models::TornFactionHofCategory::Rank))
584 .await
585 .unwrap();
586 }
587
588 #[tokio::test]
589 async fn torn_factiontree() {
590 let client = test_client().await;
591
592 let torn_scope = TornScope(&client);
593
594 torn_scope.factiontree(|b| b).await.unwrap();
595 }
596
597 #[tokio::test]
598 async fn torn_hof() {
599 let client = test_client().await;
600
601 let torn_scope = TornScope(&client);
602
603 torn_scope
604 .hof(|b| b.cat(crate::models::TornHofCategory::Offences))
605 .await
606 .unwrap();
607 }
608
609 #[tokio::test]
610 async fn torn_itemammo() {
611 let client = test_client().await;
612
613 let torn_scope = TornScope(&client);
614
615 torn_scope.itemammo(|b| b).await.unwrap();
616 }
617
618 #[tokio::test]
619 async fn torn_itemmods() {
620 let client = test_client().await;
621
622 let torn_scope = TornScope(&client);
623
624 torn_scope.itemmods(|b| b).await.unwrap();
625 }
626
627 #[tokio::test]
628 async fn torn_items() {
629 let client = test_client().await;
630
631 let torn_scope = TornScope(&client);
632
633 torn_scope.items(|b| b).await.unwrap();
634 }
635
636 #[tokio::test]
637 async fn torn_items_for_ids() {
638 let client = test_client().await;
639
640 let torn_scope = TornScope(&client);
641
642 torn_scope
643 .items_for_ids("1".to_owned(), |b| b)
644 .await
645 .unwrap();
646 }
647
648 #[tokio::test]
649 async fn torn_logcategories() {
650 let client = test_client().await;
651
652 let torn_scope = TornScope(&client);
653
654 torn_scope.logcategories(|b| b).await.unwrap();
655 }
656
657 #[tokio::test]
658 async fn torn_logtypes() {
659 let client = test_client().await;
660
661 let torn_scope = TornScope(&client);
662
663 torn_scope.logtypes(|b| b).await.unwrap();
664 }
665
666 #[tokio::test]
667 async fn torn_logtypes_for_log_category_id() {
668 let client = test_client().await;
669
670 let torn_scope = TornScope(&client);
671
672 torn_scope
673 .logtypes_for_log_category_id(23.into(), |b| b)
674 .await
675 .unwrap();
676 }
677
678 #[tokio::test]
679 async fn torn_subrcimes_for_crime_id() {
680 let client = test_client().await;
681
682 let torn_scope = TornScope(&client);
683
684 torn_scope
685 .subcrimes_for_crime_id(3.into(), |b| b)
686 .await
687 .unwrap();
688 }
689
690 #[tokio::test]
691 async fn torn_lookup() {
692 let client = test_client().await;
693 let torn_scope = TornScope(&client);
694
695 torn_scope.lookup(|b| b).await.unwrap();
696 }
697
698 #[tokio::test]
699 async fn torn_timestamp() {
700 let client = test_client().await;
701
702 let torn_scope = TornScope(&client);
703
704 torn_scope.timestamp(|b| b).await.unwrap();
705 }
706
707 #[tokio::test]
708 async fn user_attacks() {
709 let client = test_client().await;
710
711 client.user().attacks(|b| b).await.unwrap();
712 }
713
714 #[tokio::test]
715 async fn user_attacksfull() {
716 let client = test_client().await;
717
718 client.user().attacksfull(|b| b).await.unwrap();
719 }
720
721 #[tokio::test]
722 async fn user_bounties() {
723 let client = test_client().await;
724
725 client.user().bounties(|b| b).await.unwrap();
726 }
727
728 #[tokio::test]
729 async fn user_bounties_for_id() {
730 let client = test_client().await;
731
732 client
733 .user()
734 .bounties_for_id(986228.into(), |b| b)
735 .await
736 .unwrap();
737 }
738
739 #[tokio::test]
740 async fn user_calendar() {
741 let client = test_client().await;
742
743 client.user().calendar(|b| b).await.unwrap();
744 }
745
746 #[tokio::test]
747 async fn user_crimes_for_crime_id() {
748 let client = test_client().await;
749
750 client
751 .user()
752 .crimes_for_crime_id(10.into(), |b| b)
753 .await
754 .unwrap();
755 }
756
757 #[tokio::test]
758 async fn user_enlisted_cars() {
759 let client = test_client().await;
760
761 client.user().enlistedcars(|b| b).await.unwrap();
762 }
763
764 #[tokio::test]
765 async fn user_factionbalance() {
766 let client = test_client().await;
767
768 client.user().factionbalance(|b| b).await.unwrap();
769 }
770
771 #[tokio::test]
772 async fn user_forumfeed() {
773 let client = test_client().await;
774
775 client.user().forumfeed(|b| b).await.unwrap();
776 }
777
778 #[tokio::test]
779 async fn user_forumfriends() {
780 let client = test_client().await;
781
782 client.user().forumfriends(|b| b).await.unwrap();
783 }
784
785 #[tokio::test]
786 async fn user_forumposts() {
787 let client = test_client().await;
788
789 client.user().forumposts(|b| b).await.unwrap();
790 }
791
792 #[tokio::test]
793 async fn user_forumposts_for_id() {
794 let client = test_client().await;
795
796 client
797 .user()
798 .forumposts_for_id(1.into(), |b| b)
799 .await
800 .unwrap();
801 }
802
803 #[tokio::test]
804 async fn user_forumsubscribedthreads() {
805 let client = test_client().await;
806
807 client.user().forumsubscribedthreads(|b| b).await.unwrap();
808 }
809
810 #[tokio::test]
811 async fn user_forumthreads() {
812 let client = test_client().await;
813
814 client.user().forumthreads(|b| b).await.unwrap();
815 }
816
817 #[tokio::test]
818 async fn user_forumthreads_for_id() {
819 let client = test_client().await;
820
821 client
822 .user()
823 .forumthreads_for_id(1.into(), |b| b)
824 .await
825 .unwrap();
826 }
827
828 #[tokio::test]
829 async fn user_hof() {
830 let client = test_client().await;
831
832 client.user().hof(|b| b).await.unwrap();
833 }
834
835 #[tokio::test]
836 async fn user_hof_for_id() {
837 let client = test_client().await;
838
839 client.user().hof_for_id(1.into(), |b| b).await.unwrap();
840 }
841
842 #[tokio::test]
843 async fn user_itemmarket() {
844 let client = test_client().await;
845
846 client.user().itemmarket(|b| b).await.unwrap();
847 }
848
849 #[tokio::test]
850 async fn user_jobranks() {
851 let client = test_client().await;
852
853 client.user().jobranks(|b| b).await.unwrap();
854 }
855
856 #[tokio::test]
857 async fn user_list() {
858 let client = test_client().await;
859
860 client
861 .user()
862 .list(|b| b.cat(UserListEnum::Friends))
863 .await
864 .unwrap();
865 }
866
867 #[tokio::test]
868 async fn user_organizedcrime() {
869 let client = test_client().await;
870
871 client.user().organizedcrime(|b| b).await.unwrap();
872 }
873
874 #[tokio::test]
875 async fn user_personalstats() {
876 let client = test_client().await;
877
878 client
879 .user()
880 .personalstats(|b| {
881 b.stat([PersonalStatsStatName::Piercinghits])
882 .timestamp(1737661955)
883 })
884 .await
885 .unwrap();
886
887 client
888 .user()
889 .personalstats(|b| b.cat(PersonalStatsCategoryEnum::All))
890 .await
891 .unwrap();
892
893 client
894 .user()
895 .personalstats(|b| b.cat(PersonalStatsCategoryEnum::Popular))
896 .await
897 .unwrap();
898
899 client
900 .user()
901 .personalstats(|b| b.cat(PersonalStatsCategoryEnum::Drugs))
902 .await
903 .unwrap();
904
905 client
906 .user()
907 .personalstats(|b| b.stat([PersonalStatsStatName::Piercinghits]))
908 .await
909 .unwrap();
910 }
911
912 #[tokio::test]
913 async fn user_personalstats_for_id() {
914 let client = test_client().await;
915
916 client
917 .user()
918 .personalstats_for_id(1.into(), |b| b.cat(PersonalStatsCategoryEnum::All))
919 .await
920 .unwrap();
921 }
922
923 #[tokio::test]
924 async fn user_races() {
925 let client = test_client().await;
926
927 client.user().races(|b| b).await.unwrap();
928 }
929
930 #[tokio::test]
931 async fn user_revives() {
932 let client = test_client().await;
933
934 client.user().revives(|b| b).await.unwrap();
935 }
936
937 #[tokio::test]
938 async fn user_revivesfull() {
939 let client = test_client().await;
940
941 client.user().revives_full(|b| b).await.unwrap();
942 }
943
944 #[tokio::test]
945 async fn user_lookup() {
946 let client = test_client().await;
947
948 client.user().lookup(|b| b).await.unwrap();
949 }
950
951 #[tokio::test]
952 async fn user_timestamp() {
953 let client = test_client().await;
954
955 client.user().attacks(|b| b).await.unwrap();
956 }
957}