@@ -13,61 +13,70 @@ namespace launchdarkly::events {
13
13
14
14
TEST (EventSerialization, FeatureEvent) {
15
15
auto creation_date = std::chrono::system_clock::from_time_t ({});
16
- auto e = events::client::FeatureEvent{
17
- {creation_date, " key" , 17 , 2 , " value" ,
18
- EvaluationReason (" foo" , std::nullopt, std::nullopt, std::nullopt,
19
- std::nullopt, false , std::nullopt),
20
-
21
- 17 },
16
+ auto event = events::client::FeatureEvent{
17
+ client::FeatureEventBase (client::FeatureEventParams{
18
+ creation_date,
19
+ " key" ,
20
+ ContextBuilder ().kind (" foo" , " bar" ).build (),
21
+ EvaluationResult (
22
+ 1 , std::nullopt, false , false , std::nullopt,
23
+ EvaluationDetailInternal (
24
+ Value (42 ), 2 ,
25
+ Reason (" error" , std::nullopt, std::nullopt, std::nullopt,
26
+ std::nullopt, false , std::nullopt))),
27
+ 3 ,
28
+ }),
22
29
std::map<std::string, std::string>{{" foo" , " bar" }}};
23
30
24
- auto event = boost::json::value_from (e );
31
+ auto event_json = boost::json::value_from (event );
25
32
26
33
auto result = boost::json::parse (
27
- " {\" creationDate\" :0,\" key\" :\" key\" ,\" version\" :17,\" variation\" :2,"
28
- " \" value\" :\" value\" ,\" reason\" :{\" kind\" :\" foo\" },\" default\" :1.7E1,"
29
- " \" kind\" :\" feature\" ,\" contextKeys\" :{\" foo\" :\" bar\" }}" );
34
+ R"( {"creationDate":0,"key":"key","version":1,"variation":2,"value":4.2E1,"default":3E0,"kind":"feature","contextKeys":{"foo":"bar"}})" );
30
35
31
- ASSERT_EQ (result, event );
36
+ ASSERT_EQ (result, event_json );
32
37
}
33
38
34
39
TEST (EventSerialization, DebugEvent) {
35
40
auto creation_date = std::chrono::system_clock::from_time_t ({});
36
41
AttributeReference::SetType attrs;
37
42
ContextFilter filter (false , attrs);
38
- auto e = events::client::DebugEvent{
39
- {creation_date, " key" , 17 , 2 , " value" ,
40
- EvaluationReason (" foo" , std::nullopt, std::nullopt, std::nullopt,
41
- std::nullopt, false , std::nullopt),
42
-
43
- 17 },
44
- filter.filter (ContextBuilder ().kind (" foo" , " bar" ).build ())};
45
-
46
- auto event = boost::json::value_from (e);
43
+ auto context = ContextBuilder ().kind (" foo" , " bar" ).build ();
44
+ auto event = events::client::DebugEvent{
45
+ client::FeatureEventBase (client::FeatureEventParams{
46
+ creation_date,
47
+ " key" ,
48
+ context,
49
+ EvaluationResult (
50
+ 1 , std::nullopt, false , false , std::nullopt,
51
+ EvaluationDetailInternal (
52
+ Value (42 ), 2 ,
53
+ Reason (" error" , std::nullopt, std::nullopt, std::nullopt,
54
+ std::nullopt, false , std::nullopt))),
55
+ 3 ,
56
+ }),
57
+ filter.filter (context)};
58
+
59
+ auto event_json = boost::json::value_from (event);
47
60
48
61
auto result = boost::json::parse (
49
- " {\" creationDate\" :0,\" key\" :\" key\" ,\" version\" :17,\" variation\" :2,"
50
- " \" value\" :\" value\" ,\" reason\" :{\" kind\" :\" foo\" },\" default\" :1.7E1,"
51
- " \" kind\" :\" debug\" ,\" context\" :{\" key\" :\" bar\" ,\" kind\" :\" foo\" }}" );
62
+ R"( {"creationDate":0,"key":"key","version":1,"variation":2,"value":4.2E1,"default":3E0,"kind":"debug","context":{"key":"bar","kind":"foo"}})" );
52
63
53
- ASSERT_EQ (result, event );
64
+ ASSERT_EQ (result, event_json );
54
65
}
55
66
56
67
TEST (EventSerialization, IdentifyEvent) {
57
68
auto creation_date = std::chrono::system_clock::from_time_t ({});
58
69
AttributeReference::SetType attrs;
59
70
ContextFilter filter (false , attrs);
60
- auto e = events::client::IdentifyEvent{
71
+ auto event = events::client::IdentifyEvent{
61
72
creation_date,
62
73
filter.filter (ContextBuilder ().kind (" foo" , " bar" ).build ())};
63
74
64
- auto event = boost::json::value_from (e );
75
+ auto event_json = boost::json::value_from (event );
65
76
66
77
auto result = boost::json::parse (
67
- " {\" kind\" :\" identify\" ,\" creationDate\" :0,\" context\" :{\" key\" :"
68
- " \" bar\" ,\" kind\" :\" foo\" }}" );
69
-
70
- ASSERT_EQ (result, event);
78
+ R"( {"kind":"identify","creationDate":0,"context":{"key":"bar","kind":"foo"}})" );
79
+ ASSERT_EQ (result, event_json);
71
80
}
72
81
73
82
} // namespace launchdarkly::events
0 commit comments