34 lines
942 B
Rust
34 lines
942 B
Rust
use loco_rs::testing::prelude::*;
|
|
use serial_test::serial;
|
|
use termi_api::app::App;
|
|
|
|
#[tokio::test]
|
|
#[serial]
|
|
async fn can_get_posts() {
|
|
request::<App, _, _>(|request, ctx| async move {
|
|
seed::<App>(&ctx).await.unwrap();
|
|
|
|
let res = request.get("/api/posts/").await;
|
|
assert_eq!(res.status_code(), 200);
|
|
assert!(res.text().contains("\"slug\":\"welcome-to-termi\""));
|
|
})
|
|
.await;
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[serial]
|
|
async fn can_filter_posts_by_tag() {
|
|
request::<App, _, _>(|request, ctx| async move {
|
|
seed::<App>(&ctx).await.unwrap();
|
|
|
|
let res = request.get("/api/posts/?tag=Rust").await;
|
|
assert_eq!(res.status_code(), 200);
|
|
|
|
let body = res.text();
|
|
assert!(body.contains("\"slug\":\"rust-programming-tips\""));
|
|
assert!(body.contains("\"slug\":\"loco-rs-framework\""));
|
|
assert!(!body.contains("\"slug\":\"terminal-ui-design\""));
|
|
})
|
|
.await;
|
|
}
|