summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYigit Sever2021-04-09 17:10:02 +0300
committerYigit Sever2021-04-09 17:10:02 +0300
commit793bf9630d7ddf90b67e67091c05f3f252273d5c (patch)
treed959a8b40ce1266431dcbcc41784ba84a6efb782 /src
parentda4971b7b7e68d86606957d2eac7703f9ac7a5cd (diff)
downloadgradecoin-793bf9630d7ddf90b67e67091c05f3f252273d5c.tar.gz
gradecoin-793bf9630d7ddf90b67e67091c05f3f252273d5c.tar.bz2
gradecoin-793bf9630d7ddf90b67e67091c05f3f252273d5c.zip
Remove old routes tests
Diffstat (limited to 'src')
-rw-r--r--src/routes.rs276
1 files changed, 0 insertions, 276 deletions
diff --git a/src/routes.rs b/src/routes.rs
index f67c3b0..23fcd29 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -46,279 +46,3 @@ pub fn block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = Reject
46 .and_then(handlers::propose_block) 46 .and_then(handlers::propose_block)
47} 47}
48 48
49// TODO: write tests <07-04-21, yigit> //
50
51//#[cfg(test)]
52//mod tests {
53// use super::*;
54
55// use chrono::prelude::*;
56// use std::sync::Arc;
57// use tokio::sync::Mutex;
58// use warp::http::StatusCode;
59
60// use crate::schema::{Game, Genre};
61
62// // Mocked dataset for each test
63
64// fn mocked_db() -> Db {
65// Arc::new(Mutex::new(vec![
66// Game {
67// id: 1,
68// title: String::from("Crappy title"),
69// rating: 35,
70// genre: Genre::RolePlaying,
71// description: Some(String::from("Test description...")),
72// release_date: NaiveDate::from_ymd(2011, 9, 22).and_hms(0, 0, 0),
73// },
74// Game {
75// id: 2,
76// title: String::from("Decent game"),
77// rating: 84,
78// genre: Genre::Strategy,
79// description: None,
80// release_date: NaiveDate::from_ymd(2014, 3, 11).and_hms(0, 0, 0),
81// },
82// ]))
83// }
84
85// fn mocked_game() -> Game {
86// Game {
87// id: 3,
88// title: String::from("Another game"),
89// rating: 65,
90// description: None,
91// genre: Genre::Strategy,
92// release_date: NaiveDate::from_ymd(2016, 3, 11).and_hms(0, 0, 0),
93// }
94// }
95
96// #[tokio::test]
97// async fn get_list_of_games_200() {
98// let db = mocked_db();
99// let filter = games_routes(db);
100
101// let res = warp::test::request().method("GET").path("/games").reply(&filter).await;
102
103// assert_eq!(res.status(), StatusCode::OK);
104
105// let expected_json_body = r#"[{"id":1,"title":"Crappy title","rating":35,"genre":"ROLE_PLAYING","description":"Test description...","releaseDate":"2011-09-22T00:00:00"},{"id":2,"title":"Decent game","rating":84,"genre":"STRATEGY","description":null,"releaseDate":"2014-03-11T00:00:00"}]"#;
106// assert_eq!(res.body(), expected_json_body);
107// }
108
109// #[tokio::test]
110// async fn get_list_of_games_with_options_200() {
111// let db = mocked_db();
112// let filter = games_routes(db);
113
114// let res = warp::test::request()
115// .method("GET")
116// .path("/games?offset=1&limit=5")
117// .reply(&filter)
118// .await;
119
120// assert_eq!(res.status(), StatusCode::OK);
121
122// let expected_json_body = r#"[{"id":2,"title":"Decent game","rating":84,"genre":"STRATEGY","description":null,"releaseDate":"2014-03-11T00:00:00"}]"#;
123// assert_eq!(res.body(), expected_json_body);
124// }
125
126// #[tokio::test]
127// async fn get_empty_list_with_offset_overshot_200() {
128// let db = mocked_db();
129// let filter = games_routes(db);
130
131// let res = warp::test::request()
132// .method("GET")
133// .path("/games?offset=5&limit=5")
134// .reply(&filter)
135// .await;
136
137// assert_eq!(res.status(), StatusCode::OK);
138
139// let expected_json_body = r#"[]"#;
140// assert_eq!(res.body(), expected_json_body);
141// }
142
143// #[tokio::test]
144// async fn get_incorrect_options_400() {
145// let db = mocked_db();
146// let filter = games_routes(db);
147
148// let res = warp::test::request()
149// .method("GET")
150// .path("/games?offset=a&limit=b")
151// .reply(&filter)
152// .await;
153
154// assert_eq!(res.status(), StatusCode::BAD_REQUEST);
155// }
156
157// #[tokio::test]
158// async fn get_wrong_path_405() {
159// let db = mocked_db();
160// let filter = games_routes(db);
161
162// let res = warp::test::request()
163// .method("GET")
164// .path("/games/42")
165// .reply(&filter)
166// .await;
167
168// assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
169// }
170
171// #[tokio::test]
172// async fn post_json_201() {
173// let db = mocked_db();
174// let filter = games_routes(db.clone());
175
176// let res = warp::test::request()
177// .method("POST")
178// .json(&mocked_game())
179// .path("/games")
180// .reply(&filter)
181// .await;
182
183// assert_eq!(res.status(), StatusCode::CREATED);
184// assert_eq!(db.lock().await.len(), 3);
185// }
186
187// #[tokio::test]
188// async fn post_too_long_content_413() {
189// let db = mocked_db();
190// let filter = games_routes(db);
191
192// let res = warp::test::request()
193// .method("POST")
194// .header("content-length", 1024 * 36)
195// .path("/games")
196// .reply(&filter)
197// .await;
198
199// assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE);
200// }
201
202// #[tokio::test]
203// async fn post_wrong_payload_400() {
204// let db = mocked_db();
205// let filter = games_routes(db);
206
207// let res = warp::test::request()
208// .method("POST")
209// .body(&r#"{"id":4}"#)
210// .path("/games")
211// .reply(&filter)
212// .await;
213
214// assert_eq!(res.status(), StatusCode::BAD_REQUEST);
215// }
216
217// #[tokio::test]
218// async fn post_wrong_path_405() {
219// let db = mocked_db();
220// let filter = games_routes(db);
221
222// let res = warp::test::request()
223// .method("POST")
224// .path("/games/42")
225// .reply(&filter)
226// .await;
227
228// assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
229// }
230
231// #[tokio::test]
232// async fn put_json_200() {
233// let db = mocked_db();
234// let filter = games_routes(db.clone());
235
236// let res = warp::test::request()
237// .method("PUT")
238// .json(&mocked_game())
239// .path("/games/2")
240// .reply(&filter)
241// .await;
242
243// assert_eq!(res.status(), StatusCode::OK);
244
245// let db = db.lock().await;
246// let ref title = db[1].title;
247// assert_eq!(title, "Another game");
248// }
249
250// #[tokio::test]
251// async fn put_wrong_id_404() {
252// let db = mocked_db();
253// let filter = games_routes(db);
254
255// let res = warp::test::request()
256// .method("PUT")
257// .json(&mocked_game())
258// .path("/games/42")
259// .reply(&filter)
260// .await;
261
262// assert_eq!(res.status(), StatusCode::NOT_FOUND);
263// }
264
265// #[tokio::test]
266// async fn put_wrong_payload_400() {
267// let db = mocked_db();
268// let filter = games_routes(db);
269
270// let res = warp::test::request()
271// .method("PUT")
272// .header("content-length", 1024 * 16)
273// .body(&r#"{"id":2"#)
274// .path("/games/2")
275// .reply(&filter)
276// .await;
277
278// assert_eq!(res.status(), StatusCode::BAD_REQUEST);
279// }
280
281// #[tokio::test]
282// async fn put_too_long_content_413() {
283// let db = mocked_db();
284// let filter = games_routes(db);
285
286// let res = warp::test::request()
287// .method("PUT")
288// .header("content-length", 1024 * 36)
289// .path("/games/2")
290// .reply(&filter)
291// .await;
292
293// assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE);
294// }
295
296// #[tokio::test]
297// async fn delete_wrong_id_404() {
298// let db = mocked_db();
299// let filter = games_routes(db);
300
301// let res = warp::test::request()
302// .method("DELETE")
303// .path("/games/42")
304// .reply(&filter)
305// .await;
306
307// assert_eq!(res.status(), StatusCode::NOT_FOUND);
308// }
309
310// #[tokio::test]
311// async fn delete_game_204() {
312// let db = mocked_db();
313// let filter = games_routes(db.clone());
314
315// let res = warp::test::request()
316// .method("DELETE")
317// .path("/games/1")
318// .reply(&filter)
319// .await;
320
321// assert_eq!(res.status(), StatusCode::NO_CONTENT);
322// assert_eq!(db.lock().await.len(), 1);
323// }
324//}