aboutsummaryrefslogtreecommitdiffstats
path: root/tests/zotapi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/zotapi.rs')
-rw-r--r--tests/zotapi.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/zotapi.rs b/tests/zotapi.rs
index 8c9d0b0..38bdf8a 100644
--- a/tests/zotapi.rs
+++ b/tests/zotapi.rs
@@ -29,8 +29,7 @@ fn default_mock(method: &str, url: &str) -> Mock {
}
fn client() -> zotapi::Client {
- let listen_url = format!("http://{}", mockito::SERVER_ADDRESS);
- zotapi::client(&listen_url, "testuser", "test1234")
+ zotapi::client(&mockito::server_url(), "testuser", "test1234")
}
#[test]
@@ -80,14 +79,14 @@ fn create_new_post() {
#[test]
fn create_new_post_with_title() {
- // Note this regex is not as good as it could be. But since the rust regex crate
- // don't support back references it's the best we can do and not care about the
- // oder of the entries.
- let expected_body = Matcher::Regex(r"(title=A\+title&?|body=This\+is\+a\+test&?){2}".into());
-
let m = mock("POST", "/api/z/1.0/item/update")
.match_header("Authorization", Matcher::Regex(r"Basic \w+".into()))
- .match_body(expected_body)
+ .match_body(
+ Matcher::AllOf(vec![
+ Matcher::UrlEncoded("title".to_string(), "A+title".to_string()),
+ Matcher::UrlEncoded("body".to_string(), "This+is+a+test".to_string()),
+ ])
+ )
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
@@ -209,8 +208,8 @@ fn fetch_privacy_groups() {
#[test]
fn fetch_members_of_group_by_group_id() {
- let m = mock("GET", Matcher::Regex(
- r"^/api/z/1.0/group_members\?([^&]*&)*group_id=42".into()))
+ let m = mock("GET", "/api/z/1.0/group_members")
+ .match_query(Matcher::UrlEncoded("group_id".to_string(), "42".to_string()))
.match_header("Authorization", Matcher::Regex(r"Basic \w+".into()))
.with_status(200)
.with_header("content-type", "application/json")
@@ -223,8 +222,8 @@ fn fetch_members_of_group_by_group_id() {
#[test]
fn fetch_members_of_group_by_group_name() {
- let m = mock("GET", Matcher::Regex(
- r"^/api/z/1.0/group_members\?([^&]*&)*group_name=Friends\+of\+pain".into()))
+ let m = mock("GET", "/api/z/1.0/group_members")
+ .match_query(Matcher::UrlEncoded("group_name".into(), "Friends+of+pain".into()))
.match_header("Authorization", Matcher::Regex(r"Basic \w+".into()))
.with_status(200)
.with_header("content-type", "application/json")