diff options
author | alpaylan | 2021-04-14 02:35:03 +0300 |
---|---|---|
committer | alpaylan | 2021-04-14 02:35:03 +0300 |
commit | 6007918adcff0a52748f8c4fb4154e904bc2d08a (patch) | |
tree | 30a32da3e35c449ad5a3ce5a7e501cb529338c54 | |
parent | 2a6db865a4c7408f0bb56477aaa63cef4ecd60a4 (diff) | |
download | gradecoin-6007918adcff0a52748f8c4fb4154e904bc2d08a.tar.gz gradecoin-6007918adcff0a52748f8c4fb4154e904bc2d08a.tar.bz2 gradecoin-6007918adcff0a52748f8c4fb4154e904bc2d08a.zip |
finished user testing.
-rw-r--r-- | src/schema.rs | 6 | ||||
-rw-r--r-- | 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 { | |||
121 | } | 121 | } |
122 | 122 | ||
123 | /// Simply a Student | 123 | /// Simply a Student |
124 | #[derive(Serialize, Deserialize, Debug)] | 124 | #[derive(Serialize, Deserialize, Debug, PartialEq)] |
125 | pub struct User { | 125 | pub struct User { |
126 | pub user_id: MetuId, | 126 | pub user_id: MetuId, |
127 | pub public_key: String, | 127 | pub public_key: String, |
@@ -129,13 +129,13 @@ pub struct User { | |||
129 | } | 129 | } |
130 | 130 | ||
131 | /// The values will be hard coded so MetuId::new() can accept/reject values based on that | 131 | /// The values will be hard coded so MetuId::new() can accept/reject values based on that |
132 | #[derive(Serialize, Deserialize, Debug)] | 132 | #[derive(Serialize, Deserialize, Debug, PartialEq)] |
133 | pub struct MetuId { | 133 | pub struct MetuId { |
134 | id: String, | 134 | id: String, |
135 | } | 135 | } |
136 | 136 | ||
137 | // TODO: this will arrive encrypted <13-04-21, yigit> // | 137 | // TODO: this will arrive encrypted <13-04-21, yigit> // |
138 | #[derive(Serialize, Deserialize, Debug)] | 138 | #[derive(Serialize, Deserialize, Debug, PartialEq)] |
139 | pub struct AuthRequest { | 139 | pub struct AuthRequest { |
140 | pub student_id: String, | 140 | pub student_id: String, |
141 | pub public_key: String, | 141 | 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 { | |||
180 | 180 | ||
181 | #[test] | 181 | #[test] |
182 | fn user_serialize_correctly() { | 182 | fn user_serialize_correctly() { |
183 | let user = User { | ||
184 | user_id: MetuId::new("e254275".to_owned()).unwrap(), | ||
185 | public_key: "public_key".to_owned(), | ||
186 | balance: 0 | ||
187 | }; | ||
183 | 188 | ||
189 | assert_tokens( | ||
190 | &user, | ||
191 | &[ | ||
192 | Token::Struct{name: "User", len: 3}, | ||
193 | Token::String("user_id"), | ||
194 | Token::Struct {name: "MetuId", len: 1}, | ||
195 | Token::String("id"), | ||
196 | Token::String("e254275"), | ||
197 | Token::StructEnd, | ||
198 | Token::String("public_key"), | ||
199 | Token::String("public_key"), | ||
200 | Token::String("balance"), | ||
201 | Token::I32(0), | ||
202 | Token::StructEnd, | ||
203 | ] | ||
204 | ) | ||
184 | } | 205 | } |
185 | 206 | ||
186 | #[test] | 207 | #[test] |
187 | fn user_deserialize_correctly() { | 208 | fn user_deserialize_correctly() { |
209 | let expected_user = User { | ||
210 | user_id: MetuId::new("e254275".to_owned()).unwrap(), | ||
211 | public_key: "public_key".to_owned(), | ||
212 | balance: 0 | ||
213 | }; | ||
214 | let data = r#"{"user_id":{"id":"e254275"},"public_key":"public_key","balance":0}"#; | ||
215 | let user: User = serde_json::from_str(data).unwrap(); | ||
216 | |||
217 | assert_eq!(user, expected_user); | ||
188 | 218 | ||
189 | } | 219 | } |
190 | 220 | ||