chorus/tests/integration.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

use chorus::{
api::{AuthUsername, RegisterSchema, User},
instance::Instance,
URLBundle,
};
2023-05-21 15:51:24 +02:00
#[derive(Debug)]
2023-05-21 00:47:40 +02:00
struct TestBundle {
urls: URLBundle,
2023-05-21 00:47:40 +02:00
user: User,
}
2023-05-21 15:51:24 +02:00
// Set up a test by creating an Instance and a User. Reduces Test boilerplate.
2023-05-21 00:47:40 +02:00
async fn setup() -> TestBundle {
let urls = URLBundle::new(
"http://localhost:3001/api".to_string(),
"ws://localhost:3001".to_string(),
"http://localhost:3001".to_string(),
);
2023-05-21 00:47:40 +02:00
let mut instance = Instance::new(urls.clone()).await.unwrap();
// Requires the existance of the below user.
let reg = RegisterSchema::new(
AuthUsername::new("integrationtestuser".to_string()).unwrap(),
None,
true,
None,
None,
None,
Some("2000-01-01".to_string()),
None,
None,
None,
)
.unwrap();
let user = instance.register_account(&reg).await.unwrap();
TestBundle { urls, user }
}
2023-05-21 00:47:40 +02:00
// Teardown method to clean up after a test.
async fn teardown(bundle: TestBundle) {
bundle.user.delete().await;
}