db/src/channels.rs/ : Clerical error fix in Response::Other<String> message
src/channels.rs/ : simple log of sql error to stderr main.rs : swapped secret and name parameters as they were backwards somehow (tfw cant type) src/messages.sr : more clerical shit(mispelled parameter name) and logging sql to stderr
This commit is contained in:
parent
88a5d63e4f
commit
751b947bef
@ -186,7 +186,8 @@ impl Channel {
|
|||||||
Err(_) => Response::Empty
|
Err(_) => Response::Empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return Response::Other("Could fetch new channel".into());
|
// TODO: change this to return Result<> which should help with ambiguity
|
||||||
|
return Response::Other("Could not fetch new channel".into());
|
||||||
}
|
}
|
||||||
return Response::Other(no_conn!("db::channels::add"))
|
return Response::Other(no_conn!("db::channels::add"))
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,10 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
|
|||||||
},
|
},
|
||||||
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
|
db::Response::Empty => *response.status_mut() = StatusCode::NOT_FOUND,
|
||||||
// TODO: loggin
|
// TODO: loggin
|
||||||
db::Response::Other(_msg) => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR,
|
db::Response::Other(msg) => {
|
||||||
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
eprintln!("\t{}", msg);
|
||||||
|
}
|
||||||
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -88,87 +91,3 @@ pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod channels_tests {
|
|
||||||
use crate::testing::{get_pool, hyper_resp};
|
|
||||||
use serde_json::Value;
|
|
||||||
use hyper::StatusCode;
|
|
||||||
const DUMMY_TRANSIENT_CHANNEL: &'static str = "sample channel";
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn list_all_channels_good() {
|
|
||||||
// Generation of data
|
|
||||||
let p = get_pool();
|
|
||||||
let mut resp = hyper_resp();
|
|
||||||
// @params: none
|
|
||||||
// Collection of data
|
|
||||||
super::list_channels(&p, &mut resp).await;
|
|
||||||
|
|
||||||
// Analysis
|
|
||||||
assert_eq!(StatusCode::OK, resp.status());
|
|
||||||
println!("list_all_channels_good : \t{:?}", resp.body());
|
|
||||||
let _ = p.disconnect().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn delete_and_create_channel_good() {
|
|
||||||
use chrono::Utc;
|
|
||||||
let p = get_pool();
|
|
||||||
let mut resp = hyper_resp();
|
|
||||||
// @params: name + kind + [description]
|
|
||||||
let cname_id = Utc::now();
|
|
||||||
let params: Value = serde_json::from_str(&format!(r#"
|
|
||||||
{{
|
|
||||||
"name": "{}-{}",
|
|
||||||
"kind": 2,
|
|
||||||
"description": "some random bs"
|
|
||||||
}}
|
|
||||||
"#, DUMMY_TRANSIENT_CHANNEL, cname_id)).unwrap();
|
|
||||||
|
|
||||||
super::create_channel(&p, &mut resp, params).await;
|
|
||||||
|
|
||||||
println!("CREATE CHANNEL: {:?}", resp.body());
|
|
||||||
assert_eq!(StatusCode::OK, resp.status());
|
|
||||||
|
|
||||||
|
|
||||||
// clean up and hopefully delete the channel properly
|
|
||||||
let mut resp_delete = hyper_resp();
|
|
||||||
let params_delete: Value = serde_json::from_str(&format!(r#"
|
|
||||||
{{
|
|
||||||
"name": "{}-{}"
|
|
||||||
}}
|
|
||||||
"#, DUMMY_TRANSIENT_CHANNEL, cname_id)).unwrap();
|
|
||||||
println!("Parameters: {}", params_delete);
|
|
||||||
super::delete_channel(&p, &mut resp_delete, params_delete).await;
|
|
||||||
|
|
||||||
println!("Body: {:?}", resp.body());
|
|
||||||
let _ = p.disconnect().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn delete_channel_missing_name() {
|
|
||||||
let p = get_pool();
|
|
||||||
let mut resp = hyper_resp();
|
|
||||||
// this endpoint is super lenient for some reason btw
|
|
||||||
let param: Value = serde_json::from_str("{}").expect("JSON is not written correctly");
|
|
||||||
|
|
||||||
super::delete_channel(&p, &mut resp, param).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::BAD_REQUEST, resp.status());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn delet_channel_non_real_channel() {
|
|
||||||
let p = get_pool();
|
|
||||||
let mut resp = hyper_resp();
|
|
||||||
// this endpoint is super lenient for some reason btw
|
|
||||||
let param: Value = serde_json::from_str(r#"{
|
|
||||||
"name": "this channel doesn't exist"
|
|
||||||
}"#).expect("JSON is not written correctly");
|
|
||||||
|
|
||||||
super::delete_channel(&p, &mut resp, param).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, resp.status());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -210,7 +210,7 @@ OPTIONS:
|
|||||||
let owner_secret = auth::generate_secret();
|
let owner_secret = auth::generate_secret();
|
||||||
// creation of owner should just dump straight to stdout since this fires
|
// creation of owner should just dump straight to stdout since this fires
|
||||||
// from a commandline parameter anyway
|
// from a commandline parameter anyway
|
||||||
match db::member::Member::add(&p, &owner_secret, "owner sama uwu", perms::OWNER).await {
|
match db::member::Member::add(&p, "owner sama uwu", &owner_secret, perms::OWNER).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response {
|
match response {
|
||||||
db::Response::Row(owner) =>
|
db::Response::Row(owner) =>
|
||||||
|
@ -12,16 +12,16 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, params: Va
|
|||||||
let author = params.get("id")
|
let author = params.get("id")
|
||||||
.unwrap().as_u64().unwrap();
|
.unwrap().as_u64().unwrap();
|
||||||
|
|
||||||
match (params.get("conetnt") , params.get("channel")) {
|
match (params.get("content") , params.get("channel")) {
|
||||||
(Some(content_v), Some(channel_id_v)) => {
|
(Some(content_v), Some(channel_id_v)) => {
|
||||||
let (content, channel) = (content_v.as_str(), channel_id_v.as_u64());
|
let (content, channel) = (content_v.as_str(), channel_id_v.as_u64());
|
||||||
|
|
||||||
if let (Some(message), Some(cid)) = (content, channel) {
|
if let (Some(message), Some(cid)) = (content, channel) {
|
||||||
// call returns empty on sucess so we don't need to do anything
|
// call returns empty on sucess so we don't need to do anything
|
||||||
// TODO: loggin
|
// TODO: loggin
|
||||||
if let Err(_issue) = db::messages::Message::send(pool, message, cid, author).await {
|
if let Err(issue) = db::messages::Message::send(pool, message, cid, author).await {
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
// log(send)
|
eprintln!("\t{}", issue);
|
||||||
}
|
}
|
||||||
// if there's no issue then we don't need to do anything at all
|
// if there's no issue then we don't need to do anything at all
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user