-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
json_vec_tests.rs
101 lines (79 loc) 路 2.7 KB
/
json_vec_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
use sea_orm::{entity::prelude::*, entity::*, DatabaseConnection};
#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
let ctx = TestContext::new("json_vec_tests").await;
create_tables(&ctx.db).await?;
insert_json_vec(&ctx.db).await?;
insert_json_string_vec_derive(&ctx.db).await?;
insert_json_struct_vec_derive(&ctx.db).await?;
ctx.delete().await;
Ok(())
}
pub async fn insert_json_vec(db: &DatabaseConnection) -> Result<(), DbErr> {
let json_vec = json_vec::Model {
id: 1,
str_vec: Some(json_vec::StringVec(vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
])),
};
let result = json_vec.clone().into_active_model().insert(db).await?;
assert_eq!(result, json_vec);
let model = json_vec::Entity::find()
.filter(json_vec::Column::Id.eq(json_vec.id))
.one(db)
.await?;
assert_eq!(model, Some(json_vec));
Ok(())
}
pub async fn insert_json_string_vec_derive(db: &DatabaseConnection) -> Result<(), DbErr> {
let json_vec = json_vec_derive::json_string_vec::Model {
id: 1,
str_vec: Some(json_vec_derive::json_string_vec::StringVec(vec![
"4".to_string(),
"5".to_string(),
"6".to_string(),
])),
};
let result = json_vec_derive::json_string_vec::ActiveModel {
id: NotSet,
..json_vec.clone().into_active_model()
}
.insert(db)
.await?;
assert_eq!(result, json_vec);
let model = json_vec_derive::json_string_vec::Entity::find()
.filter(json_vec_derive::json_string_vec::Column::Id.eq(json_vec.id))
.one(db)
.await?;
assert_eq!(model, Some(json_vec));
Ok(())
}
pub async fn insert_json_struct_vec_derive(db: &DatabaseConnection) -> Result<(), DbErr> {
let json_vec = json_vec_derive::json_struct_vec::Model {
id: 2,
struct_vec: vec![
json_vec_derive::json_struct_vec::JsonColumn {
value: "4".to_string(),
},
json_vec_derive::json_struct_vec::JsonColumn {
value: "5".to_string(),
},
json_vec_derive::json_struct_vec::JsonColumn {
value: "6".to_string(),
},
],
};
let _result = json_vec.clone().into_active_model().insert(db).await?;
let model = json_vec_derive::json_struct_vec::Entity::find()
.filter(json_vec_derive::json_struct_vec::Column::Id.eq(json_vec.id))
.one(db)
.await?;
assert_eq!(model, Some(json_vec));
Ok(())
}