Skip to content

Commit

Permalink
feat(tests): Add locations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flo-ride committed Oct 30, 2024
1 parent 230340a commit de7ef5e
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions tests/location_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
mod utils;

use axum::http::StatusCode;
use serde_json::json;
use utils::{containers::keycloak::User, create_basic_session, create_realm_session};

use crate::utils::containers::keycloak::{Client, Realm};

#[tokio::test(flavor = "multi_thread")]
async fn location_test_1() {
let realm = Realm {
name: "location_test".to_string(),
clients: vec![Client::default()],
users: vec![
User {
username: "user_1".to_string(),
email: "[email protected]".to_string(),
..Default::default()
},
User {
username: "user_2".to_string(),
email: "[email protected]".to_string(),
..Default::default()
},
User {
username: "user_3".to_string(),
email: "[email protected]".to_string(),
..Default::default()
},
],
};

let (mut server, _ids, _nodes) = create_basic_session(realm.clone()).await;
let cookies = create_realm_session(&mut server, realm.users).await;

// POST /location new location
let response = server
.post("/location")
.json(&json!({
"name": "Salle 401",
"category": "room",
}))
.add_cookie(cookies[0].clone())
.await;
response.assert_status(StatusCode::CREATED);
let new_location_id = response.text();

let response = server.get(&format!("/location/{new_location_id}")).await;
response.assert_status_ok();
response.assert_json_contains(&json!({
"id": new_location_id,
"name": "Salle 401",
"category": "room",
"disabled": false,
}));

let response = server.get("/location").await;
response.assert_status_ok();
response.assert_json_contains(&json!({
"current_page": 0,
"total_page": 1,
"locations": [
{
"id": new_location_id,
"name": "Salle 401",
"category": "room",
"disabled": false,
}
]
}));

let response = server
.put(&format!("/location/{new_location_id}"))
.json(&json!({
"name": "Distributeur 201",
"category": "dispenser"
}))
.add_cookie(cookies[0].clone())
.await;
response.assert_status_ok();

let response = server.get(&format!("/location/{new_location_id}")).await;
response.assert_status_ok();
response.assert_json_contains(&json!({
"id": new_location_id,
"name": "Distributeur 201",
"category": "dispenser",
"disabled": false,
}));

let response = server.get("/location").await;
response.assert_status_ok();
response.assert_json_contains(&json!({
"current_page": 0,
"total_page": 1,
"locations": [
{
"id": new_location_id,
"name": "Distributeur 201",
"category": "dispenser",
"disabled": false,
}
]
}));

let response = server
.delete(&format!("/location/{new_location_id}"))
.add_cookie(cookies[0].clone())
.await;
response.assert_status_ok();

let response = server.get(&format!("/location/{new_location_id}")).await;
response.assert_status_not_found();

let response = server.get("/location").await;
response.assert_status_ok();
response.assert_json(&json!({
"current_page": 0,
"total_page": 1,
"locations": []
}));
}

0 comments on commit de7ef5e

Please sign in to comment.