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.

47 lines
1.5 KiB

  1. mod common;
  2. #[cfg(test)]
  3. mod tests {
  4. use super::*;
  5. use actix_demo::models::ErrorModel;
  6. use actix_web::dev::Service as _;
  7. use actix_web::http::StatusCode;
  8. use actix_web::test;
  9. #[actix_rt::test]
  10. async fn get_users_api_should_return_error_message_if_no_users_exist() {
  11. let req = test::TestRequest::get().uri("/api/get/users").to_request();
  12. let resp = common::test_app().await.call(req).await.unwrap();
  13. assert_eq!(resp.status(), StatusCode::ACCEPTED);
  14. let body: ErrorModel = test::read_body_json(resp).await;
  15. assert_eq!(
  16. body,
  17. ErrorModel {
  18. success: false,
  19. reason: "Entity does not exist - No users available".to_owned()
  20. }
  21. );
  22. log::debug!("{:?}", body);
  23. }
  24. #[actix_rt::test]
  25. async fn get_user_api_should_return_error_message_if_user_with_id_does_not_exist(
  26. ) {
  27. let req = test::TestRequest::get()
  28. .uri("/api/get/users/1")
  29. .to_request();
  30. let resp = common::test_app().await.call(req).await.unwrap();
  31. assert_eq!(resp.status(), StatusCode::ACCEPTED);
  32. let body: ErrorModel = test::read_body_json(resp).await;
  33. assert_eq!(
  34. body,
  35. ErrorModel {
  36. success: false,
  37. reason: "Entity does not exist - No user found with uid: 1"
  38. .to_owned()
  39. }
  40. );
  41. log::debug!("{:?}", body);
  42. }
  43. }