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.

44 lines
1.4 KiB

  1. use crate::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/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().uri("/api/users/1").to_request();
  28. let resp = common::test_app().await.call(req).await.unwrap();
  29. assert_eq!(resp.status(), StatusCode::ACCEPTED);
  30. let body: ErrorModel = test::read_body_json(resp).await;
  31. assert_eq!(
  32. body,
  33. ErrorModel {
  34. success: false,
  35. reason: "Entity does not exist - No user found with uid: 1"
  36. .to_owned()
  37. }
  38. );
  39. log::debug!("{:?}", body);
  40. }
  41. }