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_auth.rs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #[cfg(feature = "robocraft")]
  2. use libfj::robocraft;
  3. #[cfg(feature = "robocraft")]
  4. use libfj::robocraft2;
  5. #[cfg(feature = "robocraft")]
  6. use libfj::robocraft::ITokenProvider;
  7. #[cfg(feature = "robocraft")]
  8. #[test]
  9. fn robocraft_auth_login() -> Result<(), ()> {
  10. let token_maybe = robocraft::AuthenticatedTokenProvider::with_email("melon.spoik@gmail.com", "P4$$w0rd");
  11. assert!(token_maybe.is_ok());
  12. let token_maybe = robocraft::AuthenticatedTokenProvider::with_username("FJAPIC00L", "P4$$w0rd");
  13. assert!(token_maybe.is_ok());
  14. let token_p = token_maybe.unwrap();
  15. let raw_token_maybe = token_p.token();
  16. assert!(raw_token_maybe.is_ok());
  17. println!("Token: {}", raw_token_maybe.unwrap());
  18. Ok(())
  19. }
  20. #[cfg(feature = "robocraft")]
  21. #[test]
  22. fn robocraft_account() -> Result<(), ()> {
  23. let token_maybe = robocraft::AuthenticatedTokenProvider::with_username("FJAPIC00L", "P4$$w0rd");
  24. assert!(token_maybe.is_ok());
  25. let token_provider = token_maybe.unwrap();
  26. let account_maybe = token_provider.get_account_info();
  27. assert!(account_maybe.is_ok());
  28. let account = account_maybe.unwrap();
  29. assert_eq!(account.display_name, "FJAPIC00L");
  30. assert_eq!(account.created_date, "2019-01-18T14:48:09");
  31. Ok(())
  32. }
  33. // this requires human-interaction so it's disabled by default
  34. #[cfg(feature = "robocraft2")]
  35. #[allow(dead_code)]
  36. //#[tokio::test]
  37. async fn robocraft2_account() -> Result<(), ()> {
  38. let token_maybe = robocraft2::PortalTokenProvider::portal().await;
  39. assert!(token_maybe.is_ok());
  40. let token_provider = token_maybe.unwrap();
  41. let account_maybe = token_provider.get_account_info();
  42. assert!(account_maybe.is_ok());
  43. let account = account_maybe.unwrap();
  44. assert_eq!(account.display_name, "NGniusness");
  45. assert_eq!(account.created_date, "2014-09-17T21:02:46");
  46. Ok(())
  47. }
  48. // this requires human-interaction so it's disabled by default
  49. #[cfg(feature = "robocraft2")]
  50. #[allow(dead_code)]
  51. #[tokio::test]
  52. async fn robocraft2_simple_account() -> Result<(), ()> {
  53. let token_maybe = robocraft2::PortalTokenProvider::with_username("FJAPIC00L", "P4$$w0rd").await;
  54. assert!(token_maybe.is_ok());
  55. let token_provider = token_maybe.unwrap();
  56. let account_maybe = token_provider.get_account_info();
  57. assert!(account_maybe.is_ok());
  58. let account = account_maybe.unwrap();
  59. assert_eq!(account.display_name, "FJAPIC00L");
  60. assert_eq!(account.created_date, "2019-01-18T14:48:09");
  61. Ok(())
  62. }