summaryrefslogtreecommitdiff
path: root/src/tests.rs
blob: 3fafdbeff462ff54fcf868c1b1c2850b5b3cd686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::client::HydrusClient;
use crate::types::*;

#[test]
fn correct_hydruspermissions_url_encode() {
    let perms: [HydrusPermissions; 3] = [
        HydrusPermissions::ImportAndEditURLs,
        HydrusPermissions::ImportAndEditFiles,
        HydrusPermissions::SeeLocalPaths,
    ];
    let json_string = musli::json::to_string(&perms).unwrap();
    let encoded = urlencoding::encode(&json_string);

    assert_eq!(encoded, "%5B0%2C1%2C13%5D")
}

#[test]
fn correct_hydruspermissions_decode() {
    let perms: [HydrusPermissions; 3] = [
        HydrusPermissions::ImportAndEditURLs,
        HydrusPermissions::ImportAndEditFiles,
        HydrusPermissions::SeeLocalPaths,
    ];
    let json_string = musli::json::to_string(&perms).unwrap();

    let res: [HydrusPermissions; 3] = musli::json::from_str(&json_string).unwrap();
    assert_eq!(res, perms)
}

#[test]
fn correct_hydrusservice_decode() {
    let input: [ServiceType; 3] = [
        ServiceType::AllLocalFiles,
        ServiceType::ClientAPI,
        ServiceType::Trash,
    ];

    let json_string = musli::json::to_string(&input).unwrap();

    let res: [ServiceType; 3] = musli::json::from_str(&json_string).unwrap();
    assert_eq!(res, input)
}

#[test]
fn get_keys() {
    let client: HydrusClient = HydrusClient::new("http://127.0.0.1:51251/");
    let _ = client.request_new_permissions("test client", &[]).unwrap();
}