1
0
mirror of https://github.com/actix/examples synced 2025-02-24 02:03:02 +01:00

47 lines
1.3 KiB
Rust
Raw Normal View History

2019-09-05 00:04:57 +09:00
use actix_web::{web, Error, HttpResponse};
2019-04-09 14:12:07 -04:00
use crate::common::{Part, Product};
2022-02-18 02:44:02 +00:00
pub async fn get_products(_query: web::Query<Option<Part>>) -> Result<HttpResponse, Error> {
2019-12-07 23:59:24 +06:00
Ok(HttpResponse::Ok().finish())
2019-04-09 14:12:07 -04:00
}
2022-02-18 02:44:02 +00:00
pub async fn add_product(_new_product: web::Json<Product>) -> Result<HttpResponse, Error> {
2019-12-07 23:59:24 +06:00
Ok(HttpResponse::Ok().finish())
2019-04-09 14:12:07 -04:00
}
2020-04-03 16:14:30 +09:00
pub async fn get_product_detail(_id: web::Path<String>) -> Result<HttpResponse, Error> {
2019-12-07 23:59:24 +06:00
Ok(HttpResponse::Ok().finish())
2019-04-09 14:12:07 -04:00
}
2020-04-03 16:14:30 +09:00
pub async fn remove_product(_id: web::Path<String>) -> Result<HttpResponse, Error> {
2019-12-07 23:59:24 +06:00
Ok(HttpResponse::Ok().finish())
2019-04-10 14:08:10 -04:00
}
#[cfg(test)]
mod tests {
2022-02-18 02:02:44 +00:00
use crate::app_config::config_app;
use actix_web::dev::Service;
2019-04-14 10:34:41 -07:00
use actix_web::{
http::{header, StatusCode},
2019-12-07 23:59:24 +06:00
test, App,
2019-04-14 10:34:41 -07:00
};
2019-04-10 14:08:10 -04:00
#[actix_web::test]
2019-12-07 23:59:24 +06:00
async fn test_add_product() {
let app = test::init_service(App::new().configure(config_app)).await;
2019-04-10 14:08:10 -04:00
let payload = r#"{"id":12345,"product_type":"fancy","name":"test"}"#.as_bytes();
let req = test::TestRequest::post()
2019-04-14 10:34:41 -07:00
.uri("/products")
.insert_header((header::CONTENT_TYPE, "application/json"))
2019-04-14 10:34:41 -07:00
.set_payload(payload)
.to_request();
2019-04-10 14:08:10 -04:00
2019-12-07 23:59:24 +06:00
let resp = app.call(req).await.unwrap();
2019-04-10 14:08:10 -04:00
assert_eq!(resp.status(), StatusCode::OK);
}
}