From c9209d1c311e1527c0531c995c6ebae7cc5accca Mon Sep 17 00:00:00 2001 From: alpaylan Date: Wed, 14 Apr 2021 02:35:03 +0300 Subject: finished user testing. --- src/schema.rs | 6 +++--- tests/schema_tests.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/schema.rs b/src/schema.rs index 5546d12..55e46c0 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -121,7 +121,7 @@ impl Block { } /// Simply a Student -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct User { pub user_id: MetuId, pub public_key: String, @@ -129,13 +129,13 @@ pub struct User { } /// The values will be hard coded so MetuId::new() can accept/reject values based on that -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct MetuId { id: String, } // TODO: this will arrive encrypted <13-04-21, yigit> // -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct AuthRequest { pub student_id: String, pub public_key: String, diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs index 7c6833b..23537fb 100644 --- a/tests/schema_tests.rs +++ b/tests/schema_tests.rs @@ -180,11 +180,41 @@ mod tests { #[test] fn user_serialize_correctly() { + let user = User { + user_id: MetuId::new("e254275".to_owned()).unwrap(), + public_key: "public_key".to_owned(), + balance: 0 + }; + assert_tokens( + &user, + &[ + Token::Struct{name: "User", len: 3}, + Token::String("user_id"), + Token::Struct {name: "MetuId", len: 1}, + Token::String("id"), + Token::String("e254275"), + Token::StructEnd, + Token::String("public_key"), + Token::String("public_key"), + Token::String("balance"), + Token::I32(0), + Token::StructEnd, + ] + ) } #[test] fn user_deserialize_correctly() { + let expected_user = User { + user_id: MetuId::new("e254275".to_owned()).unwrap(), + public_key: "public_key".to_owned(), + balance: 0 + }; + let data = r#"{"user_id":{"id":"e254275"},"public_key":"public_key","balance":0}"#; + let user: User = serde_json::from_str(data).unwrap(); + + assert_eq!(user, expected_user); } -- cgit v1.2.3-70-g09d2