use std::sync::Arc;
use serde_json::Value;
use crate::core::encoding::encode_segment;
use crate::core::error::Result;
use crate::http::client::Inner;
use crate::http::transport::HttpMethod;
#[derive(Debug, Clone)]
pub struct FeatureMatrix {
inner: Arc<Inner>,
}
impl FeatureMatrix {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn retrieve(&self) -> Result<Value> {
self.inner
.request(HttpMethod::Get, "/feature-matrix", None, &[], None)
.await
}
pub async fn retrieve_for_merchant(&self, merchant_id: &str) -> Result<Value> {
let path = format!("/feature-matrix/{}", encode_segment(merchant_id));
self.inner
.request(HttpMethod::Get, &path, None, &[], None)
.await
}
}
#[cfg(test)]
mod tests {
use crate::http::mock::{Step, client_with};
#[tokio::test]
async fn retrieve_gets_the_feature_matrix_root() {
let (client, mock) = client_with(vec![Step::ok(r#"{"connectors":[]}"#)]);
client.feature_matrix().retrieve().await.unwrap();
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "GET");
assert_eq!(seen[0].url, "https://api.test/feature-matrix");
}
#[tokio::test]
async fn retrieve_for_merchant_encodes_the_merchant_id() {
let (client, mock) = client_with(vec![Step::ok(r#"{"connectors":[]}"#)]);
client
.feature_matrix()
.retrieve_for_merchant("mer/1")
.await
.unwrap();
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "GET");
assert_eq!(seen[0].url, "https://api.test/feature-matrix/mer%2F1");
}
}