-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
timestamp_tests.rs
116 lines (102 loc) 路 3.41 KB
/
timestamp_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#![allow(unused_imports, dead_code)]
pub mod common;
pub use common::{features::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel};
#[sea_orm_macros::test]
async fn main() -> Result<(), DbErr> {
let ctx = TestContext::new("bakery_chain_schema_timestamp_tests").await;
create_tables(&ctx.db).await?;
create_applog(&ctx.db).await?;
create_satellites_log(&ctx.db).await?;
ctx.delete().await;
Ok(())
}
pub async fn create_applog(db: &DatabaseConnection) -> Result<(), DbErr> {
let log = applog::Model {
id: 1,
action: "Testing".to_owned(),
json: Json::String("HI".to_owned()),
created_at: "2021-09-17T17:50:20+08:00".parse().unwrap(),
};
let res = Applog::insert(log.clone().into_active_model())
.exec(db)
.await?;
assert_eq!(log.id, res.last_insert_id);
assert_eq!(Applog::find().one(db).await?, Some(log.clone()));
#[cfg(feature = "sqlx-sqlite")]
assert_eq!(
Applog::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"action": "Testing",
"json": r#""HI""#,
"created_at": "2021-09-17T17:50:20+08:00",
}))
);
#[cfg(feature = "sqlx-mysql")]
assert_eq!(
Applog::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"action": "Testing",
"json": "HI",
"created_at": "2021-09-17T09:50:20Z",
}))
);
#[cfg(feature = "sqlx-postgres")]
assert_eq!(
Applog::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"action": "Testing",
"json": "HI",
"created_at": "2021-09-17T09:50:20Z",
}))
);
Ok(())
}
pub async fn create_satellites_log(db: &DatabaseConnection) -> Result<(), DbErr> {
let archive = satellite::Model {
id: 1,
satellite_name: "Sea-00001-2022".to_owned(),
launch_date: "2022-01-07T12:11:23Z".parse().unwrap(),
deployment_date: "2022-01-07T12:11:23Z".parse().unwrap(),
};
let res = Satellite::insert(archive.clone().into_active_model())
.exec(db)
.await?;
assert_eq!(archive.id, res.last_insert_id);
assert_eq!(Satellite::find().one(db).await?, Some(archive.clone()));
#[cfg(feature = "sqlx-sqlite")]
assert_eq!(
Satellite::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"satellite_name": "Sea-00001-2022",
"launch_date": "2022-01-07T12:11:23+00:00",
"deployment_date": "2022-01-07T12:11:23Z".parse::<DateTimeLocal>().unwrap().to_rfc3339(),
}))
);
#[cfg(feature = "sqlx-mysql")]
assert_eq!(
Satellite::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"satellite_name": "Sea-00001-2022",
"launch_date": "2022-01-07T12:11:23Z",
"deployment_date": "2022-01-07T12:11:23Z",
}))
);
#[cfg(feature = "sqlx-postgres")]
assert_eq!(
Satellite::find().into_json().one(db).await?,
Some(serde_json::json!({
"id": 1,
"satellite_name": "Sea-00001-2022",
"launch_date": "2022-01-07T12:11:23Z",
"deployment_date": "2022-01-07T12:11:23Z",
}))
);
Ok(())
}