1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use std::sync::Arc;
use httptest::{matchers::request, responders::json_encoded, Expectation, Server};
use serde_json::json;
use statsig_rdp::{models::StatsigOptions, Client};
pub fn expect_fetch_config_specs(server: &Server) {
server.expect(
Expectation::matching(request::method_path("POST", "/download_config_specs"))
.times(..)
.respond_with(json_encoded(json!({
"dynamic_configs": [
{
"name": "test_dynamic_config",
"type": "dynamic_config",
"salt": "salt",
"enabled": true,
"defaultValue": {
"value": "DEFAULT"
},
"rules": [
{
"name": "test_reject_email_name",
"groupName": "test_reject_email",
"passPercentage": 0,
"conditions": [
{
"type": "user_field",
"targetValue": [
"test@example.com"
],
"operator": "any",
"field": "email",
"additionalValues": {},
"isDeviceBased": false,
"idType": "userID"
}
],
"returnValue": {
"value": "EMAIL"
},
"id": "id_reject_email",
"salt": "salt_email",
"isDeviceBased": false,
"idType": "userID"
},
{
"name": "test_1239_name",
"groupName": "test_1239",
"passPercentage": 100,
"conditions": [
{
"type": "user_field",
"targetValue": [
"1239"
],
"operator": "any",
"field": "userID",
"additionalValues": {},
"isDeviceBased": false,
"idType": "userID"
},
{
"type": "user_field",
"targetValue": [
"secretid"
],
"operator": "any",
"field": "secondaryId",
"additionalValues": {
"custom_field": "secondaryId"
},
"isDeviceBased": false,
"idType": "userID"
}
],
"returnValue": {
"value": "1239"
},
"id": "id_1239_name",
"salt": "salt_1239",
"isDeviceBased": false,
"idType": "userID"
},
],
"isDeviceBased": false,
"idType": "userID",
"entity": "dynamic_config"
}
],
"feature_gates": [
{
"name": "test_gate",
"type": "feature_gate",
"salt": "salt",
"enabled": true,
"defaultValue": false,
"idType": "userID",
"rules": [{
"name": "public",
"id": "public1",
"salt": "salt_rule",
"passPercentage": 100,
"idType": "userID",
"returnValue": true,
"conditions": [{
"type": "public",
"idType": "userid",
}],
}],
}
],
"has_updates": true,
"time": 0,
}))),
);
}
pub fn expect_log_emission(server: &Server) {
server.expect(
Expectation::matching(request::method_path("POST", "/log_event"))
.times(..)
.respond_with(json_encoded(json!({}))),
);
}
#[derive(Debug, serde::Deserialize)]
pub struct ConfigValue {
pub value: String,
}
pub async fn create_client() -> Arc<Client> {
let http_server = Server::run();
expect_fetch_config_specs(&http_server);
expect_log_emission(&http_server);
Client::new(
"api_key".to_string(),
StatsigOptions {
api_url: Some(format!("http://{}", http_server.addr())),
events_url: Some(format!("http://{}", http_server.addr())),
disable_cache: false,
config_sync_interval: None,
},
)
.await
.expect("should be able to create statsig client")
}