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.5 KiB

  1. use crate::common;
  2. #[cfg(test)]
  3. mod tests {
  4. use super::*;
  5. use actix_demo::models::ApiResponse;
  6. use actix_web::dev::Service as _;
  7. use actix_web::http::StatusCode;
  8. use actix_web::test;
  9. mod get_users_api {
  10. use super::*;
  11. #[actix_rt::test]
  12. async fn should_return_empty_array_if_no_users_exist() {
  13. let req = test::TestRequest::get()
  14. .uri("/api/users?page=0&limit=2")
  15. .to_request();
  16. let resp =
  17. common::test_app().await.unwrap().call(req).await.unwrap();
  18. assert_eq!(resp.status(), StatusCode::OK);
  19. let body: ApiResponse<Vec<_>> = test::read_body_json(resp).await;
  20. let _ = tracing::debug!("{:?}", body);
  21. assert_eq!(body, ApiResponse::successful(vec![1; 0]));
  22. }
  23. #[actix_rt::test]
  24. async fn should_return_error_message_if_user_with_id_does_not_exist() {
  25. let req = test::TestRequest::get().uri("/api/users/1").to_request();
  26. let resp =
  27. common::test_app().await.unwrap().call(req).await.unwrap();
  28. assert_eq!(resp.status(), StatusCode::NOT_FOUND);
  29. let body: ApiResponse<String> = test::read_body_json(resp).await;
  30. let _ = tracing::debug!("{:?}", body);
  31. assert_eq!(
  32. body,
  33. ApiResponse::failure(
  34. "Entity does not exist - No user found with uid: 1"
  35. .to_owned()
  36. )
  37. );
  38. }
  39. }
  40. }