forked from kenkoooo/AtCoderProblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_problem_list_manager.rs
More file actions
82 lines (71 loc) · 2.44 KB
/
test_problem_list_manager.rs
File metadata and controls
82 lines (71 loc) · 2.44 KB
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
use sql_client::{
internal::problem_list_manager::{ListItem, ProblemList, ProblemListManager},
PgPool,
};
mod utils;
#[sqlx::test]
async fn test_problem_list_manager(pool: PgPool) {
let internal_user_id = "user_id";
let atcoder_user_id = "atcoder_id";
let list_name = "list_name";
let problem_id = "problem_id";
utils::initialize(&pool).await;
utils::setup_internal_user(&pool, internal_user_id, atcoder_user_id).await;
assert!(
pool.get_list(internal_user_id).await.unwrap().is_empty(),
"`get_list` here should return an empty list, but got not empty."
);
let list_id = pool.create_list(internal_user_id, list_name).await.unwrap();
let list = pool.get_single_list(&list_id).await.unwrap();
assert_eq!(
list,
ProblemList {
internal_list_id: list_id.clone(),
internal_list_name: list_name.to_string(),
internal_user_id: internal_user_id.to_string(),
items: vec![],
},
"`get_single_list` returned an unexpected value."
);
pool.update_list(&list_id, "list_name_updated")
.await
.unwrap();
let list = pool.get_single_list(&list_id).await.unwrap();
assert_eq!(
list.internal_list_name, "list_name_updated",
"`internal_list_name` should be updated, but not."
);
pool.add_item(&list_id, problem_id).await.unwrap();
let list = pool.get_single_list(&list_id).await.unwrap();
assert_eq!(
list.items,
vec![ListItem {
problem_id: problem_id.to_string(),
memo: "".to_string(),
}],
"The item that has been added to the list is not found."
);
pool.update_item(&list_id, problem_id, "memo_updated")
.await
.unwrap();
let list = pool.get_single_list(&list_id).await.unwrap();
assert_eq!(
list.items,
vec![ListItem {
problem_id: problem_id.to_string(),
memo: "memo_updated".to_string(),
}],
"`memo` should be updated, but not."
);
pool.delete_item(&list_id, problem_id).await.unwrap();
let list = pool.get_single_list(&list_id).await.unwrap();
assert!(
list.items.is_empty(),
"The list still has its item unexpectedly."
);
pool.delete_list(&list_id).await.unwrap();
assert!(
pool.get_list(internal_user_id).await.unwrap().is_empty(),
"The list should be deleted, but still exists."
);
}