Skip to content

Commit 4bdeee0

Browse files
Server: add 'event_types' query param to 'list-attempted-messages' (#993)
The `v1.message-attempt.list-by-endpoint` API takes in a `event_types` parameter that filters the returned `MessageAttemptOut`s by event type. This makes the similar `v1.message-attempt.list-by-endpoint` endpoint have an `event_types` parameter that does the same to the returned `EndpointMessageOut`s.
1 parent c9b19f3 commit 4bdeee0

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

server/openapi.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,6 +4152,22 @@
41524152
"type": "string"
41534153
},
41544154
"style": "simple"
4155+
},
4156+
{
4157+
"in": "query",
4158+
"name": "event_types",
4159+
"schema": {
4160+
"items": {
4161+
"example": "user.signup",
4162+
"maxLength": 256,
4163+
"pattern": "^[a-zA-Z0-9\\-_.]+$",
4164+
"type": "string"
4165+
},
4166+
"nullable": true,
4167+
"type": "array",
4168+
"uniqueItems": true
4169+
},
4170+
"style": "form"
41554171
}
41564172
],
41574173
"responses": {

server/svix-server/src/v1/endpoints/attempt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ async fn list_attempted_messages(
177177
}): ValidatedQuery<ListAttemptedMessagesQueryParams>,
178178
Path(ApplicationEndpointPath { endpoint_id, .. }): Path<ApplicationEndpointPath>,
179179
permissions::Application { app }: permissions::Application,
180+
EventTypesQueryParams(event_types): EventTypesQueryParams,
180181
) -> Result<Json<ListResponse<EndpointMessageOut>>> {
181182
let PaginationLimit(limit) = pagination.limit;
182183
let endp = ctx!(
@@ -198,6 +199,10 @@ async fn list_attempted_messages(
198199
dests_and_msgs = dests_and_msgs.filter(messagedestination::Column::Status.eq(status));
199200
}
200201

202+
if let Some(EventTypeNameSet(event_types)) = event_types {
203+
dests_and_msgs = dests_and_msgs.filter(message::Column::EventType.is_in(event_types));
204+
}
205+
201206
async fn _get_msg_dest_id(
202207
db: &DatabaseConnection,
203208
msg_id: MessageId,

server/svix-server/tests/e2e_attempt.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ async fn test_list_attempted_messages() {
178178
.unwrap();
179179
assert_eq!(list_filtered.data.len(), 1);
180180
assert!(list_filtered.data[0].msg == msg_3);
181+
182+
// Test 'event_types' query parameter
183+
184+
let list_balloon_popped: ListResponse<EndpointMessageOut> = client
185+
.get(
186+
&format!("api/v1/app/{app_id}/endpoint/{endp_id_1}/msg/?event_types=balloon.popped",),
187+
StatusCode::OK,
188+
)
189+
.await
190+
.unwrap();
191+
192+
assert_eq!(list_balloon_popped.data.len(), 1);
193+
assert!(list_balloon_popped.data[0].msg == msg_3);
194+
195+
let list_event_type: ListResponse<EndpointMessageOut> = client
196+
.get(
197+
&format!("api/v1/app/{app_id}/endpoint/{endp_id_1}/msg/?event_types=event.type",),
198+
StatusCode::OK,
199+
)
200+
.await
201+
.unwrap();
202+
assert_eq!(list_event_type.data.len(), 2);
203+
assert!(list_event_type.data.iter().any(|x| x.msg == msg_1));
204+
assert!(list_event_type.data.iter().any(|x| x.msg == msg_2));
205+
206+
let list_both_event_types: ListResponse<EndpointMessageOut> = client
207+
.get(
208+
&format!("api/v1/app/{app_id}/endpoint/{endp_id_1}/msg/?event_types=event.type,balloon.popped",),
209+
StatusCode::OK,
210+
)
211+
.await
212+
.unwrap();
213+
214+
assert_eq!(list_both_event_types.data.len(), 3);
215+
assert!(list_both_event_types.data.iter().any(|x| x.msg == msg_1));
216+
assert!(list_both_event_types.data.iter().any(|x| x.msg == msg_2));
217+
assert!(list_both_event_types.data.iter().any(|x| x.msg == msg_3));
181218
}
182219

183220
#[tokio::test]

0 commit comments

Comments
 (0)