@smbcloud / cli / commits / 5ec6270

Add test parsing

Seto Elkahfi committed Sep 16, 2023 at 17:46 UTC 5ec62700234c6ccdb0956e39e76d2d9f3792a682
6 files changed +100
smbpndk-model/src/account.rs
+24
@@ -78,3 +78,27 @@ pub struct GithubInfo {
78 pub created_at: String,
79 pub updated_at: String,
80 }
81 +
82 +#[cfg(test)]
83 +mod tests {
84 + use super::*;
85 + use serde_json::json;
86 + #[test]
87 + fn test_smb_authorization() {
88 + let smb_authorization = SmbAuthorization {
89 + message: "test".to_owned(),
90 + user: None,
91 + user_email: None,
92 + user_info: None,
93 + error_code: Some(ErrorCode::EmailUnverified),
94 + };
95 + let json = json!({
96 + "message": "test",
97 + "user": null,
98 + "user_email": null,
99 + "user_info": null,
100 + "error_code": 1001,
101 + });
102 + assert_eq!(serde_json::to_value(smb_authorization).unwrap(), json);
103 + }
104 +}
smbpndk-model/src/app_auth.rs
+18
@@ -18,3 +18,21 @@ pub struct AuthAppCreate {
18 pub name: String,
19 pub description: String,
20 }
21 +
22 +#[cfg(test)]
23 +mod tests {
24 + use super::*;
25 + use serde_json::json;
26 + #[test]
27 + fn test_auth_app_create() {
28 + let auth_app_create = AuthAppCreate {
29 + name: "test".to_owned(),
30 + description: "test".to_owned(),
31 + };
32 + let json = json!({
33 + "name": "test",
34 + "description": "test",
35 + });
36 + assert_eq!(serde_json::to_value(auth_app_create).unwrap(), json);
37 + }
38 +}
smbpndk-model/src/forgot.rs
+20
@@ -21,3 +21,23 @@ pub struct UserUpdatePassword {
21 pub password: String,
22 pub password_confirmation: String,
23 }
24 +
25 +#[cfg(test)]
26 +mod tests {
27 + use super::*;
28 + use serde_json::json;
29 + #[test]
30 + fn test_update_password() {
31 + let args = Args {
32 + user: Email {
33 + email: "test".to_owned(),
34 + },
35 + };
36 + let json = json!({
37 + "user": {
38 + "email": "test",
39 + },
40 + });
41 + assert_eq!(serde_json::to_value(args).unwrap(), json);
42 + }
43 +}
smbpndk-model/src/lib.rs
+13
@@ -41,4 +41,17 @@ pub mod ar_date_format {
41 Utc.datetime_from_str(&s, FORMAT)
42 .map_err(serde::de::Error::custom)
43 }
44 +
45 + #[cfg(test)]
46 + mod tests {
47 + use super::*;
48 + use chrono::TimeZone;
49 + use serde_json::json;
50 + #[test]
51 + fn test_ar_date_format() {
52 + let date = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0);
53 + let json = json!("2020-01-01T00:00:00Z");
54 + assert_eq!(serde_json::to_value(date.unwrap()).unwrap(), json);
55 + }
56 + }
57 }
smbpndk-model/src/login.rs
+19
@@ -1,6 +1,7 @@
1 use crate::account::{Data, Status};
2 use serde::{Deserialize, Serialize};
3
4 +#[derive(Debug, Serialize)]
5 pub struct LoginArgs {
6 pub username: String,
7 pub password: String,
@@ -22,3 +23,21 @@ pub struct LoginResult {
23 pub status: Status,
24 pub data: Data,
25 }
26 +
27 +#[cfg(test)]
28 +mod tests {
29 + use super::*;
30 + use serde_json::json;
31 + #[test]
32 + fn test_login() {
33 + let args = LoginArgs {
34 + username: "test".to_owned(),
35 + password: "test".to_owned(),
36 + };
37 + let json = json!({
38 + "username": "test",
39 + "password": "test",
40 + });
41 + assert_eq!(serde_json::to_value(args).unwrap(), json);
42 + }
43 +}
\ No newline at end of file
smbpndk-model/src/signup.rs
+6
@@ -62,3 +62,9 @@ impl Display for GithubEmail {
62 write!(f, "{}", self.email)
63 }
64 }
65 +
66 +#[cfg(test)]
67 +mod tests {
68 +
69 +
70 +}
\ No newline at end of file