From ad370430ef356fdc0e2d514041560ae5c4185e32 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Thu, 3 Oct 2024 21:53:25 +0200 Subject: Test post with registration echoed back --- rust/src/lib.rs | 1 + rust/src/web.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'rust/src') diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a8cf18e..568637e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2,3 +2,4 @@ pub mod ast; pub mod io; pub mod lambda; pub mod parser; +pub mod web; diff --git a/rust/src/web.rs b/rust/src/web.rs index 94ed282..2614c06 100644 --- a/rust/src/web.rs +++ b/rust/src/web.rs @@ -3,14 +3,12 @@ use std::{ io::{stdin, stdout, IsTerminal}, }; -use lambda::io::{batch_eval, eval_file, repl}; - use actix_web::{ get, http::header::ContentType, post, web, App, HttpResponse, HttpServer, Responder, }; use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] struct Registration { url: String, } @@ -32,21 +30,28 @@ async fn main() -> std::io::Result<()> { #[cfg(test)] mod app_tests { - use actix_web::{http::header::ContentType, test, App}; + use actix_web::{body, http::header::ContentType, test, App}; use super::*; #[actix_web::test] - async fn post_registration_echoes_back_registration_data() { + async fn post_registration_echoes_back_registration_data_with_unique_id() { let app = test::init_service(App::new().service(register)).await; + let registration = Registration { + url: "http://192.168.1.1".to_string(), + }; let req = test::TestRequest::post() .uri("/register") - .set_json(Registration { - url: "http://192.168.1.1".to_string(), - }) + .set_json(registration.clone()) .insert_header(ContentType::json()) .to_request(); let resp = test::call_service(&app, req).await; assert!(resp.status().is_success()); + let body = resp.into_body(); + let bytes = body::to_bytes(body).await; + assert_eq!( + registration, + serde_json::from_slice(&bytes.unwrap()).unwrap() + ); } } -- cgit v1.2.3