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 ruma_common::api::{
MatrixVersion, OutgoingRequest as _, OutgoingResponse as _, SendAccessToken,
};
mod get {
ruma_common::api::ruma_api! {
metadata: {
description: "Does something.",
method: GET,
name: "no_fields",
unstable_path: "/_matrix/my/endpoint",
rate_limited: false,
authentication: None,
}
request: {}
response: {}
}
}
mod post {
ruma_common::api::ruma_api! {
metadata: {
description: "Does something.",
method: POST,
name: "no_fields",
unstable_path: "/_matrix/my/endpoint",
rate_limited: false,
authentication: None,
}
request: {}
response: {}
}
}
#[test]
fn empty_post_request_http_repr() {
let req = post::Request {};
let http_req = req
.try_into_http_request::<Vec<u8>>(
"https://homeserver.tld",
SendAccessToken::None,
&[MatrixVersion::V1_1],
)
.unwrap();
// Empty POST requests should contain an empty dictionary as a body...
assert_eq!(http_req.body(), b"{}");
}
#[test]
fn empty_get_request_http_repr() {
let req = get::Request {};
let http_req = req
.try_into_http_request::<Vec<u8>>(
"https://homeserver.tld",
SendAccessToken::None,
&[MatrixVersion::V1_1],
)
.unwrap();
// ... but GET requests' bodies should be empty.
assert_eq!(http_req.body().len(), 0);
}
#[test]
fn empty_post_response_http_repr() {
let res = post::Response {};
let http_res = res.try_into_http_response::<Vec<u8>>().unwrap();
// For the response, the body should be an empty dict again...
assert_eq!(http_res.body(), b"{}");
}
#[test]
fn empty_get_response_http_repr() {
let res = get::Response {};
let http_res = res.try_into_http_response::<Vec<u8>>().unwrap();
// ... even for GET requests.
assert_eq!(http_res.body(), b"{}");
}
|