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

61 lines
1.6 KiB
Rust
Raw Normal View History

2019-04-14 10:34:41 -07:00
use actix_multipart::{Field, Multipart, MultipartError};
use actix_web::{error, web, Error, HttpResponse};
use futures::{
future::{err as fut_err, ok as fut_ok, Either},
Future, Stream,
};
2019-04-09 14:12:07 -04:00
use crate::common::{Part, Product};
2019-04-14 10:34:41 -07:00
pub fn get_products(
query: web::Query<Option<Part>>,
) -> impl Future<Item = HttpResponse, Error = Error> {
2019-04-09 14:12:07 -04:00
fut_ok(HttpResponse::Ok().finish())
}
2019-04-14 10:34:41 -07:00
pub fn add_product(
new_product: web::Json<Product>,
) -> impl Future<Item = HttpResponse, Error = Error> {
2019-04-09 14:12:07 -04:00
fut_ok(HttpResponse::Ok().finish())
}
2019-04-14 10:34:41 -07:00
pub fn get_product_detail(
id: web::Path<String>,
) -> impl Future<Item = HttpResponse, Error = Error> {
2019-04-09 14:12:07 -04:00
fut_ok(HttpResponse::Ok().finish())
}
2019-04-14 10:34:41 -07:00
pub fn remove_product(
id: web::Path<String>,
) -> impl Future<Item = HttpResponse, Error = Error> {
2019-04-09 14:12:07 -04:00
fut_ok(HttpResponse::Ok().finish())
2019-04-10 14:08:10 -04:00
}
#[cfg(test)]
mod tests {
use super::*;
use crate::appconfig::config_app;
2019-04-14 10:34:41 -07:00
use actix_service::Service;
use actix_web::{
http::{header, StatusCode},
test, web, App, HttpRequest, HttpResponse,
};
2019-04-10 14:08:10 -04:00
#[test]
fn test_add_product() {
2019-04-14 10:34:41 -07:00
let mut app = test::init_service(App::new().configure(config_app));
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")
.header(header::CONTENT_TYPE, "application/json")
.set_payload(payload)
.to_request();
2019-04-10 14:08:10 -04:00
let resp = test::block_on(app.call(req)).unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}
}