1
0
mirror of https://github.com/actix/examples synced 2025-02-23 17:53:02 +01:00
2022-07-09 21:08:11 +01:00

48 lines
1.3 KiB
Rust

use actix_web::{web, Error, HttpResponse};
use crate::common::{Part, Product};
pub async fn get_products(_query: web::Query<Option<Part>>) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().finish())
}
pub async fn add_product(_new_product: web::Json<Product>) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().finish())
}
pub async fn get_product_detail(_id: web::Path<String>) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().finish())
}
pub async fn remove_product(_id: web::Path<String>) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().finish())
}
#[cfg(test)]
mod tests {
use actix_web::{
dev::Service,
http::{header, StatusCode},
test, App,
};
use crate::app_config::config_app;
#[actix_web::test]
async fn test_add_product() {
let app = test::init_service(App::new().configure(config_app)).await;
let payload = r#"{"id":12345,"product_type":"fancy","name":"test"}"#.as_bytes();
let req = test::TestRequest::post()
.uri("/products")
.insert_header((header::CONTENT_TYPE, "application/json"))
.set_payload(payload)
.to_request();
let resp = app.call(req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}
}