-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add request context management and tests
- Introduced `create_request_context` and updated `get_request_context` in `mysession.rs` for managing request context data. - Added tests for setting and getting request context data in `mysession.rs`. - Updated `test.yaml` and `teste2e.yaml` to include request context configuration. - Minor refactoring and cleanup in `cookie.rs` and other test files.
- Loading branch information
Showing
10 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod auth; | ||
mod cache; | ||
mod mylayer; | ||
mod mysession; | ||
mod notes; | ||
mod ping; | ||
mod prepare_data; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use blo::app::App; | ||
use loco_rs::testing; | ||
use serial_test::serial; | ||
|
||
macro_rules! configure_insta { | ||
($($expr:expr),*) => { | ||
let mut settings = insta::Settings::clone_current(); | ||
settings.set_prepend_module_to_snapshot(false); | ||
settings.set_snapshot_suffix("cache"); | ||
let _guard = settings.bind_to_scope(); | ||
}; | ||
} | ||
|
||
#[tokio::test] | ||
#[serial] | ||
async fn set_request_context_data() { | ||
configure_insta!(); | ||
testing::request::<App, _, _>(|request, _ctx| async move { | ||
let response = request.post("/mysession/request_context").await; | ||
|
||
// Get Cookie from response header | ||
let headers = response.headers(); | ||
let cookie = headers.get("set-cookie"); | ||
assert_eq!(response.status_code(), 200); | ||
assert_eq!(response.text(), "turing"); | ||
assert!(cookie.is_some()); | ||
}) | ||
.await; | ||
} | ||
#[tokio::test] | ||
#[serial] | ||
async fn get_request_context_without_setting_data() { | ||
configure_insta!(); | ||
testing::request::<App, _, _>(|request, _ctx| async move { | ||
let response = request.get("/mysession/request_context").await; | ||
// Get response body | ||
assert_eq!(response.status_code(), 200); | ||
assert_eq!(response.text(), "") | ||
}) | ||
.await; | ||
} | ||
|
||
#[tokio::test] | ||
#[serial] | ||
async fn get_request_context_with_setting_data() { | ||
configure_insta!(); | ||
testing::request::<App, _, _>(|request, _ctx| async move { | ||
let response = request.post("/mysession/request_context").await; | ||
// Get Cookie from response header | ||
let headers = response.headers(); | ||
let cookie_value = headers.get("set-cookie"); | ||
assert_eq!(response.status_code(), 200); | ||
assert_eq!(response.text(), "turing"); | ||
assert!(cookie_value.is_some()); | ||
let data = response.text(); | ||
|
||
let response = request | ||
.get("/mysession/request_context") | ||
.add_header("cookie".parse().unwrap(), cookie_value.unwrap().clone()) | ||
.await; | ||
// Get response body | ||
assert_eq!(response.status_code(), 200); | ||
assert_eq!(response.text(), data); | ||
}) | ||
.await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters