write tests for request types
This commit is contained in:
parent
f46404eb7e
commit
724d7ef154
|
@ -1,9 +1,35 @@
|
|||
use std::sync::atomic::AtomicU32;
|
||||
use fcpv2::types::SSK;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_json::Result;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
|
||||
type Id = crate::db::types::Id;
|
||||
use crate::db::types::Id;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(tag = "type")]
|
||||
enum Request {
|
||||
StartApp,
|
||||
StopApp,
|
||||
LoadUsers,
|
||||
#[serde(rename_all = "camelCase")]
|
||||
SendMessage {
|
||||
user_id: Id,
|
||||
message: String,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
LoadMessages {
|
||||
user_id: Id,
|
||||
count: u32,
|
||||
start_index: u32,
|
||||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
AddUser {
|
||||
name: String,
|
||||
sign_key: String,
|
||||
insert_key: String,
|
||||
}, // CreateInstance TODO v0.3
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -86,18 +112,55 @@ pub struct AddUserReq {
|
|||
|
||||
#[test]
|
||||
fn request_StoppApp_are_correct() {
|
||||
let json: &str = "{'reqType':'StopApp'}";
|
||||
//log::info!("{} and {}", json, tjsn);
|
||||
//assert_eq!(jsoned, StopAppReq{req_type: StopApp});
|
||||
//assert_eq!(json,tjsn);
|
||||
let json = "{\"type\":\"stopApp\"}";
|
||||
let parsed: Request = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(Request::StopApp, parsed);
|
||||
}
|
||||
#[test]
|
||||
fn request_StartApp_are_correct() {}
|
||||
fn request_StartApp_are_correct() {
|
||||
let json = "{\"type\":\"startApp\"}";
|
||||
let parsed: Request = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(Request::StartApp, parsed);
|
||||
}
|
||||
#[test]
|
||||
fn request_LoadUsers_are_correct() {}
|
||||
fn request_LoadUsers_are_correct() {
|
||||
let json = "{\"type\":\"loadUsers\"}";
|
||||
let parsed: Request = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(Request::LoadUsers, parsed);
|
||||
}
|
||||
#[test]
|
||||
fn request_SendMessage_are_correct() {}
|
||||
fn request_SendMessage_are_correct() {
|
||||
let id = uuid::Uuid::new_v4();
|
||||
let json = "{\"type\":\"sendMessage\",\"userId\":\"".to_owned()
|
||||
+ &id.to_string()[..]
|
||||
+ "\",\"message\":\"hey jon\"}";
|
||||
let parsed: Request = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(Request::SendMessage{user_id: Id(id), message: "hey jon".to_string()}, parsed);
|
||||
}
|
||||
#[test]
|
||||
fn request_LoadMessages_are_correct() {}
|
||||
fn request_LoadMessages_are_correct() {
|
||||
let id = uuid::Uuid::new_v4();
|
||||
let json = "{\"type\":\"loadMessages\",\"userId\":\"".to_owned()
|
||||
+ &id.to_string()[..]
|
||||
+ "\",\"count\":10,\"startIndex\":343}";
|
||||
let parsed: Request = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(
|
||||
parsed,
|
||||
Request::LoadMessages {
|
||||
user_id: Id(id),
|
||||
count: 10,
|
||||
start_index: 343
|
||||
}
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn request_AddUser_are_correct() {}
|
||||
fn request_AddUser_are_correct() {
|
||||
let json = "{\"type\":\"addUser\",\"name\":\"john\",\"signKey\":\"USK@bxouok43eKpx3g4WmURjviGispWzYxeByiWRsmYOy5k,Y9j~lPDUoNlSTbZfDNaUajfePBrW~KM6uvHyOGWeA7Q,AQECAAE\",\"insertKey\":\"USK@bxouok43eKpx3g4WmURjviGispWzYxeByiWRsmYOy5k,Y9j~lPDUoNlSTbZfDNaUajfePBrW~KM6uvHyOGWeA7Q,AQECAAE\"}";
|
||||
let parsed: Request = serde_json::from_str(json).unwrap();
|
||||
assert_eq!(parsed, Request::AddUser{
|
||||
name: "john".to_string(),
|
||||
sign_key: "USK@bxouok43eKpx3g4WmURjviGispWzYxeByiWRsmYOy5k,Y9j~lPDUoNlSTbZfDNaUajfePBrW~KM6uvHyOGWeA7Q,AQECAAE".to_string(),
|
||||
insert_key: "USK@bxouok43eKpx3g4WmURjviGispWzYxeByiWRsmYOy5k,Y9j~lPDUoNlSTbZfDNaUajfePBrW~KM6uvHyOGWeA7Q,AQECAAE".to_string(),
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use crate::chat::types::{PackedMessage, SP};
|
||||
use rusqlite;
|
||||
|
||||
use crate::chat::types::{PackedMessage, SP}; use rusqlite;
|
||||
use super::{
|
||||
handlers,
|
||||
request::*,
|
||||
|
|
|
@ -16,7 +16,7 @@ pub type Time = chrono::DateTime<chrono::Local>;
|
|||
|
||||
pub type SignKey = String;
|
||||
pub type InsertKey = SSK;
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub struct Id(pub uuid::Uuid);
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
Loading…
Reference in a new issue