- Removing /messages/from_id as its no longer usable with the new id generation model
+ Adding new flags to sample .env file + Wrapper script run-api-tests.sh which does as its called - Removing build.sh in favor of run-api-tests.sh Makefile takes care of building, and apitests are ran with special script anyway
This commit is contained in:
parent
bb2201c00e
commit
52676cdd1f
@ -4,12 +4,11 @@ DATABASE_PASS=password
|
|||||||
DATABASE_USER=freechat_dev
|
DATABASE_USER=freechat_dev
|
||||||
DATABASE_HOST=localhost
|
DATABASE_HOST=localhost
|
||||||
DATABASE_PORT=3306
|
DATABASE_PORT=3306
|
||||||
REDIS_URL=redis://127.0.0.1:6379
|
|
||||||
|
|
||||||
|
|
||||||
# Server meta things
|
# Server meta things
|
||||||
SERVER_NAME="Freechat Dev Server"
|
SERVER_NAME="Freechat Dev Server"
|
||||||
SERVER_DESCRIPTION="Server for sick development things"
|
SERVER_DESCRIPTION="Server for sick development things"
|
||||||
SERVER_HOSTNAME=localhost
|
# NOTE: most clients shouldn't expect these to end with a slash
|
||||||
SERVER_PORT=4536
|
PUBLIC_URL=http://localhost:4536
|
||||||
SERVER_PROTOCOL=http
|
PUBLIC_WS_URL=ws://localhost:5648
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
_help() {
|
|
||||||
cat <<EOF
|
|
||||||
Usage: ./build.sh [-h|-t|-b|-r]
|
|
||||||
h Help : shows this command
|
|
||||||
f Full : Runs all available tests including the cargo ones
|
|
||||||
t Test : Runs All tests from cargo tests to client tests
|
|
||||||
T Test Realse : Runs tests against release build
|
|
||||||
b Build : Builds dev build with 'cargo build'
|
|
||||||
r Release : Builds release build with --release flag
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ -z $1 ]] && _help && exit 0
|
|
||||||
|
|
||||||
diesel database reset
|
|
||||||
export CARGO_BIN=$HOME/.cargo/bin/cargo
|
|
||||||
full=
|
|
||||||
|
|
||||||
testing() {
|
|
||||||
release_opt=$1
|
|
||||||
cargo build $release_opt
|
|
||||||
# next we run the server in the background
|
|
||||||
|
|
||||||
cargo run $release_opt -- -s&
|
|
||||||
sid=$!
|
|
||||||
|
|
||||||
# wait a sec
|
|
||||||
echo Waiting on server to start
|
|
||||||
sleep 3
|
|
||||||
# now fire off client tests
|
|
||||||
source ./client-tests/bin/activate
|
|
||||||
python3 client-tests/client.py
|
|
||||||
# clean up the server now
|
|
||||||
kill -9 $sid
|
|
||||||
if [ ! -z $full ];then
|
|
||||||
cargo test $release_opt
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
while getopts ":fhtTbr" arg; do
|
|
||||||
case ${arg} in
|
|
||||||
f) full=true;;
|
|
||||||
h) echo help command;;
|
|
||||||
t) testing;;
|
|
||||||
T) testing --release;;
|
|
||||||
b) cargo build;;
|
|
||||||
r) cargo build --release;;
|
|
||||||
*) _help;;
|
|
||||||
esac
|
|
||||||
done
|
|
24
json-api/run-api-tests.sh
Normal file
24
json-api/run-api-tests.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# First the rtc server
|
||||||
|
pushd ../rtc-server/
|
||||||
|
node main.js&
|
||||||
|
rtc_pid=$!
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Next the json api
|
||||||
|
cargo run --release -- -s&
|
||||||
|
json_pid=$!
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Next come back and startup the rest test client
|
||||||
|
source ./client-tests/bin/activate
|
||||||
|
python3 client-tests/client.py
|
||||||
|
|
||||||
|
catch errors that may occur and kill off process group
|
||||||
|
trap "kill $json_pid $rtc_pid" exit INT TERM
|
||||||
|
|
||||||
|
# Normal exit (for the most part)
|
||||||
|
kill -9 $json_pid $rtc_pid
|
||||||
|
|
||||||
|
echo Done
|
@ -76,7 +76,6 @@ async fn route_dispatcher(
|
|||||||
/* MESSAGING */
|
/* MESSAGING */
|
||||||
(POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, body, headers, params).await,
|
(POST, routes::MESSAGE_SEND) => messages::send_message(pool, resp, body, headers, params).await,
|
||||||
(GET, routes::MESSAGE_TIME_RANGE) => messages::get_by_time(pool, resp, params).await,
|
(GET, routes::MESSAGE_TIME_RANGE) => messages::get_by_time(pool, resp, params).await,
|
||||||
(GET, routes::MESSAGE_FROM_ID) =>messages::from_id(pool, resp, params).await,
|
|
||||||
(GET, routes::MESSAGE_LAST_N) => messages::recent_messages(pool, resp, params).await,
|
(GET, routes::MESSAGE_LAST_N) => messages::recent_messages(pool, resp, params).await,
|
||||||
/* ADMIN */
|
/* ADMIN */
|
||||||
(POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await,
|
(POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await,
|
||||||
|
@ -130,49 +130,6 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn from_id(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
|
||||||
/*
|
|
||||||
* @start-id: u64
|
|
||||||
* @limit: optional<u64>
|
|
||||||
* @channel: u64
|
|
||||||
* {
|
|
||||||
* "channel_id": 1,
|
|
||||||
* "start": 123,
|
|
||||||
* "limit": 100
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
let channel = qs_param!(params, "channel_id", u64);
|
|
||||||
let start_id = qs_param!(params, "start", u64);
|
|
||||||
let limit = qs_param!(params, "limit", u64);
|
|
||||||
|
|
||||||
if let (Some(channel), Some(start_id)) = (channel, start_id) {
|
|
||||||
match Message::get_from_id(pool, channel, start_id, limit).await {
|
|
||||||
Ok(db_response) => {
|
|
||||||
match db_response {
|
|
||||||
db::Response::Set(messages) => {
|
|
||||||
// *any* kind of empty response, even those from weird
|
|
||||||
// parameters get 404's
|
|
||||||
if messages.len() == 0 {
|
|
||||||
*response.status_mut() = StatusCode::NOT_FOUND;
|
|
||||||
} else {
|
|
||||||
set_json_body(response, json!({"messages": messages}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
|
|
||||||
};
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
|
||||||
eprintln!("{}", err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*response.status_mut() = StatusCode::BAD_REQUEST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn recent_messages(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
pub async fn recent_messages(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||||
let limit = qs_param!(params, "limit", i32);
|
let limit = qs_param!(params, "limit", i32);
|
||||||
let channel_id = qs_param!(params, "channel_id", u64);
|
let channel_id = qs_param!(params, "channel_id", u64);
|
||||||
|
@ -12,7 +12,6 @@ pub const CHANNELS_DELETE: Rstr = "/channels/delete"; // requires @name perms:
|
|||||||
|
|
||||||
pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content perms::MESSAGE_SEND
|
pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content perms::MESSAGE_SEND
|
||||||
pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @channel(id) @start-time @end-time
|
pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @channel(id) @start-time @end-time
|
||||||
pub const MESSAGE_FROM_ID: Rstr = "/message/from_id"; // requires @channel_id requires @start(id) @<optional>limit(1..1000)
|
|
||||||
pub const MESSAGE_LAST_N: Rstr = "/message/recent"; // requires @channel_id requires @limit(1..100)
|
pub const MESSAGE_LAST_N: Rstr = "/message/recent"; // requires @channel_id requires @limit(1..100)
|
||||||
|
|
||||||
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none
|
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none
|
||||||
|
Loading…
Reference in New Issue
Block a user