-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(api): [#143] add tests for database failure
- Loading branch information
1 parent
1515753
commit e1ed929
Showing
7 changed files
with
218 additions
and
20 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
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,25 +1,48 @@ | ||
use reqwest::Response; | ||
|
||
pub async fn assert_torrent_not_known(response: Response) { | ||
assert_eq!(response.status(), 200); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); | ||
assert_eq!(response.text().await.unwrap(), "\"torrent not known\""); | ||
} | ||
|
||
pub async fn assert_token_not_valid(response: Response) { | ||
assert_eq!(response.status(), 500); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "text/plain; charset=utf-8"); | ||
assert_eq!( | ||
response.text().await.unwrap(), | ||
"Unhandled rejection: Err { reason: \"token not valid\" }" | ||
); | ||
assert_unhandled_rejection(response, "token not valid").await; | ||
} | ||
|
||
pub async fn assert_unauthorized(response: Response) { | ||
assert_unhandled_rejection(response, "unauthorized").await; | ||
} | ||
|
||
pub async fn assert_failed_to_remove_torrent_from_whitelist(response: Response) { | ||
assert_unhandled_rejection(response, "failed to remove torrent from whitelist").await; | ||
} | ||
|
||
pub async fn assert_failed_to_whitelist_torrent(response: Response) { | ||
assert_unhandled_rejection(response, "failed to whitelist torrent").await; | ||
} | ||
|
||
pub async fn assert_failed_to_generate_key(response: Response) { | ||
assert_unhandled_rejection(response, "failed to generate key").await; | ||
} | ||
|
||
pub async fn assert_failed_to_delete_key(response: Response) { | ||
assert_unhandled_rejection(response, "failed to delete key").await; | ||
} | ||
|
||
pub async fn assert_failed_to_reload_whitelist(response: Response) { | ||
assert_unhandled_rejection(response, "failed to reload whitelist").await; | ||
} | ||
|
||
pub async fn assert_failed_to_reload_keys(response: Response) { | ||
assert_unhandled_rejection(response, "failed to reload keys").await; | ||
} | ||
|
||
async fn assert_unhandled_rejection(response: Response, reason: &str) { | ||
assert_eq!(response.status(), 500); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "text/plain; charset=utf-8"); | ||
assert_eq!( | ||
response.text().await.unwrap(), | ||
"Unhandled rejection: Err { reason: \"unauthorized\" }" | ||
format!("Unhandled rejection: Err {{ reason: \"{reason}\" }}") | ||
); | ||
} | ||
|
||
pub async fn assert_torrent_not_known(response: Response) { | ||
assert_eq!(response.status(), 200); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "application/json"); | ||
assert_eq!(response.text().await.unwrap(), "\"torrent not known\""); | ||
} |
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