Skip to content

Commit

Permalink
chore: update test for pubs
Browse files Browse the repository at this point in the history
  • Loading branch information
shanithkk committed Mar 25, 2024
1 parent 129a194 commit 378354b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
12 changes: 6 additions & 6 deletions runtime/lite/src/modules/kuska_ssb_client/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,18 @@ impl Client {
Ok(())
}

pub async fn create_invite(&mut self) -> Result<()> {
pub async fn create_invite(&mut self) -> Result<String> {
let req_id = self.api.invite_create_req_send(1).await?;

self.print_source_until_eof(req_id, invite_create).await?;
let res = self.get_async(req_id, invite_create).await?;

Ok(())
Ok(res)
}
pub async fn accept_invite(&mut self, invite_code: &str) -> Result<()> {
pub async fn accept_invite(&mut self, invite_code: &str) -> Result<Vec<Feed>> {
let req_id = self.api.invite_use_req_send(invite_code).await?;

self.print_source_until_eof(req_id, invite_create).await?;
Ok(())
let res = self.get_async(req_id, invite_accept_res_parse).await?;
Ok(res)
}

pub async fn publish(&mut self, msg: &str, mention: Option<Vec<Mention>>) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ pub fn latest_res_parse(body: &[u8]) -> Result<LatestOut> {
}

pub fn invite_create(body: &[u8]) -> Result<String> {
Ok(std::str::from_utf8(&body)
.map_err(|err| Box::new(err) as Box<dyn std::error::Error>)?
.to_string())
}

pub fn invite_accept_res_parse(body: &[u8]) -> Result<Vec<Feed>> {
Ok(serde_json::from_slice(body)?)
}
44 changes: 42 additions & 2 deletions runtime/lite/src/modules/kuska_ssb_client/client/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(test)]
mod tests {
use kuska_ssb::keystore::read_patchwork_config;

use crate::modules::kuska_ssb_client::client::{types, Client, UserConfig};

use super::*;
Expand Down Expand Up @@ -33,7 +35,9 @@ mod tests {
let user = UserConfig::new("vhuaeBySHfMTeBpTseKP/ksOVtyLGaqZ+Ae4SyQk7wY=",
"MywOEUUCk9rUcWq6OFsfbzZABDc+sItJHJoN+RJrwMK+G5p4HJId8xN4GlOx4o/+Sw5W3IsZqpn4B7hLJCTvBg=",
"@vhuaeBySHfMTeBpTseKP/ksOVtyLGaqZ+Ae4SyQk7wY=.ed25519");
let mut client = Client::new(None, "0.0.0.0".to_string(), "8015".to_string()).await.unwrap();
let mut client = Client::new(None, "0.0.0.0".to_string(), "8015".to_string())
.await
.unwrap();
client.feed(true).await.unwrap();
}

Expand Down Expand Up @@ -88,7 +92,7 @@ mod tests {

// Tranfer the amount manually after starting this function

//Todo
//Todo
// Change user configuration
let user = UserConfig::new("PV5BFUk8N6DN1lEmnaS6ssZ9HvUc5WqLZP0lHN++CME=",
"iwmBTO3wfIqvOa8aodBJSdmcqhY4IByy9THlWNalL7E9XkEVSTw3oM3WUSadpLqyxn0e9Rzlaotk/SUc374IwQ=",
Expand Down Expand Up @@ -160,4 +164,40 @@ mod tests {
}
}
}

#[async_std::test]
#[ignore]
async fn test_create_invite() {
dotenv::dotenv().ok();
let secret = std::env::var("PUB_SECRET").unwrap_or_else(|_| {
let home_dir = dirs::home_dir().unwrap();
std::format!("{}/.ssb/secret", home_dir.to_string_lossy())
});
let port = std::env::var("PUB_PORT").unwrap_or_else(|_| 8013.to_string());
let mut file = async_std::fs::File::open(secret).await.unwrap();
let key = read_patchwork_config(&mut file).await.unwrap();
let mut client = Client::new(Some(key), "0.0.0.0".to_string(), port)
.await
.unwrap();
let res = client.create_invite().await;
assert!(res.is_ok())
}

#[async_std::test]
#[ignore]
async fn test_accept_invite() {
dotenv::dotenv().ok();
let secret = std::env::var("CONSUMER_SECRET").unwrap_or_else(|_| {
let home_dir = dirs::home_dir().unwrap();
std::format!("{}/.ssb/secret", home_dir.to_string_lossy())
});
let port = std::env::var("CONSUMER_PORT").unwrap_or_else(|_| 8015.to_string());
let mut file = async_std::fs::File::open(secret).await.unwrap();
let key = read_patchwork_config(&mut file).await.unwrap();
let mut client = Client::new(Some(key), "0.0.0.0".to_string(), port)
.await
.unwrap();
let res = client.accept_invite("172.28.0.4:8008:@hkYrVBGtWm5+xeRYDzsL9u6b0cM2rtcYs4NiiZQEVLs=.ed25519~BERengMsq9t2ovXHBZgiFtKDlcvAYQTXSPk/JAw+3zQ=").await;
assert!(res.is_ok())
}
}

0 comments on commit 378354b

Please sign in to comment.