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_simple.rs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #[cfg(all(feature = "simple", feature = "robocraft"))]
  2. use libfj::robocraft_simple;
  3. #[cfg(all(feature = "simple", feature = "robocraft"))]
  4. use libfj::robocraft;
  5. #[cfg(all(feature = "simple", feature = "robocraft"))]
  6. #[test]
  7. fn robocraft_factory_api_init_simple() -> Result<(), ()> {
  8. robocraft_simple::FactoryAPI::new();
  9. Ok(())
  10. }
  11. #[cfg(all(feature = "simple", feature = "robocraft"))]
  12. fn builder() -> robocraft_simple::FactorySearchBuilder {
  13. robocraft_simple::FactoryAPI::new().list_builder()
  14. }
  15. #[cfg(all(feature = "simple", feature = "robocraft"))]
  16. fn assert_factory_list(robo_info: robocraft::FactoryInfo<robocraft::RoboShopItemsInfo>) -> Result<(), ()> {
  17. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  18. assert_eq!(robo_info.status_code, 200);
  19. for robot in &robo_info.response.roboshop_items {
  20. assert_ne!(robot.item_name, "");
  21. assert_ne!(robot.added_by, "");
  22. assert_ne!(robot.added_by_display_name, "");
  23. assert_ne!(robot.thumbnail, "");
  24. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  25. }
  26. Ok(())
  27. }
  28. #[test]
  29. #[cfg(all(feature = "simple", feature = "robocraft"))]
  30. fn robocraft_factory_query_simple() -> Result<(), ()> {
  31. let result = robocraft_simple::FactoryAPI::new().list();
  32. assert!(result.is_ok());
  33. let robo_info = result.unwrap();
  34. assert_factory_list(robo_info)?;
  35. Ok(())
  36. }
  37. #[test]
  38. #[cfg(all(feature = "simple", feature = "robocraft"))]
  39. fn robocraft_factory_custom_query_simple() -> Result<(), ()> {
  40. let result = builder()
  41. .movement_or(robocraft::FactoryMovementType::Wheels)
  42. .weapon_or(robocraft::FactoryWeaponType::Laser)
  43. .page(2)
  44. .items_per_page(10)
  45. .send();
  46. assert!(result.is_ok());
  47. let robo_info = result.unwrap();
  48. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  49. //assert_eq!(robo_info.response.roboshop_items.len(), 16); the API behaviour is weird, I swear it's not me!
  50. assert!(robo_info.response.roboshop_items.len() >= 10);
  51. assert_eq!(robo_info.status_code, 200);
  52. for robot in &robo_info.response.roboshop_items {
  53. assert_ne!(robot.item_name, "");
  54. assert_ne!(robot.added_by, "");
  55. assert_ne!(robot.added_by_display_name, "");
  56. assert_ne!(robot.thumbnail, "");
  57. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  58. }
  59. Ok(())
  60. }
  61. #[test]
  62. #[cfg(all(feature = "simple", feature = "robocraft"))]
  63. fn robocraft_factory_player_query() -> Result<(), ()> {
  64. // hard-coding a user inevitably fails, so that's grab one from the front page
  65. let username = robocraft_simple::FactoryAPI::new()
  66. .list()
  67. .unwrap() // covered by another test case
  68. .response
  69. .roboshop_items[0]
  70. .added_by
  71. .clone();
  72. let result = builder()
  73. .text(username) // there is a featured robot by this user, so this should never fail
  74. .text_search_type(robocraft::FactoryTextSearchType::Player)
  75. .items_per_page(10)
  76. .send();
  77. assert!(result.is_ok());
  78. assert_factory_list(result.unwrap())
  79. }
  80. #[test]
  81. #[cfg(all(feature = "simple", feature = "robocraft"))]
  82. fn robocraft_factory_robot_query() -> Result<(), ()> {
  83. let api = robocraft_simple::FactoryAPI::new();
  84. let result = api.get(6478345 /* featured robot id*/);
  85. assert!(result.is_ok());
  86. let bot_info = result.unwrap();
  87. assert_ne!(bot_info.response.item_name, "");
  88. assert_eq!(bot_info.response.item_id, 6478345);
  89. assert_ne!(bot_info.response.cube_data, "");
  90. assert_ne!(bot_info.response.colour_data, "");
  91. Ok(())
  92. }