remove json api tests
This commit is contained in:
parent
cbb4027099
commit
72b7281587
|
@ -3,11 +3,8 @@ use std::io::Read;
|
|||
|
||||
use rocket::http::{ContentType, Status};
|
||||
use rocket::local::blocking::Client;
|
||||
use rocket::serde::json::{json, Value};
|
||||
use rocket::{Build, Config, Rocket};
|
||||
|
||||
use crate::utils::build_json_response;
|
||||
|
||||
use super::init_rocket;
|
||||
|
||||
// define authentication mode
|
||||
|
@ -509,179 +506,6 @@ fn network_status_html() {
|
|||
assert!(body.contains("DOWNLOAD"));
|
||||
assert!(body.contains("UPLOAD"));
|
||||
}
|
||||
|
||||
// JSON API ROUTES
|
||||
|
||||
#[test]
|
||||
fn activate_ap() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.post("/api/v1/network/activate_ap")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn activate_client() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.post("/api/v1/network/activate_client")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_ip() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/ip")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("wlan0"));
|
||||
assert!(body.contains("ap0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_rssi() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/rssi")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Not currently connected to an access point."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_ssid() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/ssid")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Not currently connected to an access point."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_state() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/state")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("ap0"));
|
||||
assert!(body.contains("wlan0"));
|
||||
assert!(body.contains("unavailable"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_status() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/status")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Not currently connected to an access point."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scan_networks() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/network/wifi")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Unable to scan for networks. Interface may be deactivated."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_wifi() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.post("/api/v1/network/wifi")
|
||||
.header(ContentType::JSON)
|
||||
.body(r#"{ "ssid": "Home", "pass": "Password" }"#)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Failed to add WiFi credentials."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_wifi() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.post("/api/v1/network/wifi/forget")
|
||||
.header(ContentType::JSON)
|
||||
.body(r#"{ "ssid": "Home" }"#)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Failed to remove WiFi network credentials."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_password() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.post("/api/v1/network/wifi/modify")
|
||||
.header(ContentType::JSON)
|
||||
.body(r#"{ "ssid": "Home", "pass": "Password" }"#)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("Failed to update WiFi password."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ping_pong() {
|
||||
let client = Client::tracked(init_test_rocket(DISABLE_AUTH)).expect("valid rocket instance");
|
||||
let response = client
|
||||
.get("/api/v1/ping")
|
||||
.header(ContentType::JSON)
|
||||
.dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
assert_eq!(response.content_type(), Some(ContentType::JSON));
|
||||
let body = response.into_string().unwrap();
|
||||
assert!(body.contains("pong!"));
|
||||
}
|
||||
|
||||
// HELPER FUNCTION TESTS
|
||||
|
||||
#[test]
|
||||
fn test_build_json_response() {
|
||||
let status = "success".to_string();
|
||||
let data = json!("WiFi credentials added.".to_string());
|
||||
let j: Value = build_json_response(status, Some(data), None);
|
||||
assert_eq!(j["status"], "success");
|
||||
assert_eq!(j["data"], "WiFi credentials added.");
|
||||
assert_eq!(j["msg"], json!(null));
|
||||
}
|
||||
|
||||
// FILE TESTS
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue