Added unit test for api/initial_setup
This commit is contained in:
parent
5f91da915e
commit
132a8c3dbf
2 changed files with 37 additions and 3 deletions
|
@ -160,9 +160,9 @@ fn version() -> Json<Version> {
|
|||
Json(current_version)
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct InitialSetup {
|
||||
has_any_users: bool,
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub struct InitialSetup {
|
||||
pub has_any_users: bool,
|
||||
}
|
||||
|
||||
#[get("/initial_setup")]
|
||||
|
|
|
@ -40,6 +40,16 @@ fn get_test_environment(db_name: &str) -> TestEnvironment
|
|||
TestEnvironment { client, command_sender }
|
||||
}
|
||||
|
||||
fn complete_initial_setup(client: &Client) {
|
||||
client.get("/api/initial_setup").dispatch();
|
||||
client.put("/api/settings")
|
||||
.body(r#"
|
||||
{ "users": [{ "name": "test_user", "password": "test_password", "admin": true }]
|
||||
, "mount_dirs": [{ "name": "collection", "source": "test/collection" }]
|
||||
}"#)
|
||||
.dispatch();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version() {
|
||||
let env = get_test_environment("api_version.sqlite");
|
||||
|
@ -52,3 +62,27 @@ fn version() {
|
|||
let response_json: api::Version = serde_json::from_str(&response_body).unwrap();
|
||||
assert_eq!(response_json, api::Version{major: 3, minor: 0});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initial_setup() {
|
||||
let env = get_test_environment("api_initial_setup.sqlite");
|
||||
let client = &env.client;
|
||||
|
||||
{
|
||||
let mut response = client.get("/api/initial_setup").dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
let response_body = response.body_string().unwrap();
|
||||
let response_json: api::InitialSetup = serde_json::from_str(&response_body).unwrap();
|
||||
assert_eq!(response_json, api::InitialSetup{has_any_users: false});
|
||||
}
|
||||
|
||||
complete_initial_setup(client);
|
||||
|
||||
{
|
||||
let mut response = client.get("/api/initial_setup").dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
let response_body = response.body_string().unwrap();
|
||||
let response_json: api::InitialSetup = serde_json::from_str(&response_body).unwrap();
|
||||
assert_eq!(response_json, api::InitialSetup{has_any_users: true});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue