-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.rs
138 lines (128 loc) · 3.14 KB
/
page.rs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
mod common;
use common::API;
use serial_test::serial;
use wikijs::page::{PageError, PageTreeMode};
#[test]
#[serial]
fn page_get_nonexistent() {
let result = API.page_get(1000000);
assert!(result.is_err());
assert_eq!(result.unwrap_err() == PageError::PageNotFound, true);
}
#[test]
#[serial]
fn page_get_by_path_nonexistent() {
let result = API.page_get_by_path("qwerty".to_string(), "en".to_string());
assert!(result.is_err());
assert_eq!(result.unwrap_err() == PageError::PageNotFound, true);
}
#[test]
#[serial]
fn page_list_empty() {
let result = API.page_list(None, None, None, None, None, None, None);
assert!(result.is_ok());
assert_eq!(result.unwrap().len(), 0);
}
#[test]
#[serial]
fn page_tag_list_empty() {
let result = API.page_tag_list();
assert!(result.is_ok());
assert_eq!(result.unwrap().len(), 0);
}
#[test]
#[serial]
fn page_tree_empty() {
let result =
API.page_tree_get(0, PageTreeMode::ALL, true, "en".to_string());
assert!(result.is_ok());
assert_eq!(result.unwrap().len(), 0);
}
#[test]
#[serial]
fn page_delete_nonexistent() {
let result = API.page_delete(1000000);
assert!(result.is_err());
assert_eq!(result.unwrap_err() == PageError::PageNotFound, true);
}
#[test]
#[serial]
fn page_render_nonexistent() {
let result = API.page_render(1000000);
assert!(result.is_err());
assert_eq!(result.unwrap_err() == PageError::PageNotFound, true);
}
#[test]
#[serial]
fn page_create_get_delete() {
let result = API.page_create(
"...".to_string(),
"".to_string(),
"markdown".to_string(),
true,
false,
"en".to_string(),
"test".to_string(),
None,
None,
None,
None,
Vec::new(),
"test".to_string(),
);
assert!(result.is_ok());
let result2 = API.page_get_by_path("test".to_string(), "en".to_string());
assert!(result2.is_ok());
let id = result2.unwrap().id;
let result3 = API.page_delete(id);
assert!(result3.is_ok());
let result4 = API.page_get(id);
assert!(result4.is_err());
}
#[test]
#[serial]
fn page_update() {
let result = API.page_create(
"...".to_string(),
"".to_string(),
"markdown".to_string(),
true,
false,
"en".to_string(),
"test".to_string(),
None,
None,
None,
None,
Vec::new(),
"test".to_string(),
);
assert!(result.is_ok());
let result2 = API.page_get_by_path("test".to_string(), "en".to_string());
assert!(result2.is_ok());
let id = result2.unwrap().id;
let result3 = API.page_update(
id,
None,
Some("test2".to_string()),
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
Some("test2".to_string()),
);
assert!(result3.is_ok());
let result4 = API.page_get(id);
assert!(result4.is_ok());
let page = result4.unwrap();
assert_eq!(page.description, "test2");
assert_eq!(page.title, "test2");
let result5 = API.page_delete(id);
assert!(result5.is_ok());
}