mod common;

use randomorg_rpc::TicketType;

#[tokio::test]
async fn tickets_lifecycle_typed() {
    let c = common::client();
    let stubs = c.create_tickets_typed(1, true).await.unwrap();
    assert_eq!(stubs.0.len(), 1);
    let stub = &stubs.0[0];
    let tid = stub.ticket_id.clone();
    assert!(stub.next_ticket_id.is_none());
    assert!(stub.previous_ticket_id.is_none());

    let t = c.get_ticket(&tid).await.unwrap();
    assert_eq!(t.ticket_id, tid);
    assert_eq!(t.show_result, Some(true));
    assert!(t.serial_number.is_none(), "ticket not yet revealed");

    let listed = c.list_tickets(TicketType::Singleton).await.unwrap();
    assert!(
        listed
            .iter()
            .any(|v| v.get("ticketId").and_then(|x| x.as_str()) == Some(&tid)),
        "ticket missing from listTickets"
    );
}
