use loco_rs::testing::prelude::*;
use serial_test::serial;
use termi_api::app::App;

#[tokio::test]
#[serial]
async fn can_get_friend_links() {
    request::<App, _, _>(|request, ctx| async move {
        seed::<App>(&ctx).await.unwrap();

        let res = request.get("/api/friend_links/").await;
        assert_eq!(res.status_code(), 200);
        assert!(res.text().contains("\"site_name\":\"Tech Blog Daily\""));
    })
    .await;
}

#[tokio::test]
#[serial]
async fn can_filter_friend_links_by_status() {
    request::<App, _, _>(|request, ctx| async move {
        seed::<App>(&ctx).await.unwrap();

        let res = request.get("/api/friend_links/?status=approved").await;
        assert_eq!(res.status_code(), 200);

        let body = res.text();
        assert!(body.contains("\"site_name\":\"Tech Blog Daily\""));
        assert!(!body.contains("\"site_name\":\"Code Snippets\""));
    })
    .await;
}
