Add tests for coverage

This commit is contained in:
bitfl0wer 2023-11-22 18:48:44 +01:00
parent 7954e38643
commit 05fd02a717
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
2 changed files with 51 additions and 4 deletions

View File

@ -9,7 +9,7 @@ async fn main() {
"wss://example.com/".to_string(), "wss://example.com/".to_string(),
"https://example.com/cdn".to_string(), "https://example.com/cdn".to_string(),
); );
let instance = Instance::new(bundle, true) let mut instance = Instance::new(bundle, true)
.await .await
.expect("Failed to connect to the Spacebar server"); .expect("Failed to connect to the Spacebar server");
// Assume, you already have an account created on this instance. Registering an account works // Assume, you already have an account created on this instance. Registering an account works

View File

@ -1,4 +1,6 @@
use chorus::types::RegisterSchema; use std::borrow::BorrowMut;
use chorus::types::{LoginSchema, RegisterSchema};
// PRETTYFYME: Move common wasm setup to common.rs // PRETTYFYME: Move common wasm setup to common.rs
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
@ -10,14 +12,59 @@ mod common;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] #[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_registration() { async fn test_registration() {
let bundle = common::setup().await; let mut bundle = common::setup().await;
let reg = RegisterSchema { let reg = RegisterSchema {
username: "Hiiii".into(), username: "Hiiii".into(),
date_of_birth: Some("2000-01-01".to_string()), date_of_birth: Some("2000-01-01".to_string()),
consent: true, consent: true,
..Default::default() ..Default::default()
}; };
bundle.instance.clone().register_account(reg).await.unwrap(); bundle.instance.register_account(reg).await.unwrap();
common::teardown(bundle).await;
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_login() {
let mut bundle = common::setup().await;
let reg = RegisterSchema {
username: "Hiiii".into(),
email: Some("testuser1@integrationtesting.xyz".into()),
password: Some("Correct-Horse-Battery-Staple1".into()),
date_of_birth: Some("2000-01-01".to_string()),
consent: true,
..Default::default()
};
bundle.instance.register_account(reg).await.unwrap();
let login = LoginSchema {
login: "testuser1@integrationtesting.xyz".into(),
password: "Correct-Horse-Battery-Staple1".into(),
..Default::default()
};
bundle.instance.login_account(login).await.unwrap();
common::teardown(bundle).await;
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_wrong_login() {
let mut bundle = common::setup().await;
let reg = RegisterSchema {
username: "Hiiii".into(),
email: Some("testuser2@integrationtesting.xyz".into()),
password: Some("Correct-Horse-Battery-Staple1".into()),
date_of_birth: Some("2000-01-01".to_string()),
consent: true,
..Default::default()
};
bundle.instance.register_account(reg).await.unwrap();
let login = LoginSchema {
login: "testuser2@integrationtesting.xyz".into(),
password: "Correct-Horse-Battery-Staple2".into(),
..Default::default()
};
let res = bundle.instance.login_account(login).await;
assert!(res.is_err());
common::teardown(bundle).await; common::teardown(bundle).await;
} }