Skip to content

Commit

Permalink
fix: duplicated params
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser committed Feb 27, 2023
1 parent 053cad8 commit 2fbeda7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::constants::{
END_AT, EQUAL_TO, EXPORT, FORMAT, LIMIT_TO_FIRST, LIMIT_TO_LAST, ORDER_BY, SHALLOW, START_AT,
};
use crate::Firebase;
use itertools::Itertools;
use std::collections::HashMap;
use url::Url;
use itertools::Itertools;

#[derive(Debug)]
pub struct Params {
Expand All @@ -27,11 +27,10 @@ impl Params {
}

pub fn add_param<T>(&mut self, key: &str, value: T) -> &mut Self
where
T: ToString,
where
T: ToString,
{
self.params.insert(key.to_string(), value.to_string());
self.set_params();

self
}
Expand Down Expand Up @@ -68,26 +67,34 @@ impl Params {
self.add_param(FORMAT, EXPORT)
}

pub fn finish(&self) -> Firebase {
pub fn finish(&mut self) -> Firebase {
self.set_params();
Firebase::new(self.uri.as_str()).unwrap()
}
}


#[cfg(test)]
mod tests {
use crate::params::Params;
use std::collections::HashMap;
use url::Url;
use crate::params::Params;

#[test]
fn check_params() {
let mut params: HashMap<String, String> = HashMap::new();
params.insert("param_1".to_owned(), "value_1".to_owned());
params.insert("param_2".to_owned(), "value_2".to_owned());
let mut param = Params { uri: Url::parse("https://github.com/emreyalvac").unwrap(), params };
let mut params = HashMap::new();
params.insert("param_1", "value_1");
params.insert("param_2", "value_2");

let mut param = Params::new(Url::parse("https://github.com/emreyalvac").unwrap());

for (k, v) in params {
param.add_param(&k, v);
}
param.set_params();

assert_eq!(param.uri.as_str(), "https://github.com/emreyalvac?param_1=value_1&param_2=value_2")
assert_eq!(
param.uri.as_str(),
"https://github.com/emreyalvac?param_1=value_1&param_2=value_2"
)
}
}
}

0 comments on commit 2fbeda7

Please sign in to comment.