Skip to content

Commit

Permalink
aw-server: Test key_value of different types
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-bjareholt committed Oct 29, 2020
1 parent 6ecb206 commit 70968e4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions aw-server/tests/api.rs
Expand Up @@ -564,6 +564,48 @@ mod api_tests {
);
}

#[test]
fn test_getting_setting_multiple_types() {
let server = setup_testserver();
let client = rocket::local::Client::new(server).expect("valid instance");

let timestamp = Utc::now();

// Test array
let response_status = set_setting_request(&client, "test_key_array", json!("[1,2,3]"));
assert_eq!(response_status, rocket::http::Status::Created);

let mut res = client.get("/api/0/settings/test_key_array").dispatch();
assert_eq!(res.status(), rocket::http::Status::Ok);
let deserialized: KeyValue = serde_json::from_str(&res.body_string().unwrap()).unwrap();
_equal_and_timestamp_in_range(
timestamp,
deserialized,
KeyValue::new("settings.test_key_array", "[1,2,3]", Utc::now()),
);

// Test dict
let response_status = set_setting_request(
&client,
"test_key_dict",
json!("{key: 'value', another_key: 'another value'}"),
);
assert_eq!(response_status, rocket::http::Status::Created);

let mut res = client.get("/api/0/settings/test_key_dict").dispatch();
assert_eq!(res.status(), rocket::http::Status::Ok);
let deserialized: KeyValue = serde_json::from_str(&res.body_string().unwrap()).unwrap();
_equal_and_timestamp_in_range(
timestamp,
deserialized,
KeyValue::new(
"settings.test_key_dict",
"{key: 'value', another_key: 'another value'}",
Utc::now(),
),
);
}

#[test]
fn test_updating_setting() {
let server = setup_testserver();
Expand Down

0 comments on commit 70968e4

Please sign in to comment.