Skip to content

Commit 5e718fe

Browse files
committed
moved test to DB function
1 parent 3cc973f commit 5e718fe

File tree

2 files changed

+20
-73
lines changed

2 files changed

+20
-73
lines changed

sentry/src/db/analytics.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,32 @@ mod test {
229229
assert_eq!(UnifiedNum::from_u64(1_000_000), analytics.payout_amount);
230230
assert_eq!(1, analytics.payout_count);
231231

232-
let analytics_updated = update_analytics(&database.clone(), update.clone())
232+
let new_update = UpdateAnalytics {
233+
time: DateHour::from_ymdh(2021, 2, 1, 1),
234+
campaign_id: DUMMY_CAMPAIGN.id,
235+
ad_unit: ad_unit.ipfs,
236+
ad_slot: ad_slot_ipfs,
237+
ad_slot_type: Some(ad_unit.ad_type.clone()),
238+
advertiser: *CREATOR,
239+
publisher: *PUBLISHER,
240+
hostname: Some("localhost".to_string()),
241+
country: Some("Bulgaria".to_string()),
242+
os_name: OperatingSystem::Linux,
243+
chain_id: ChainId::new(1),
244+
event_type: IMPRESSION,
245+
amount_to_add: UnifiedNum::from_u64(1_000_000),
246+
count_to_add: 69,
247+
};
248+
249+
let analytics_updated = update_analytics(&database.clone(), new_update.clone())
233250
.await
234251
.expect("Should update");
252+
235253
assert_eq!(
236254
analytics_updated.payout_amount,
237255
UnifiedNum::from_u64(2_000_000)
238256
);
239-
assert_eq!(analytics_updated.payout_count, 2);
257+
assert_eq!(analytics_updated.payout_count, 70);
240258
}
241259

242260
// On empty fields marked as `NOT NULL` it should successfully insert a new analytics

sentry/src/routes/routers.rs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,77 +1247,6 @@ 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 (events from previous updates) + 69 (events 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-
}
13211250
// Test with timeframe=day and start_date= 2 or more days ago to check if the results vec is split properly
13221251
}
13231252

0 commit comments

Comments
 (0)