@@ -126,7 +126,7 @@ impl actix_web::FromRequest for Event {
126
126
}
127
127
}
128
128
129
- /// Extention Trait for [`HttpRequest`] which acts as a wrapper for the function [`request_to_event()`].
129
+ /// Extension Trait for [`HttpRequest`] which acts as a wrapper for the function [`request_to_event()`].
130
130
///
131
131
/// This trait is sealed and cannot be implemented for types outside of this crate.
132
132
#[ async_trait( ?Send ) ]
@@ -160,19 +160,14 @@ mod tests {
160
160
use actix_web:: test;
161
161
162
162
use crate :: { EventBuilder , EventBuilderV10 } ;
163
- use chrono:: Utc ;
164
163
use serde_json:: json;
165
164
166
165
#[ actix_rt:: test]
167
166
async fn test_request ( ) {
168
- let time = Utc :: now ( ) ;
169
167
let expected = EventBuilderV10 :: new ( )
170
168
. id ( "0001" )
171
169
. ty ( "example.test" )
172
170
. source ( "http://localhost/" )
173
- //TODO this is required now because the message deserializer implictly set default values
174
- // As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
175
- . time ( time)
176
171
. extension ( "someint" , "10" )
177
172
. build ( )
178
173
. unwrap ( ) ;
@@ -183,7 +178,6 @@ mod tests {
183
178
. header ( "ce-type" , "example.test" )
184
179
. header ( "ce-source" , "http://localhost/" )
185
180
. header ( "ce-someint" , "10" )
186
- . header ( "ce-time" , time. to_rfc3339 ( ) )
187
181
. to_http_parts ( ) ;
188
182
189
183
let resp = req. to_event ( web:: Payload ( payload) ) . await . unwrap ( ) ;
@@ -192,16 +186,12 @@ mod tests {
192
186
193
187
#[ actix_rt:: test]
194
188
async fn test_request_with_full_data ( ) {
195
- let time = Utc :: now ( ) ;
196
189
let j = json ! ( { "hello" : "world" } ) ;
197
190
198
191
let expected = EventBuilderV10 :: new ( )
199
192
. id ( "0001" )
200
193
. ty ( "example.test" )
201
194
. source ( "http://localhost" )
202
- //TODO this is required now because the message deserializer implictly set default values
203
- // As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
204
- . time ( time)
205
195
. data ( "application/json" , j. to_string ( ) . into_bytes ( ) )
206
196
. extension ( "someint" , "10" )
207
197
. build ( )
@@ -213,12 +203,43 @@ mod tests {
213
203
. header ( "ce-type" , "example.test" )
214
204
. header ( "ce-source" , "http://localhost" )
215
205
. header ( "ce-someint" , "10" )
216
- . header ( "ce-time" , time. to_rfc3339 ( ) )
217
206
. header ( "content-type" , "application/json" )
218
207
. set_json ( & j)
219
208
. to_http_parts ( ) ;
220
209
221
210
let resp = req. to_event ( web:: Payload ( payload) ) . await . unwrap ( ) ;
222
211
assert_eq ! ( expected, resp) ;
223
212
}
213
+
214
+ #[ actix_rt:: test]
215
+ async fn test_structured_request_with_full_data ( ) {
216
+ let j = json ! ( { "hello" : "world" } ) ;
217
+ let payload = json ! ( {
218
+ "specversion" : "1.0" ,
219
+ "id" : "0001" ,
220
+ "type" : "example.test" ,
221
+ "source" : "http://localhost" ,
222
+ "someint" : "10" ,
223
+ "datacontenttype" : "application/json" ,
224
+ "data" : j
225
+ } ) ;
226
+ let bytes = serde_json:: to_string ( & payload) . expect ( "Failed to serialize test data to json" ) ;
227
+
228
+ let expected = EventBuilderV10 :: new ( )
229
+ . id ( "0001" )
230
+ . ty ( "example.test" )
231
+ . source ( "http://localhost" )
232
+ . data ( "application/json" , j)
233
+ . extension ( "someint" , "10" )
234
+ . build ( )
235
+ . unwrap ( ) ;
236
+
237
+ let ( req, payload) = test:: TestRequest :: post ( )
238
+ . header ( "content-type" , "application/cloudevents+json" )
239
+ . set_payload ( bytes)
240
+ . to_http_parts ( ) ;
241
+
242
+ let resp = req. to_event ( web:: Payload ( payload) ) . await . unwrap ( ) ;
243
+ assert_eq ! ( expected, resp) ;
244
+ }
224
245
}
0 commit comments