Skip to content

Commit cbe5c78

Browse files
committed
sentry - examples - /campaign/list query
1 parent 799351f commit cbe5c78

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use chrono::{TimeZone, Utc};
2+
use primitives::{
3+
sentry::campaign_list::{CampaignListQuery, ValidatorParam},
4+
test_util::{ADVERTISER, FOLLOWER, LEADER},
5+
};
6+
7+
fn main() {
8+
// Empty query - default values only
9+
{
10+
let empty_query = "";
11+
let query: CampaignListQuery = serde_qs::from_str(empty_query).unwrap();
12+
13+
assert_eq!(0, query.page);
14+
assert!(
15+
Utc::now() >= query.active_to_ge,
16+
"By default `activeTo` is set to `Utc::now()`"
17+
);
18+
assert!(query.creator.is_none());
19+
assert!(query.validator.is_none());
20+
}
21+
22+
// Query with `activeTo` only
23+
{
24+
let active_to_query = "activeTo=1624192200";
25+
let active_to = CampaignListQuery {
26+
page: 0,
27+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
28+
creator: None,
29+
validator: None,
30+
};
31+
32+
assert_eq!(active_to, serde_qs::from_str(active_to_query).unwrap());
33+
}
34+
35+
// Query with `page` & `activeTo`
36+
{
37+
let with_page_query = "page=14&activeTo=1624192200";
38+
let with_page = CampaignListQuery {
39+
page: 14,
40+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
41+
creator: None,
42+
validator: None,
43+
};
44+
45+
assert_eq!(with_page, serde_qs::from_str(with_page_query).unwrap());
46+
}
47+
48+
// Query with `creator`
49+
{
50+
let with_creator_query =
51+
"activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0";
52+
53+
let with_creator = CampaignListQuery {
54+
page: 0,
55+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
56+
creator: Some(*ADVERTISER),
57+
validator: None,
58+
};
59+
60+
assert_eq!(
61+
with_creator,
62+
serde_qs::from_str(with_creator_query).unwrap()
63+
);
64+
}
65+
66+
// Query with `validator`
67+
{
68+
let with_creator_validator_query = "page=0&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&validator=0xf3f583AEC5f7C030722Fe992A5688557e1B86ef7";
69+
let with_creator_validator = CampaignListQuery {
70+
page: 0,
71+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
72+
creator: Some(*ADVERTISER),
73+
validator: Some(ValidatorParam::Validator((*FOLLOWER).into())),
74+
};
75+
76+
assert_eq!(
77+
with_creator_validator,
78+
serde_qs::from_str(with_creator_validator_query).unwrap()
79+
);
80+
}
81+
82+
// Query with `leader`
83+
{
84+
let with_leader_query = "page=0&activeTo=1624192200&creator=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0&leader=0x80690751969B234697e9059e04ed72195c3507fa";
85+
86+
let with_leader = CampaignListQuery {
87+
page: 0,
88+
active_to_ge: Utc.ymd(2021, 6, 20).and_hms(12, 30, 0),
89+
creator: Some(*ADVERTISER),
90+
validator: Some(ValidatorParam::Leader((*LEADER).into())),
91+
};
92+
93+
assert_eq!(with_leader, serde_qs::from_str(with_leader_query).unwrap());
94+
}
95+
}

0 commit comments

Comments
 (0)