Skip to content

Commit 58d7119

Browse files
committed
added aditional test case for adding more than one event count in a single update
1 parent 3921688 commit 58d7119

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

sentry/src/routes/routers.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,77 @@ mod analytics_router_test {
12471247
);
12481248
}
12491249

1250+
// Test where we add more than one event count
1251+
// with base date hour
1252+
// event type: CLICK
1253+
{
1254+
let analytics_base_hour = UpdateAnalytics {
1255+
time: base_datehour,
1256+
campaign_id: DUMMY_CAMPAIGN.id,
1257+
ad_unit: DUMMY_IPFS[0],
1258+
ad_slot: DUMMY_IPFS[1],
1259+
ad_slot_type: None,
1260+
advertiser: *ADVERTISER,
1261+
publisher: *PUBLISHER,
1262+
hostname: None,
1263+
country: Some("Bulgaria".to_string()),
1264+
os_name: OperatingSystem::map_os("Windows"),
1265+
chain_id: GANACHE_1337.chain_id,
1266+
event_type: CLICK,
1267+
amount_to_add: UnifiedNum::from_u64(1_000_000),
1268+
count_to_add: 69,
1269+
};
1270+
update_analytics(&app.pool, analytics_base_hour)
1271+
.await
1272+
.expect("Should update analytics");
1273+
1274+
let query = AnalyticsQuery {
1275+
limit: 1000,
1276+
event_type: CLICK,
1277+
metric: Metric::Count,
1278+
segment_by: None,
1279+
time: Time {
1280+
timeframe: Timeframe::Day,
1281+
start: base_datehour - 1,
1282+
end: None,
1283+
},
1284+
campaign_id: None,
1285+
ad_unit: None,
1286+
ad_slot: None,
1287+
ad_slot_type: None,
1288+
advertiser: None,
1289+
publisher: None,
1290+
hostname: None,
1291+
country: None,
1292+
os_name: None,
1293+
chains: vec![GANACHE_1337.chain_id],
1294+
};
1295+
let query = serde_qs::to_string(&query).expect("should parse query");
1296+
let req = Request::builder()
1297+
.uri(format!("http://127.0.0.1/v5/analytics?{}", query))
1298+
.body(Body::empty())
1299+
.expect("Should build Request");
1300+
1301+
let analytics_response = analytics_router(req, &app)
1302+
.await
1303+
.expect("Should get analytics data");
1304+
let json = hyper::body::to_bytes(analytics_response.into_body())
1305+
.await
1306+
.expect("Should get json");
1307+
1308+
let fetched_analytics = serde_json::from_slice::<AnalyticsResponse>(&json)
1309+
.expect("Should get analytics response")
1310+
.analytics;
1311+
1312+
// 1 + 1 (from previous events) + 69 (from update in this test case) = 71
1313+
assert_eq!(
1314+
vec![FetchedMetric::Count(71)],
1315+
fetched_analytics
1316+
.iter()
1317+
.map(|analytics| analytics.value)
1318+
.collect::<Vec<_>>(),
1319+
);
1320+
}
12501321
// Test with timeframe=day and start_date= 2 or more days ago to check if the results vec is split properly
12511322
}
12521323

0 commit comments

Comments
 (0)