Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit c2bfe48c authored by Éloïs's avatar Éloïs
Browse files

Merge branch 'master' into 'master'

feat: add members count query

See merge request !1
parents 11d48a8f 45da934b
Pipeline #10515 passed with stages
in 12 minutes and 25 seconds
......@@ -12,3 +12,9 @@ query CurrentUd {
amount
}
}
query MembersCount {
currentBlock {
membersCount
}
}
......@@ -25,6 +25,8 @@ pub(crate) enum Command {
},
/// Get current UD value
CurrentUd,
/// Get current number of WoT members
MembersCount,
}
pub(crate) fn balance<W: Write>(
......@@ -83,6 +85,24 @@ pub(crate) fn current_ud<W: Write>(client: &Client, out: &mut W) -> anyhow::Resu
Ok(())
}
pub(crate) fn members_count<W: Write>(client: &Client, out: &mut W) -> anyhow::Result<()> {
let request_body = MembersCount::build_query(members_count::Variables);
let members_count::ResponseData {
current_block: members_count::MembersCountCurrentBlock { members_count },
} = client.send_gql_query(&request_body)?;
writeln!(
out,
"There is currently {} members in Ğ1 WoT!",
members_count
)?;
Ok(())
}
// below are tests
#[cfg(test)]
mod tests {
use super::*;
......@@ -145,4 +165,25 @@ mod tests {
Ok(())
}
#[test]
fn test_member_count() -> anyhow::Result<()> {
let mut client = Client::default();
client
.expect_send_gql_query::<graphql_client::QueryBody<members_count::Variables>, _>()
.returning(|_| {
Ok(members_count::ResponseData {
current_block: members_count::MembersCountCurrentBlock {
members_count: 10_000,
},
})
});
let mut out = Vec::new();
members_count(&client, &mut out)?;
let output = std::str::from_utf8(&out)?;
assert_eq!(output, "There is currently 10000 members in Ğ1 WoT!\n");
Ok(())
}
}
......@@ -32,7 +32,7 @@ use crate::client::Client;
#[cfg(test)]
use crate::client::MockClient as Client;
use crate::commands::Command;
use commands::{balance, current_ud};
use commands::{balance, current_ud, members_count};
use graphql_client::GraphQLQuery;
use graphql_client::Response;
use std::io::Write;
......@@ -49,6 +49,10 @@ pub struct Balance;
#[graphql(schema_path = "gql/gva_schema.gql", query_path = "gql/gva_queries.gql")]
pub struct CurrentUd;
#[derive(Debug, Clone, Copy, GraphQLQuery)]
#[graphql(schema_path = "gql/gva_schema.gql", query_path = "gql/gva_queries.gql")]
pub struct MembersCount;
#[derive(StructOpt)]
#[structopt(name = "rust-gva-client", about = "Client use GVA API of Duniter.")]
struct CliArgs {
......@@ -71,6 +75,7 @@ fn main() -> anyhow::Result<()> {
ud_unit,
} => balance(&client, &mut out, &pubkey_or_script, ud_unit)?,
Command::CurrentUd => current_ud(&client, &mut out)?,
Command::MembersCount => members_count(&client, &mut out)?,
}
Ok(())
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment