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.

82 lines
3.0KB

  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_custom_query_simple() -> Result<(), ()> {
  31. let result = builder()
  32. .movement_or(robocraft::FactoryMovementType::Wheels)
  33. .weapon_or(robocraft::FactoryWeaponType::Laser)
  34. .page(2)
  35. .items_per_page(10)
  36. .send();
  37. assert!(result.is_ok());
  38. let robo_info = result.unwrap();
  39. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  40. //assert_eq!(robo_info.response.roboshop_items.len(), 16); the API behaviour is weird, I swear it's not me!
  41. assert!(robo_info.response.roboshop_items.len() >= 10);
  42. assert_eq!(robo_info.status_code, 200);
  43. for robot in &robo_info.response.roboshop_items {
  44. assert_ne!(robot.item_name, "");
  45. assert_ne!(robot.added_by, "");
  46. assert_ne!(robot.added_by_display_name, "");
  47. assert_ne!(robot.thumbnail, "");
  48. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  49. }
  50. Ok(())
  51. }
  52. #[test]
  53. #[cfg(all(feature = "simple", feature = "robocraft"))]
  54. fn robocraft_factory_player_query() -> Result<(), ()> {
  55. let result = builder()
  56. .text("MilanZhi".to_string()) // there is a featured robot by this user, so this should never fail
  57. .text_search_type(robocraft::FactoryTextSearchType::Player)
  58. .items_per_page(10)
  59. .send();
  60. assert!(result.is_ok());
  61. assert_factory_list(result.unwrap())
  62. }
  63. #[test]
  64. #[cfg(all(feature = "simple", feature = "robocraft"))]
  65. fn robocraft_factory_robot_query() -> Result<(), ()> {
  66. let api = robocraft_simple::FactoryAPI::new();
  67. let result = api.get(6478345 /* featured robot id*/);
  68. assert!(result.is_ok());
  69. let bot_info = result.unwrap();
  70. assert_ne!(bot_info.response.item_name, "");
  71. assert_eq!(bot_info.response.item_id, 6478345);
  72. assert_ne!(bot_info.response.cube_data, "");
  73. assert_ne!(bot_info.response.colour_data, "");
  74. Ok(())
  75. }