add fixture-backed admin and ios scaffold
This commit is contained in:
@@ -2,6 +2,7 @@ use axum::{body::{to_bytes, Body}, http::{Request, StatusCode}};
|
||||
use chrono::Utc;
|
||||
use hermes_backend::{app_state::AppState, build_router, config::AppConfig};
|
||||
use serde_json as json;
|
||||
use uuid::Uuid;
|
||||
use tower::ServiceExt;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -410,6 +411,223 @@ async fn analytics_batch_is_recorded() {
|
||||
assert_eq!(attribute_count, 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn admin_endpoints_publish_round_data() {
|
||||
let app = build_router(AppState::new(AppConfig::default(), None, None));
|
||||
|
||||
let event_id = Uuid::new_v4();
|
||||
let market_id = Uuid::new_v4();
|
||||
let home_outcome_id = Uuid::new_v4();
|
||||
let away_outcome_id = Uuid::new_v4();
|
||||
let odds_version_id = Uuid::new_v4();
|
||||
|
||||
let event_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/v1/admin/events")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(
|
||||
json::json!({
|
||||
"event": {
|
||||
"id": event_id,
|
||||
"sport_type": "football",
|
||||
"source_ref": "admin-event-001",
|
||||
"title_en": "Admin created event",
|
||||
"title_sv": "Adminskapad händelse",
|
||||
"status": "scheduled",
|
||||
"preview_start_ms": 0,
|
||||
"preview_end_ms": 1000,
|
||||
"reveal_start_ms": 2000,
|
||||
"reveal_end_ms": 3000,
|
||||
"lock_at": "2099-01-01T01:10:00Z",
|
||||
"settle_at": "2099-01-01T01:25:00Z"
|
||||
},
|
||||
"media": [
|
||||
{
|
||||
"id": Uuid::new_v4(),
|
||||
"event_id": event_id,
|
||||
"media_type": "hls_main",
|
||||
"hls_master_url": "https://cdn.example.com/admin/master.m3u8",
|
||||
"poster_url": "https://cdn.example.com/admin/poster.jpg",
|
||||
"duration_ms": 3000,
|
||||
"preview_start_ms": 0,
|
||||
"preview_end_ms": 1000,
|
||||
"reveal_start_ms": 2000,
|
||||
"reveal_end_ms": 3000
|
||||
}
|
||||
],
|
||||
"markets": []
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(event_response.status(), StatusCode::CREATED);
|
||||
|
||||
let market_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/v1/admin/markets")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(
|
||||
json::json!({
|
||||
"id": market_id,
|
||||
"event_id": event_id,
|
||||
"question_key": "market.admin.winner",
|
||||
"market_type": "winner",
|
||||
"status": "open",
|
||||
"lock_at": "2099-01-01T01:10:00Z",
|
||||
"settlement_rule_key": "settle_on_match_winner",
|
||||
"outcomes": [
|
||||
{
|
||||
"id": home_outcome_id,
|
||||
"market_id": market_id,
|
||||
"outcome_code": "home",
|
||||
"label_key": "outcome.home",
|
||||
"sort_order": 1
|
||||
},
|
||||
{
|
||||
"id": away_outcome_id,
|
||||
"market_id": market_id,
|
||||
"outcome_code": "away",
|
||||
"label_key": "outcome.away",
|
||||
"sort_order": 2
|
||||
}
|
||||
]
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(market_response.status(), StatusCode::CREATED);
|
||||
|
||||
let odds_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/v1/admin/odds")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(
|
||||
json::json!({
|
||||
"id": odds_version_id,
|
||||
"market_id": market_id,
|
||||
"version_no": 1,
|
||||
"created_at": "2099-01-01T01:00:00Z",
|
||||
"is_current": true,
|
||||
"odds": [
|
||||
{
|
||||
"id": Uuid::new_v4(),
|
||||
"odds_version_id": odds_version_id,
|
||||
"outcome_id": home_outcome_id,
|
||||
"decimal_odds": 1.9,
|
||||
"fractional_num": 9,
|
||||
"fractional_den": 10
|
||||
},
|
||||
{
|
||||
"id": Uuid::new_v4(),
|
||||
"odds_version_id": odds_version_id,
|
||||
"outcome_id": away_outcome_id,
|
||||
"decimal_odds": 2.1,
|
||||
"fractional_num": 11,
|
||||
"fractional_den": 10
|
||||
}
|
||||
]
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(odds_response.status(), StatusCode::CREATED);
|
||||
|
||||
let settlement_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/v1/admin/settlements")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(
|
||||
json::json!({
|
||||
"id": Uuid::new_v4(),
|
||||
"market_id": market_id,
|
||||
"settled_at": "2099-01-01T01:25:00Z",
|
||||
"winning_outcome_id": home_outcome_id
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(settlement_response.status(), StatusCode::CREATED);
|
||||
|
||||
let manifest_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(format!("/api/v1/events/{event_id}/manifest"))
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(manifest_response.status(), StatusCode::OK);
|
||||
|
||||
let manifest_body = to_bytes(manifest_response.into_body(), usize::MAX).await.unwrap();
|
||||
let manifest_json: json::Value = json::from_slice(&manifest_body).unwrap();
|
||||
assert_eq!(manifest_json["markets"].as_array().unwrap().len(), 1);
|
||||
|
||||
let odds_response = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(format!("/api/v1/markets/{market_id}/odds/current"))
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(odds_response.status(), StatusCode::OK);
|
||||
|
||||
let odds_body = to_bytes(odds_response.into_body(), usize::MAX).await.unwrap();
|
||||
let odds_json: json::Value = json::from_slice(&odds_body).unwrap();
|
||||
assert_eq!(odds_json["id"], odds_version_id.to_string());
|
||||
|
||||
let result_response = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(format!("/api/v1/events/{event_id}/result"))
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result_response.status(), StatusCode::OK);
|
||||
|
||||
let result_body = to_bytes(result_response.into_body(), usize::MAX).await.unwrap();
|
||||
let result_json: json::Value = json::from_slice(&result_body).unwrap();
|
||||
assert_eq!(result_json["market_id"], market_id.to_string());
|
||||
assert_eq!(result_json["winning_outcome_id"], home_outcome_id.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn event_markets_and_current_odds_work() {
|
||||
let app = build_router(AppState::new(AppConfig::default(), None, None));
|
||||
|
||||
Reference in New Issue
Block a user