Add test for web send event to draft v2
@@ -390,4 +390,63 @@ mod test {
assert_eq!(401, resp.status());
}
+
+ #[actix_rt::test]
+ async fn should_send_event_to_draft_v2() {
+ // Arrange
+ let srv = test::init_service(App::new().service(build_event_v2_endpoints(ApiDataV2 {
+ auth: test_auth_service_v2(),
+ api: EventApiV2::new(TestApiHandler {}, Arc::new(TestConfigManager {})),
+ })))
+ .await;
+
+ let metadata = HashMap::from([(
+ "something".to_owned(),
+ serde_json::Value::String(format!("{}", rand::random::<usize>())),
+ )]);
+
+ let send_event_request = SendEventRequestDto {
+ event: EventDto {
+ event_type: "my_test_event_for_draft".to_owned(),
+ payload: HashMap::new(),
+ metadata: serde_json::to_value(&metadata).unwrap(),
+ created_ms: 0,
+ trace_id: Some("my_trace_id".to_owned()),
+ },
+ process_type: ProcessType::SkipActions,
+ };
+
+ // Act
+ let request = test::TestRequest::post()
+ .uri("/event/drafts/auth1/a123")
+ .insert_header((header::CONTENT_TYPE, "application/json"))
+ .insert_header((
+ header::AUTHORIZATION,
+ AuthServiceV2::auth_to_token_header(&AuthHeaderV2 {
+ user: "OWNER".to_string(),
+ auths: HashMap::from([(
+ "auth1".to_owned(),
+ Authorization {
+ path: vec!["root".to_owned()],
+ roles: vec!["view".to_owned()],
+ },
+ )]),
+ preferences: None,
+ })
+ .unwrap(),
+ ))
+ .set_payload(serde_json::to_string(&send_event_request).unwrap())
+ .to_request();
+
+ // Assert
+ let resp = test::call_service(&srv, request).await;
+ assert_eq!(200, resp.status());
+
+ let dto: tornado_engine_api_dto::event::ProcessedEventDto =
+ test::read_body_json(resp).await;
+
+ assert_eq!("my_test_event_for_draft", dto.event.event_type);
+ assert_eq!(Some("my_trace_id".to_owned()), dto.event.trace_id);
+ assert_eq!(serde_json::to_value(&metadata).unwrap(), dto.event.metadata);
+ }
}
