client-api: Fix tests for unstable-pre-spec
This commit is contained in:
parent
aeb4a24492
commit
24e2f3996a
@ -257,6 +257,7 @@ mod login_type_serde;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use matches::assert_matches;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use serde_json::to_value as to_json_value;
|
use serde_json::to_value as to_json_value;
|
||||||
@ -266,28 +267,29 @@ mod tests {
|
|||||||
use super::{IdentityProvider, IdentityProviderBrand, SsoLoginType, TokenLoginType};
|
use super::{IdentityProvider, IdentityProviderBrand, SsoLoginType, TokenLoginType};
|
||||||
use super::{LoginType, PasswordLoginType};
|
use super::{LoginType, PasswordLoginType};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
pub flows: Vec<LoginType>,
|
pub flows: Vec<LoginType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_password_login_type() {
|
fn deserialize_password_login_type() {
|
||||||
assert_eq!(
|
assert_matches!(
|
||||||
from_json_value::<Foo>(json!({
|
from_json_value::<Foo>(json!({
|
||||||
"flows": [
|
"flows": [
|
||||||
{ "type": "m.login.password" }
|
{ "type": "m.login.password" }
|
||||||
],
|
],
|
||||||
}))
|
})),
|
||||||
.unwrap(),
|
Ok(Foo { flows })
|
||||||
Foo { flows: vec![LoginType::Password(PasswordLoginType {})] }
|
if flows.len() == 1
|
||||||
|
&& matches!(flows[0], LoginType::Password(PasswordLoginType {}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
fn deserialize_sso_login_type() {
|
fn deserialize_sso_login_type() {
|
||||||
let foo = from_json_value::<Foo>(json!({
|
let mut foo = from_json_value::<Foo>(json!({
|
||||||
"flows": [
|
"flows": [
|
||||||
{
|
{
|
||||||
"type": "m.login.sso",
|
"type": "m.login.sso",
|
||||||
@ -308,27 +310,38 @@ mod tests {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
let mut flow = foo.flows.pop();
|
||||||
foo,
|
assert_matches!(foo.flows.as_slice(), []);
|
||||||
Foo {
|
|
||||||
flows: vec![LoginType::Sso(SsoLoginType {
|
let mut identity_providers = match flow {
|
||||||
identity_providers: vec![
|
Some(LoginType::Sso(SsoLoginType { identity_providers })) => identity_providers,
|
||||||
IdentityProvider {
|
_ => panic!("unexpected enum variant: {:?}", flow),
|
||||||
id: "oidc-gitlab".into(),
|
};
|
||||||
name: "GitLab".into(),
|
|
||||||
icon: Some("mxc://localhost/gitlab-icon".into()),
|
let provider = identity_providers.pop();
|
||||||
brand: Some(IdentityProviderBrand::GitLab)
|
assert_matches!(
|
||||||
},
|
provider,
|
||||||
IdentityProvider {
|
Some(IdentityProvider {
|
||||||
id: "custom".into(),
|
id,
|
||||||
name: "Custom".into(),
|
name,
|
||||||
icon: None,
|
icon: None,
|
||||||
brand: None
|
brand: None,
|
||||||
}
|
}) if id == "custom"
|
||||||
]
|
&& name == "Custom"
|
||||||
})]
|
);
|
||||||
}
|
|
||||||
)
|
let provider = identity_providers.pop();
|
||||||
|
assert_matches!(
|
||||||
|
provider,
|
||||||
|
Some(IdentityProvider {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
icon: Some(icon),
|
||||||
|
brand: Some(IdentityProviderBrand::GitLab),
|
||||||
|
}) if id == "oidc-gitlab"
|
||||||
|
&& name == "GitLab"
|
||||||
|
&& icon.to_string() == "mxc://localhost/gitlab-icon"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -51,9 +51,9 @@ impl Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(all(test, feature = "client"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ruma_api::OutgoingRequest;
|
use ruma_api::OutgoingRequest as _;
|
||||||
|
|
||||||
use super::Request;
|
use super::Request;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user