forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: [torrust#107] E2E tests for API entrypoint and about routes
- Loading branch information
1 parent
abb4e91
commit 5678e4d
Showing
9 changed files
with
98 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::e2e::response::Response; | ||
|
||
pub fn assert_response_title(response: &Response, title: &str) { | ||
let title_element = format!("<title>{title}</title>"); | ||
|
||
assert!( | ||
response.body.contains(&title), | ||
":\n response does not contain the title element: `\"{title_element}\"`." | ||
); | ||
} | ||
|
||
pub fn assert_ok(response: &Response) { | ||
assert_eq!(response.status, 200); | ||
assert_eq!(response.content_type, "text/html; charset=utf-8"); | ||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
//! End-to-end tests. | ||
//! | ||
//! Execute E2E tests with: | ||
//! | ||
//! ``` | ||
//! cargo test --features e2e-tests | ||
//! ``` | ||
//! cargo test -- --ignored | ||
//! | ||
//! or the Cargo alias | ||
//! | ||
//! ``` | ||
//! cargo e2e | ||
//! ``` | ||
//! | ||
//! > **NOTICE**: E2E tests are not executed by default, because they require | ||
//! a running instance of the API. | ||
//! | ||
//! See the docker documentation for more information on how to run the API. | ||
mod asserts; | ||
mod client; | ||
mod connection_info; | ||
mod contexts; | ||
mod http; | ||
mod response; | ||
mod routes; |
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,17 @@ | ||
use reqwest::Response as ReqwestResponse; | ||
|
||
pub struct Response { | ||
pub status: u16, | ||
pub content_type: String, | ||
pub body: String, | ||
} | ||
|
||
impl Response { | ||
pub async fn from(response: ReqwestResponse) -> Self { | ||
Self { | ||
status: response.status().as_u16(), | ||
content_type: response.headers().get("content-type").unwrap().to_str().unwrap().to_owned(), | ||
body: response.text().await.unwrap(), | ||
} | ||
} | ||
} |
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,26 @@ | ||
use crate::e2e::asserts::{assert_ok, assert_response_title}; | ||
use crate::e2e::client::Client; | ||
use crate::e2e::connection_info::connection_with_no_token; | ||
use crate::e2e::http::Query; | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_load_the_about_page_with_information_about_the_api() { | ||
let client = Client::new(connection_with_no_token("localhost:3000")); | ||
|
||
let response = client.get("about", Query::empty()).await; | ||
|
||
assert_ok(&response); | ||
assert_response_title(&response, "About"); | ||
} | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_load_the_license_page_at_the_api_entrypoint() { | ||
let client = Client::new(connection_with_no_token("localhost:3000")); | ||
|
||
let response = client.get("about/license", Query::empty()).await; | ||
|
||
assert_ok(&response); | ||
assert_response_title(&response, "Licensing"); | ||
} |
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 +1,2 @@ | ||
pub mod about; | ||
pub mod root; |
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,15 @@ | ||
use crate::e2e::asserts::{assert_ok, assert_response_title}; | ||
use crate::e2e::client::Client; | ||
use crate::e2e::connection_info::connection_with_no_token; | ||
use crate::e2e::http::Query; | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_load_the_about_page_at_the_api_entrypoint() { | ||
let client = Client::new(connection_with_no_token("localhost:3000")); | ||
|
||
let response = client.get("", Query::empty()).await; | ||
|
||
assert_ok(&response); | ||
assert_response_title(&response, "About"); | ||
} |