-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #112: E2E tests for API
user
routes
2b58923 tests: [#111] E2E test for user routes (Jose Celano) f257692 feat: [#111] add cargo dependency rand (Jose Celano) 73a26ae tests: [#109] E2E test for category routes (Jose Celano) 652f50b refactor: [#109] extract structs and functions (Jose Celano) Pull request description: E2E tests for API `user` routes. ACKs for top commit: josecelano: ACK 2b58923 da2ce7: ACK 2b58923 Tree-SHA512: 974a0393e0e2910c7855b8b9d7eb8bb04b57b6025b836ec27d2f1eb2a6438a7eeec731b344883fbe74c79f6be50fb4f21d813fd00465913be4c2454a77c13a12
- Loading branch information
Showing
23 changed files
with
580 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ pbkdf2 = "0.11.0" | |
text-colorizer = "1.0.0" | ||
log = "0.4.17" | ||
fern = "0.6.2" | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ max_password_length = 64 | |
secret_key = "MaxVerstappenWC2021" | ||
|
||
[database] | ||
connect_url = "sqlite://storage/database/data.db?mode=rwc" # SQLite | ||
connect_url = "sqlite://storage/database/torrust_index_backend_e2e_testing.db?mode=rwc" # SQLite | ||
#connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index_backend" # MySQL | ||
torrent_info_update_interval = 3600 | ||
|
||
|
@@ -28,5 +28,5 @@ from = "[email protected]" | |
reply_to = "[email protected]" | ||
username = "" | ||
password = "" | ||
server = "" | ||
port = 25 | ||
server = "mailcatcher" | ||
port = 1025 |
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ Leechers | |
LEECHERS | ||
lettre | ||
luckythelab | ||
mailcatcher | ||
nanos | ||
NCCA | ||
nilm | ||
|
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,15 +1,35 @@ | ||
use crate::e2e::response::Response; | ||
|
||
// Text responses | ||
|
||
pub fn assert_response_title(response: &Response, title: &str) { | ||
let title_element = format!("<title>{title}</title>"); | ||
|
||
assert!( | ||
response.body.contains(&title), | ||
response.body.contains(title), | ||
":\n response does not contain the title element: `\"{title_element}\"`." | ||
); | ||
} | ||
|
||
pub fn assert_ok(response: &Response) { | ||
pub fn assert_text_ok(response: &Response) { | ||
assert_eq!(response.status, 200); | ||
if let Some(content_type) = &response.content_type { | ||
assert_eq!(content_type, "text/html; charset=utf-8"); | ||
} | ||
} | ||
|
||
pub fn _assert_text_bad_request(response: &Response) { | ||
assert_eq!(response.status, 400); | ||
if let Some(content_type) = &response.content_type { | ||
assert_eq!(content_type, "text/plain; charset=utf-8"); | ||
} | ||
} | ||
|
||
// JSON responses | ||
|
||
pub fn assert_json_ok(response: &Response) { | ||
assert_eq!(response.status, 200); | ||
assert_eq!(response.content_type, "text/html; charset=utf-8"); | ||
if let Some(content_type) = &response.content_type { | ||
assert_eq!(content_type, "application/json"); | ||
} | ||
} |
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,16 +1,29 @@ | ||
pub fn connection_with_no_token(bind_address: &str) -> ConnectionInfo { | ||
pub fn anonymous_connection(bind_address: &str) -> ConnectionInfo { | ||
ConnectionInfo::anonymous(bind_address) | ||
} | ||
|
||
pub fn authenticated_connection(bind_address: &str, token: &str) -> ConnectionInfo { | ||
ConnectionInfo::new(bind_address, token) | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ConnectionInfo { | ||
pub bind_address: String, | ||
pub token: Option<String>, | ||
} | ||
|
||
impl ConnectionInfo { | ||
pub fn new(bind_address: &str, token: &str) -> Self { | ||
Self { | ||
bind_address: bind_address.to_string(), | ||
token: Some(token.to_string()), | ||
} | ||
} | ||
|
||
pub fn anonymous(bind_address: &str) -> Self { | ||
Self { | ||
bind_address: bind_address.to_string(), | ||
token: None, | ||
} | ||
} | ||
} |
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,24 @@ | ||
use crate::e2e::asserts::{assert_response_title, assert_text_ok}; | ||
use crate::e2e::environment::TestEnv; | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_load_the_about_page_with_information_about_the_api() { | ||
let client = TestEnv::default().unauthenticated_client(); | ||
|
||
let response = client.about().await; | ||
|
||
assert_text_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 = TestEnv::default().unauthenticated_client(); | ||
|
||
let response = client.license().await; | ||
|
||
assert_text_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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::e2e::asserts::assert_json_ok; | ||
use crate::e2e::environment::TestEnv; | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_return_an_empty_category_list_when_there_are_no_categories() { | ||
let client = TestEnv::default().unauthenticated_client(); | ||
|
||
let response = client.get_categories().await; | ||
|
||
assert_json_ok(&response); | ||
} | ||
|
||
/* todo: | ||
- it_should_not_allow_adding_a_new_category_to_unauthenticated_clients | ||
- it should allow adding a new category to authenticated clients | ||
- it should not allow adding a new category with an empty name | ||
- it should not allow adding a new category with an empty icon | ||
- ... | ||
*/ |
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,4 @@ | ||
pub mod about; | ||
pub mod category; | ||
pub mod root; | ||
pub mod user; |
Oops, something went wrong.