An unofficial collection of APIs used in FreeJam games and mods
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

robocraft_factory.rs 4.3KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #[cfg(feature = "robocraft")]
  2. use libfj::robocraft;
  3. #[cfg(feature = "robocraft")]
  4. use libfj::robocraft2;
  5. #[cfg(feature = "robocraft")]
  6. use std::convert::From;
  7. #[cfg(feature = "robocraft")]
  8. #[test]
  9. fn robocraft_factory_api_init() -> Result<(), ()> {
  10. robocraft::FactoryAPI::new();
  11. Ok(())
  12. }
  13. #[cfg(feature = "robocraft")]
  14. #[tokio::test]
  15. async fn robocraft_factory_default_query() -> Result<(), ()> {
  16. let api = robocraft::FactoryAPI::new();
  17. let result = api.list().await;
  18. assert!(result.is_ok());
  19. let robo_info = result.unwrap();
  20. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  21. assert_eq!(robo_info.status_code, 200);
  22. for robot in &robo_info.response.roboshop_items {
  23. assert_ne!(robot.item_name, "");
  24. assert_ne!(robot.added_by, "");
  25. assert_ne!(robot.added_by_display_name, "");
  26. assert_ne!(robot.thumbnail, "");
  27. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  28. }
  29. Ok(())
  30. }
  31. #[cfg(feature = "robocraft")]
  32. fn builder() -> robocraft::FactorySearchBuilder {
  33. robocraft::FactoryAPI::new().list_builder()
  34. }
  35. #[cfg(feature = "robocraft")]
  36. fn assert_factory_list(robo_info: robocraft::FactoryInfo<robocraft::RoboShopItemsInfo>) -> Result<(), ()> {
  37. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  38. assert_eq!(robo_info.status_code, 200);
  39. for robot in &robo_info.response.roboshop_items {
  40. assert_ne!(robot.item_name, "");
  41. assert_ne!(robot.added_by, "");
  42. assert_ne!(robot.added_by_display_name, "");
  43. assert_ne!(robot.thumbnail, "");
  44. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  45. }
  46. Ok(())
  47. }
  48. #[cfg(feature = "robocraft")]
  49. #[tokio::test]
  50. async fn robocraft_factory_custom_query() -> Result<(), ()> {
  51. let api = robocraft::FactoryAPI::new();
  52. let result = api.list_builder()
  53. .movement_or(robocraft::FactoryMovementType::Wheels)
  54. .weapon_or(robocraft::FactoryWeaponType::Laser)
  55. .page(2)
  56. .items_per_page(10)
  57. .send().await;
  58. assert!(result.is_ok());
  59. let robo_info = result.unwrap();
  60. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  61. //assert_eq!(robo_info.response.roboshop_items.len(), 16); the API behaviour is weird, I swear it's not me!
  62. assert!(robo_info.response.roboshop_items.len() >= 10);
  63. assert_eq!(robo_info.status_code, 200);
  64. for robot in &robo_info.response.roboshop_items {
  65. assert_ne!(robot.item_name, "");
  66. assert_ne!(robot.added_by, "");
  67. assert_ne!(robot.added_by_display_name, "");
  68. assert_ne!(robot.thumbnail, "");
  69. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  70. }
  71. Ok(())
  72. }
  73. #[cfg(feature = "robocraft")]
  74. #[tokio::test]
  75. async fn robocraft_factory_player_query() -> Result<(), ()> {
  76. let result = builder()
  77. .text("Zalera57".to_string()) // there is a featured robot by this user, so this should never fail
  78. .text_search_type(robocraft::FactoryTextSearchType::Player)
  79. .items_per_page(10)
  80. .send().await;
  81. assert!(result.is_ok());
  82. assert_factory_list(result.unwrap())
  83. }
  84. #[cfg(feature = "robocraft")]
  85. #[tokio::test]
  86. async fn robocraft_factory_robot_query() -> Result<(), ()> {
  87. let api = robocraft::FactoryAPI::new();
  88. let result = api.get(6478345 /* featured robot id */).await;
  89. assert!(result.is_ok());
  90. let bot_info = result.unwrap();
  91. assert_ne!(bot_info.response.item_name, "");
  92. assert_eq!(bot_info.response.item_id, 6478345);
  93. assert_ne!(bot_info.response.cube_data, "");
  94. assert_ne!(bot_info.response.colour_data, "");
  95. Ok(())
  96. }
  97. #[cfg(feature = "robocraft")]
  98. #[tokio::test]
  99. async fn robocraft_factory_robot_cubes() -> Result<(), ()> {
  100. let api = robocraft::FactoryAPI::new();
  101. let result = api.get(6478345 /* featured robot id */).await;
  102. assert!(result.is_ok());
  103. let bot_info = result.unwrap();
  104. let cubes = robocraft::Cubes::from(bot_info.clone());
  105. println!("cube count: {} or {}", cubes.provided_len, cubes.len());
  106. /*for c in cubes.into_iter() {
  107. println!("Cube.to_string() -> `{}`", c.to_string());
  108. }*/
  109. let (cube_d, colour_d) = cubes.dump();
  110. let cube_str = base64::encode(&cube_d);
  111. let colour_str = base64::encode(&colour_d);
  112. assert_eq!(cube_str, bot_info.response.cube_data);
  113. assert_eq!(colour_str, bot_info.response.colour_data);
  114. Ok(())
  115. }