flagsmith_flag_engine/environments/
builders.rs1use super::Environment;
2use super::EnvironmentAPIKey;
3
4pub fn build_environment_struct(value: serde_json::Value) -> Environment {
5 let environment: Environment = serde_json::from_value(value).unwrap();
6 return environment;
7}
8
9pub fn build_environment_api_key_struct(value: serde_json::Value) -> EnvironmentAPIKey {
10 let environment_api_key: EnvironmentAPIKey = serde_json::from_value(value).unwrap();
11 return environment_api_key;
12}
13#[cfg(test)]
14mod tests {
15 use super::*;
16
17 #[test]
18 fn build_environment_api_key_struct_returns_correct_struct() {
19 let key = "ser.test_key".to_string();
21 let api_key_json = serde_json::json!({
22 "key": key,
23 "active": true,
24 "created_at": "2022-03-02T12:31:05.309861+00:00",
25 "client_api_key": "client_key",
26 "id": 1,
27 "name": "api key 1",
28 "expires_at": null
29 });
30 let api_key_struct = build_environment_api_key_struct(api_key_json);
32 assert_eq!(api_key_struct.key, key);
34 }
35}