update integration tests with edit
This commit is contained in:
parent
5cc159e7a3
commit
3e2b765678
@ -19,7 +19,4 @@ sea-orm = { version = "^0.9.1", features = [], default-features = false }
|
||||
actix_admin_macros = { path = "actix_admin_macros" }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0"
|
||||
sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
|
||||
actix_admin_macros = { path = "actix_admin_macros" }
|
||||
async-trait = "0.1.53"
|
||||
sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
|
@ -84,7 +84,7 @@ impl ActixAdminModel {
|
||||
}
|
||||
|
||||
pub fn get_bool(&self, key: &str, is_option_or_string: bool) -> Result<Option<bool>, String> {
|
||||
let val = self.get_value_by_closure(key, is_option_or_string, |val| if !val.is_empty() { Ok(true) } else { Ok(false) });
|
||||
let val = self.get_value_by_closure(key, is_option_or_string, |val| if !val.is_empty() && (val == "true" || val == "yes") { Ok(true) } else { Ok(false) });
|
||||
// not selected bool field equals to false and not to missing
|
||||
match val {
|
||||
Ok(val) => Ok(val),
|
||||
|
@ -9,9 +9,12 @@ mod tests {
|
||||
use actix_web::http::header::ContentType;
|
||||
use actix_web::test;
|
||||
use actix_web::{middleware, web, App};
|
||||
use chrono::NaiveDate;
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{Serialize};
|
||||
use sea_orm::EntityTrait;
|
||||
use sea_orm::PaginatorTrait;
|
||||
use sea_orm::prelude::Decimal;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn comment_create_and_edit() {
|
||||
@ -31,7 +34,7 @@ mod tests {
|
||||
)
|
||||
.await;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct CommentModel {
|
||||
id: &'static str,
|
||||
insert_date: &'static str,
|
||||
@ -42,7 +45,8 @@ mod tests {
|
||||
my_decimal: &'static str
|
||||
}
|
||||
|
||||
let model = CommentModel {
|
||||
// create entity
|
||||
let mut model = CommentModel {
|
||||
id: "0",
|
||||
insert_date: "1977-04-01T14:00",
|
||||
comment: "test",
|
||||
@ -51,11 +55,11 @@ mod tests {
|
||||
post_id: None,
|
||||
my_decimal: "113.141" // must be larger than 100
|
||||
};
|
||||
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.insert_header(ContentType::form_url_encoded())
|
||||
.uri("/admin/comment/create_post_from_plaintext")
|
||||
.set_form(model)
|
||||
.set_form(model.clone())
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
|
||||
@ -68,7 +72,46 @@ mod tests {
|
||||
.expect("could not retrieve entities");
|
||||
|
||||
assert!(entities.len() == 1, "After post, db does not contain 1 model");
|
||||
let entity = entities.first().unwrap();
|
||||
assert!(entity.id == 1);
|
||||
assert!(entity.comment == "test");
|
||||
assert!(entity.user == "test");
|
||||
assert!(entity.is_visible);
|
||||
assert!(entity.post_id.is_none());
|
||||
assert!(entity.my_decimal == Decimal::new(113141, 3));
|
||||
assert!(entity.insert_date == NaiveDateTime::parse_from_str("1977-04-01T14:00", "%Y-%m-%dT%H:%M").unwrap());
|
||||
|
||||
// update entity
|
||||
model.my_decimal = "213.141";
|
||||
model.user = "updated";
|
||||
model.comment = "updated";
|
||||
model.insert_date = "1987-04-01T14:00";
|
||||
model.is_visible = "false";
|
||||
|
||||
let edit_req = test::TestRequest::post()
|
||||
.insert_header(ContentType::form_url_encoded())
|
||||
.uri("/admin/comment/edit_post_from_plaintext/1")
|
||||
.set_form(model.clone())
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, edit_req).await;
|
||||
|
||||
assert!(resp.status().is_redirection());
|
||||
|
||||
let entities = super::test_setup::Comment::find()
|
||||
.paginate(&app_state.db, 50)
|
||||
.fetch_page(0)
|
||||
.await
|
||||
.expect("could not retrieve entities");
|
||||
|
||||
assert!(entities.len() == 1, "After edit post, db does not contain 1 model");
|
||||
let entity = entities.first().unwrap();
|
||||
assert!(entity.id == 1);
|
||||
assert!(entity.comment == "updated");
|
||||
assert!(entity.user == "updated");
|
||||
assert!(!entity.is_visible);
|
||||
assert!(entity.post_id.is_none());
|
||||
assert!(entity.my_decimal == Decimal::new(213141, 3));
|
||||
assert!(entity.insert_date == NaiveDateTime::parse_from_str("1987-04-01T14:00", "%Y-%m-%dT%H:%M").unwrap());
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
@ -89,7 +132,7 @@ mod tests {
|
||||
)
|
||||
.await;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct PostModel {
|
||||
id: &'static str,
|
||||
title: &'static str,
|
||||
@ -98,7 +141,7 @@ mod tests {
|
||||
insert_date: &'static str,
|
||||
}
|
||||
|
||||
let model = PostModel {
|
||||
let mut model = PostModel {
|
||||
id: "0",
|
||||
insert_date: "1977-04-01",
|
||||
title: "test",
|
||||
@ -109,7 +152,7 @@ mod tests {
|
||||
let req = test::TestRequest::post()
|
||||
.insert_header(ContentType::form_url_encoded())
|
||||
.uri("/admin/post/create_post_from_plaintext")
|
||||
.set_form(model)
|
||||
.set_form(model.clone())
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, req).await;
|
||||
|
||||
@ -122,5 +165,39 @@ mod tests {
|
||||
.expect("could not retrieve entities");
|
||||
|
||||
assert!(entities.len() == 1, "After post, db does not contain 1 model");
|
||||
let entity = entities.first().unwrap();
|
||||
assert!(entity.id == 1);
|
||||
assert!(entity.tea_mandatory == super::test_setup::post::Tea::EverydayTea);
|
||||
assert!(entity.title == model.title);
|
||||
assert!(entity.text == model.text);
|
||||
assert!(entity.insert_date == NaiveDate::parse_from_str("1977-04-01", "%Y-%m-%d").unwrap());
|
||||
|
||||
// update entity
|
||||
model.tea_mandatory = "BreakfastTea";
|
||||
model.title = "updated";
|
||||
model.text = "updated";
|
||||
model.insert_date = "1987-04-01";
|
||||
|
||||
let edit_req = test::TestRequest::post()
|
||||
.insert_header(ContentType::form_url_encoded())
|
||||
.uri("/admin/post/edit_post_from_plaintext/1")
|
||||
.set_form(model.clone())
|
||||
.to_request();
|
||||
let resp = test::call_service(&app, edit_req).await;
|
||||
|
||||
assert!(resp.status().is_redirection());
|
||||
|
||||
let entities = super::test_setup::Post::find()
|
||||
.paginate(&app_state.db, 50)
|
||||
.fetch_page(0)
|
||||
.await
|
||||
.expect("could not retrieve entities");
|
||||
|
||||
assert!(entities.len() == 1, "After edit post, db does not contain 1 model");
|
||||
let entity = entities.first().unwrap();
|
||||
assert!(entity.id == 1);
|
||||
assert!(entity.text == "updated");
|
||||
assert!(entity.title == "updated");
|
||||
assert!(entity.insert_date == NaiveDate::parse_from_str("1987-04-01", "%Y-%m-%d").unwrap());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user