Saving tests
Rust Build / Test Suite (pull_request) Successful in 44s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Check (pull_request) Successful in 1m15s
Rust Build / Clippy (pull_request) Successful in 1m45s
Rust Build / build (pull_request) Successful in 1m48s
Rust Build / Test Suite (pull_request) Successful in 44s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Check (pull_request) Successful in 1m15s
Rust Build / Clippy (pull_request) Successful in 1m45s
Rust Build / build (pull_request) Successful in 1m48s
This commit is contained in:
+119
-109
@@ -187,131 +187,139 @@ mod util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn register_user(
|
mod flow {
|
||||||
app: &axum::Router,
|
use super::callers;
|
||||||
) -> Result<textsender_models::user::User, std::io::Error> {
|
use super::requests;
|
||||||
match requests::register_user(&app).await {
|
use super::util;
|
||||||
Ok(response) => {
|
|
||||||
if axum::http::StatusCode::CREATED != response.status() {
|
pub async fn register_user(
|
||||||
Err(std::io::Error::other(format!(
|
app: &axum::Router,
|
||||||
"Status code is off {:?}",
|
) -> Result<textsender_models::user::User, std::io::Error> {
|
||||||
response.status()
|
match requests::register_user(&app).await {
|
||||||
)))
|
Ok(response) => {
|
||||||
} else {
|
if axum::http::StatusCode::CREATED != response.status() {
|
||||||
match util::convert_response::<callers::register::response::Response>(response)
|
Err(std::io::Error::other(format!(
|
||||||
|
"Status code is off {:?}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
match util::convert_response::<callers::register::response::Response>(response)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
if response.data.len() > 0 {
|
||||||
|
let user = response.data[0].clone();
|
||||||
|
Ok(user)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn login_user(
|
||||||
|
app: &axum::Router,
|
||||||
|
username: &str,
|
||||||
|
password: &str,
|
||||||
|
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||||
|
match requests::login_user(&app, username, password).await {
|
||||||
|
Ok(response) => {
|
||||||
|
if axum::http::StatusCode::OK != response.status() {
|
||||||
|
Err(std::io::Error::other(format!(
|
||||||
|
"Status code is off {:?}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
match util::convert_response::<callers::login::response::LoginResponse>(
|
||||||
|
response,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if response.data.len() > 0 {
|
if response.data.len() > 0 {
|
||||||
let user = response.data[0].clone();
|
let user = response.data[0].clone();
|
||||||
Ok(user)
|
Ok(user)
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other("No data returned"))
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn login_user(
|
pub async fn register_service_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
username: &str,
|
) -> Result<textsender_models::user::ServiceUser, std::io::Error> {
|
||||||
password: &str,
|
match requests::register_service_user(&app).await {
|
||||||
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
Ok(response) => {
|
||||||
match requests::login_user(&app, username, password).await {
|
if axum::http::StatusCode::CREATED != response.status() {
|
||||||
Ok(response) => {
|
Err(std::io::Error::other(format!(
|
||||||
if axum::http::StatusCode::OK != response.status() {
|
"Status code is off {:?}",
|
||||||
Err(std::io::Error::other(format!(
|
response.status()
|
||||||
"Status code is off {:?}",
|
)))
|
||||||
response.status()
|
} else {
|
||||||
)))
|
match util::convert_response::<
|
||||||
} else {
|
callers::register::response::RegisterServiceUserResponse,
|
||||||
match util::convert_response::<callers::login::response::LoginResponse>(response)
|
>(response)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
if response.data.len() > 0 {
|
if response.data.len() > 0 {
|
||||||
let user = response.data[0].clone();
|
let service_user = response.data[0].clone();
|
||||||
Ok(user)
|
Ok(service_user)
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other("No data returned"))
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn register_service_user(
|
pub async fn login_service_user(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
) -> Result<textsender_models::user::ServiceUser, std::io::Error> {
|
username: &str,
|
||||||
match requests::register_service_user(&app).await {
|
passphrase: &str,
|
||||||
Ok(response) => {
|
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||||
if axum::http::StatusCode::CREATED != response.status() {
|
match requests::login_service_user(&app, username, passphrase).await {
|
||||||
Err(std::io::Error::other(format!(
|
Ok(response) => {
|
||||||
"Status code is off {:?}",
|
if axum::http::StatusCode::OK != response.status() {
|
||||||
response.status()
|
Err(std::io::Error::other(format!(
|
||||||
)))
|
"Status code is off {:?}",
|
||||||
} else {
|
response.status()
|
||||||
match util::convert_response::<
|
)))
|
||||||
callers::register::response::RegisterServiceUserResponse,
|
} else {
|
||||||
>(response)
|
match util::convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
||||||
.await
|
response,
|
||||||
{
|
)
|
||||||
Ok(response) => {
|
.await
|
||||||
if response.data.len() > 0 {
|
{
|
||||||
let service_user = response.data[0].clone();
|
Ok(response) => {
|
||||||
Ok(service_user)
|
if response.data.len() > 0 {
|
||||||
} else {
|
let login_result = response.data[0].clone();
|
||||||
Err(std::io::Error::other("No data returned"))
|
Ok(login_result)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other("No data returned"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn login_service_user(
|
|
||||||
app: &axum::Router,
|
|
||||||
username: &str,
|
|
||||||
passphrase: &str,
|
|
||||||
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
|
||||||
match requests::login_service_user(&app, username, passphrase).await {
|
|
||||||
Ok(response) => {
|
|
||||||
if axum::http::StatusCode::OK != response.status() {
|
|
||||||
Err(std::io::Error::other(format!(
|
|
||||||
"Status code is off {:?}",
|
|
||||||
response.status()
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
match util::convert_response::<callers::login::response::ServiceUserLoginResponse>(
|
|
||||||
response,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(response) => {
|
|
||||||
if response.data.len() > 0 {
|
|
||||||
let login_result = response.data[0].clone();
|
|
||||||
Ok(login_result)
|
|
||||||
} else {
|
|
||||||
Err(std::io::Error::other("No data returned"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +343,7 @@ async fn test_register_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_user(&app).await {
|
match flow::register_user(&app).await {
|
||||||
Ok(returned_user) => {
|
Ok(returned_user) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
TEST_USERNAME, returned_user.username,
|
TEST_USERNAME, returned_user.username,
|
||||||
@@ -375,8 +383,8 @@ async fn test_login_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_user(&app).await {
|
match flow::register_user(&app).await {
|
||||||
Ok(user) => match login_user(&app, &user.username, TEST_PASSWORD).await {
|
Ok(user) => match flow::login_user(&app, &user.username, TEST_PASSWORD).await {
|
||||||
Ok(login_result) => {
|
Ok(login_result) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
@@ -474,14 +482,16 @@ async fn test_login_service_user() {
|
|||||||
|
|
||||||
let app = init::routes().await.layer(axum::Extension(pool));
|
let app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
match register_service_user(&app).await {
|
match flow::register_service_user(&app).await {
|
||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
user.id.is_nil(),
|
user.id.is_nil(),
|
||||||
"The service user id should not be nil"
|
"The service user id should not be nil"
|
||||||
);
|
);
|
||||||
match login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE).await {
|
match flow::login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(login_result) => {
|
Ok(login_result) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
false,
|
false,
|
||||||
|
|||||||
Reference in New Issue
Block a user