extern crate regex;
extern crate reqwest;
extern crate serde_json;

use regex::Regex;
use reqwest::{Client, StatusCode};
use serde_json::Value;

mod common;

#[test]
fn test_app_status_view_returns_app_info_as_a_json() {
    let api_base_uri = common::api_base_url();
    let test_client = Client::new();

    let status_url = api_base_uri.join("/status").unwrap();

    let mut actual_response = test_client.get(status_url).send().unwrap();

    assert_eq!(actual_response.status(), StatusCode::Ok);
    let actual_response_json: Value = actual_response.json().unwrap();
    assert_eq!(actual_response_json["app"], "rookeries");

    let version_regex = Regex::new(r"\d{1,2}\.\d{1,2}\.\d{1,3}").unwrap();
    assert!(version_regex.is_match(&Value::to_string(&actual_response_json["version"])));

    let git_hash_regex = Regex::new(r"[[:alnum:]]{7}").unwrap();
    assert!(git_hash_regex.is_match(&Value::to_string(&actual_response_json["gitRevision"])));
}
