feat: paginated introduced starchart instances list with tests
This commit is contained in:
parent
9ff4788b69
commit
83175b333a
4 changed files with 60 additions and 0 deletions
|
@ -58,6 +58,13 @@ pub mod dev {
|
||||||
pub use async_trait::async_trait;
|
pub use async_trait::async_trait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
/// Data related to a Starchart instance
|
||||||
|
pub struct Starchart {
|
||||||
|
/// URL of the Starchart instance
|
||||||
|
pub instance_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
/// create a new forge on the database
|
/// create a new forge on the database
|
||||||
pub struct CreateForge<'a> {
|
pub struct CreateForge<'a> {
|
||||||
|
@ -232,6 +239,13 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||||
|
|
||||||
/// Add Starchart instance to introducer
|
/// Add Starchart instance to introducer
|
||||||
async fn add_starchart_to_introducer(&self, url: &Url) -> DBResult<()>;
|
async fn add_starchart_to_introducer(&self, url: &Url) -> DBResult<()>;
|
||||||
|
|
||||||
|
/// Get all introduced Starchart instances
|
||||||
|
async fn get_all_introduced_starchart_instances(
|
||||||
|
&self,
|
||||||
|
offset: u32,
|
||||||
|
limit: u32,
|
||||||
|
) -> DBResult<Vec<Starchart>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to clone SCDatabase
|
/// Trait to clone SCDatabase
|
||||||
|
|
|
@ -108,3 +108,15 @@ pub async fn forge_type_exists_helper<T: SCDatabase>(db: &T) {
|
||||||
println!("Testing forge implementation exists for: {}", f.to_str());
|
println!("Testing forge implementation exists for: {}", f.to_str());
|
||||||
assert!(db.forge_type_exists(&f).await.unwrap());
|
assert!(db.forge_type_exists(&f).await.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// test if all instance introducer methods work
|
||||||
|
pub async fn instance_introducer_helper<T: SCDatabase>(db: &T, instance_url: &Url) {
|
||||||
|
db.add_starchart_to_introducer(instance_url).await.unwrap();
|
||||||
|
let instances = db
|
||||||
|
.get_all_introduced_starchart_instances(0, 100)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(instances
|
||||||
|
.iter()
|
||||||
|
.any(|i| i.instance_url == instance_url.as_str()));
|
||||||
|
}
|
||||||
|
|
|
@ -831,6 +831,29 @@ impl SCDatabase for Database {
|
||||||
.map_err(map_register_err)?;
|
.map_err(map_register_err)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all introduced Starchart instances
|
||||||
|
async fn get_all_introduced_starchart_instances(
|
||||||
|
&self,
|
||||||
|
offset: u32,
|
||||||
|
limit: u32,
|
||||||
|
) -> DBResult<Vec<Starchart>> {
|
||||||
|
let s = sqlx::query_as!(
|
||||||
|
Starchart,
|
||||||
|
"SELECT
|
||||||
|
instance_url
|
||||||
|
FROM
|
||||||
|
starchart_introducer
|
||||||
|
LIMIT $1 OFFSET $2;
|
||||||
|
",
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DBError::DBError(Box::new(e)))?;
|
||||||
|
Ok(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn now_unix_time_stamp() -> i64 {
|
fn now_unix_time_stamp() -> i64 {
|
||||||
|
|
|
@ -89,6 +89,17 @@ async fn everything_works() {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn introducer_works() {
|
||||||
|
let url = env::var("SQLITE_DATABASE_URL").expect("Set SQLITE_DATABASE_URL env var");
|
||||||
|
let pool_options = SqlitePoolOptions::new().max_connections(2);
|
||||||
|
let connection_options = ConnectionOptions::Fresh(Fresh { pool_options, url });
|
||||||
|
let db = connection_options.connect().await.unwrap();
|
||||||
|
|
||||||
|
let instance_url = Url::parse("https://introducer_works_sqlite_sqlx.example.com").unwrap();
|
||||||
|
instance_introducer_helper(&db, &instance_url).await;
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn forge_type_exists() {
|
async fn forge_type_exists() {
|
||||||
let url = env::var("SQLITE_DATABASE_URL").expect("Set SQLITE_DATABASE_URL env var");
|
let url = env::var("SQLITE_DATABASE_URL").expect("Set SQLITE_DATABASE_URL env var");
|
||||||
|
|
Loading…
Reference in a new issue