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
use crate::jcli::command::rest::v0::VoteCommand;
use assert_cmd::assert::OutputAssertExt;
use jormungandr_lib::interfaces::{CommitteeIdDef, VotePlanStatus};
use jortestkit::prelude::ProcessOutput;

pub struct Vote {
    vote_command: VoteCommand,
}

impl Vote {
    pub fn new(vote_command: VoteCommand) -> Self {
        Self { vote_command }
    }

    pub fn active_voting_committees<S: Into<String>>(self, host: S) -> Vec<CommitteeIdDef> {
        let content = self
            .vote_command
            .active_committees(host)
            .build()
            .assert()
            .success()
            .get_output()
            .as_lossy_string();
        serde_yaml::from_str(&content).expect("JCLI returned malformed CommitteeIdDef")
    }

    pub fn active_vote_plans<S: Into<String>>(self, host: S) -> Vec<VotePlanStatus> {
        let content = self
            .vote_command
            .active_vote_plans(host)
            .build()
            .assert()
            .success()
            .get_output()
            .as_lossy_string();
        serde_yaml::from_str(&content).expect("JCLI returned malformed VotePlan")
    }
}