File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,13 @@ impl Related<super::message::Entity> for Entity {
35
35
impl ActiveModelBehavior for ActiveModel { }
36
36
37
37
impl ActiveModel {
38
- pub fn new ( msg_id : MessageId , payload : Vec < u8 > ) -> Self {
38
+ pub fn new ( msg_id : MessageId , payload : Vec < u8 > , expiration : DateTimeWithTimeZone ) -> Self {
39
39
let timestamp = Utc :: now ( ) ;
40
40
Self {
41
41
id : Set ( msg_id) ,
42
42
created_at : Set ( timestamp. into ( ) ) ,
43
43
payload : Set ( payload) ,
44
- .. ActiveModelTrait :: default ( )
44
+ expiration : Set ( expiration ) ,
45
45
}
46
46
}
47
47
}
Original file line number Diff line number Diff line change @@ -382,7 +382,8 @@ pub(crate) async fn create_message_inner(
382
382
. transaction ( |txn| {
383
383
async move {
384
384
let msg = msg. insert ( txn) . await . map_err ( http_error_on_conflict) ?;
385
- let msg_content = messagecontent:: ActiveModel :: new ( msg. id . clone ( ) , payload) ;
385
+ let msg_content =
386
+ messagecontent:: ActiveModel :: new ( msg. id . clone ( ) , payload, msg. expiration ) ;
386
387
let msg_content = msg_content. insert ( txn) . await ?;
387
388
Ok ( ( msg, msg_content) )
388
389
}
Original file line number Diff line number Diff line change @@ -423,6 +423,45 @@ async fn test_payload_retention_period() {
423
423
assert ! ( content. is_none( ) ) ;
424
424
}
425
425
426
+ #[ tokio:: test]
427
+ async fn test_payload_retention_period_messagecontent ( ) {
428
+ let ( client, _jh) = start_svix_server ( ) . await ;
429
+ dotenvy:: dotenv ( ) . ok ( ) ;
430
+ let cfg = svix_server:: cfg:: load ( ) . expect ( "Error loading configuration" ) ;
431
+ let pool = svix_server:: db:: init_db ( & cfg) . await ;
432
+
433
+ let app_id = create_test_app ( & client, "test-content-expiration-period" )
434
+ . await
435
+ . unwrap ( )
436
+ . id ;
437
+
438
+ let custom_retention_period = 5 ;
439
+ let msg: MessageOut = client
440
+ . post (
441
+ & format ! ( "api/v1/app/{app_id}/msg/" ) ,
442
+ json ! ( {
443
+ "eventType" : "test.event" ,
444
+ "payload" : { "test" : "value" } ,
445
+ "payloadRetentionPeriod" : custom_retention_period
446
+ } ) ,
447
+ StatusCode :: ACCEPTED ,
448
+ )
449
+ . await
450
+ . unwrap ( ) ;
451
+ let msg_id = msg. id . clone ( ) ;
452
+
453
+ let content: messagecontent:: Model = messagecontent:: Entity :: find_by_id ( msg_id. clone ( ) )
454
+ . one ( & pool)
455
+ . await
456
+ . unwrap ( )
457
+ . unwrap ( ) ;
458
+
459
+ let expected = Utc :: now ( ) + Duration :: days ( custom_retention_period) + Duration :: hours ( 1 ) ;
460
+ let actual: chrono:: DateTime < Utc > = content. expiration . into ( ) ;
461
+
462
+ assert ! ( actual < expected) ;
463
+ }
464
+
426
465
#[ tokio:: test]
427
466
async fn test_expunge_message_payload ( ) {
428
467
let ( client, _jh) = start_svix_server ( ) . await ;
You can’t perform that action at this time.
0 commit comments