Trailing slash tests (#105)

* Better test names

* Add tests for recent/random endpoints with trailing slash
This commit is contained in:
Antoine Gersant 2020-12-03 21:31:14 -08:00 committed by GitHub
parent 2eed57cc47
commit f80a42e666
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,16 @@
use http::StatusCode;
use http::{Request, StatusCode};
use std::path::{Path, PathBuf};
use crate::index;
use crate::service::test::{constants::*, ServiceType, TestService};
use crate::test_name;
fn add_trailing_slash<T>(request: &mut Request<T>) {
*request.uri_mut() = (request.uri().to_string().trim_end_matches("/").to_string() + "/")
.parse()
.unwrap();
}
#[test]
fn test_browse_requires_auth() {
let mut service = ServiceType::new(&test_name!());
@ -117,7 +123,7 @@ fn test_random_requires_auth() {
}
#[test]
fn test_random() {
fn test_random_golden_path() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
@ -131,6 +137,22 @@ fn test_random() {
assert_eq!(entries.len(), 3);
}
#[test]
fn test_random_with_trailing_slash() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
service.index();
service.login();
let mut request = service.request_builder().random();
add_trailing_slash(&mut request);
let response = service.fetch_json::<_, Vec<index::Directory>>(&request);
assert_eq!(response.status(), StatusCode::OK);
let entries = response.body();
assert_eq!(entries.len(), 3);
}
#[test]
fn test_recent_requires_auth() {
let mut service = ServiceType::new(&test_name!());
@ -140,7 +162,7 @@ fn test_recent_requires_auth() {
}
#[test]
fn test_recent() {
fn test_recent_golden_path() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
@ -154,6 +176,22 @@ fn test_recent() {
assert_eq!(entries.len(), 3);
}
#[test]
fn test_recent_with_trailing_slash() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
service.index();
service.login();
let mut request = service.request_builder().recent();
add_trailing_slash(&mut request);
let response = service.fetch_json::<_, Vec<index::Directory>>(&request);
assert_eq!(response.status(), StatusCode::OK);
let entries = response.body();
assert_eq!(entries.len(), 3);
}
#[test]
fn test_search_requires_auth() {
let mut service = ServiceType::new(&test_name!());