use super::helper::{MOCK_ONE_PATH, MOCK_TOTAL_PATH};
use super::model::MockQuery;
use crate::e2e::codegen::percent_encode_query;
pub(crate) fn build_path_and_query(query: &MockQuery) -> String {
match query {
MockQuery::Total => format!("{MOCK_TOTAL_PATH}?prefix="),
MockQuery::Count(key) => format!("{MOCK_ONE_PATH}?key={}", percent_encode_query(key)),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn total_queries_the_total_endpoint_with_an_empty_prefix() {
assert_eq!(
build_path_and_query(&MockQuery::Total),
"/__alef/requests/total?prefix="
);
}
#[test]
fn count_percent_encodes_a_method_and_path_key() {
assert_eq!(
build_path_and_query(&MockQuery::Count("POST /v1/chat".to_string())),
"/__alef/requests/one?key=POST%20%2Fv1%2Fchat"
);
}
#[test]
fn count_percent_encodes_a_bare_path_key() {
assert_eq!(
build_path_and_query(&MockQuery::Count("/v1/chat".to_string())),
"/__alef/requests/one?key=%2Fv1%2Fchat"
);
}
}