@@ -13,8 +13,10 @@ async fn it_captures_one_event() -> Result<()> {
13
13
setup_tracing ( ) ;
14
14
let token = random_string ( "token" , 16 ) ;
15
15
let distinct_id = random_string ( "id" , 16 ) ;
16
- let topic = EphemeralTopic :: new ( ) . await ;
17
- let server = ServerHandle :: for_topic ( & topic) . await ;
16
+
17
+ let main_topic = EphemeralTopic :: new ( ) . await ;
18
+ let histo_topic = EphemeralTopic :: new ( ) . await ;
19
+ let server = ServerHandle :: for_topics ( & main_topic, & histo_topic) . await ;
18
20
19
21
let event = json ! ( {
20
22
"token" : token,
@@ -24,7 +26,7 @@ async fn it_captures_one_event() -> Result<()> {
24
26
let res = server. capture_events ( event. to_string ( ) ) . await ;
25
27
assert_eq ! ( StatusCode :: OK , res. status( ) ) ;
26
28
27
- let event = topic . next_event ( ) ?;
29
+ let event = main_topic . next_event ( ) ?;
28
30
assert_json_include ! (
29
31
actual: event,
30
32
expected: json!( {
@@ -37,14 +39,15 @@ async fn it_captures_one_event() -> Result<()> {
37
39
}
38
40
39
41
#[ tokio:: test]
40
- async fn it_captures_a_batch ( ) -> Result < ( ) > {
42
+ async fn it_captures_a_posthogjs_array ( ) -> Result < ( ) > {
41
43
setup_tracing ( ) ;
42
44
let token = random_string ( "token" , 16 ) ;
43
45
let distinct_id1 = random_string ( "id" , 16 ) ;
44
46
let distinct_id2 = random_string ( "id" , 16 ) ;
45
47
46
- let topic = EphemeralTopic :: new ( ) . await ;
47
- let server = ServerHandle :: for_topic ( & topic) . await ;
48
+ let main_topic = EphemeralTopic :: new ( ) . await ;
49
+ let histo_topic = EphemeralTopic :: new ( ) . await ;
50
+ let server = ServerHandle :: for_topics ( & main_topic, & histo_topic) . await ;
48
51
49
52
let event = json ! ( [ {
50
53
"token" : token,
@@ -59,14 +62,98 @@ async fn it_captures_a_batch() -> Result<()> {
59
62
assert_eq ! ( StatusCode :: OK , res. status( ) ) ;
60
63
61
64
assert_json_include ! (
62
- actual: topic . next_event( ) ?,
65
+ actual: main_topic . next_event( ) ?,
63
66
expected: json!( {
64
67
"token" : token,
65
68
"distinct_id" : distinct_id1
66
69
} )
67
70
) ;
68
71
assert_json_include ! (
69
- actual: topic. next_event( ) ?,
72
+ actual: main_topic. next_event( ) ?,
73
+ expected: json!( {
74
+ "token" : token,
75
+ "distinct_id" : distinct_id2
76
+ } )
77
+ ) ;
78
+
79
+ Ok ( ( ) )
80
+ }
81
+
82
+ #[ tokio:: test]
83
+ async fn it_captures_a_batch ( ) -> Result < ( ) > {
84
+ setup_tracing ( ) ;
85
+ let token = random_string ( "token" , 16 ) ;
86
+ let distinct_id1 = random_string ( "id" , 16 ) ;
87
+ let distinct_id2 = random_string ( "id" , 16 ) ;
88
+
89
+ let main_topic = EphemeralTopic :: new ( ) . await ;
90
+ let histo_topic = EphemeralTopic :: new ( ) . await ;
91
+ let server = ServerHandle :: for_topics ( & main_topic, & histo_topic) . await ;
92
+
93
+ let event = json ! ( {
94
+ "token" : token,
95
+ "batch" : [ {
96
+ "event" : "event1" ,
97
+ "distinct_id" : distinct_id1
98
+ } , {
99
+ "event" : "event2" ,
100
+ "distinct_id" : distinct_id2
101
+ } ]
102
+ } ) ;
103
+ let res = server. capture_events ( event. to_string ( ) ) . await ;
104
+ assert_eq ! ( StatusCode :: OK , res. status( ) ) ;
105
+
106
+ assert_json_include ! (
107
+ actual: main_topic. next_event( ) ?,
108
+ expected: json!( {
109
+ "token" : token,
110
+ "distinct_id" : distinct_id1
111
+ } )
112
+ ) ;
113
+ assert_json_include ! (
114
+ actual: main_topic. next_event( ) ?,
115
+ expected: json!( {
116
+ "token" : token,
117
+ "distinct_id" : distinct_id2
118
+ } )
119
+ ) ;
120
+
121
+ Ok ( ( ) )
122
+ }
123
+ #[ tokio:: test]
124
+ async fn it_captures_a_historical_batch ( ) -> Result < ( ) > {
125
+ setup_tracing ( ) ;
126
+ let token = random_string ( "token" , 16 ) ;
127
+ let distinct_id1 = random_string ( "id" , 16 ) ;
128
+ let distinct_id2 = random_string ( "id" , 16 ) ;
129
+
130
+ let main_topic = EphemeralTopic :: new ( ) . await ;
131
+ let histo_topic = EphemeralTopic :: new ( ) . await ;
132
+ let server = ServerHandle :: for_topics ( & main_topic, & histo_topic) . await ;
133
+
134
+ let event = json ! ( {
135
+ "token" : token,
136
+ "historical_migration" : true ,
137
+ "batch" : [ {
138
+ "event" : "event1" ,
139
+ "distinct_id" : distinct_id1
140
+ } , {
141
+ "event" : "event2" ,
142
+ "distinct_id" : distinct_id2
143
+ } ]
144
+ } ) ;
145
+ let res = server. capture_events ( event. to_string ( ) ) . await ;
146
+ assert_eq ! ( StatusCode :: OK , res. status( ) ) ;
147
+
148
+ assert_json_include ! (
149
+ actual: histo_topic. next_event( ) ?,
150
+ expected: json!( {
151
+ "token" : token,
152
+ "distinct_id" : distinct_id1
153
+ } )
154
+ ) ;
155
+ assert_json_include ! (
156
+ actual: histo_topic. next_event( ) ?,
70
157
expected: json!( {
71
158
"token" : token,
72
159
"distinct_id" : distinct_id2
0 commit comments