matrix_sdk_base: Use test_json values for tests in base

master
Devin R 2020-06-21 14:22:28 -04:00
parent 4a7b3a103c
commit 8e8ac8c5ac
4 changed files with 58 additions and 18 deletions

View File

@ -1768,7 +1768,7 @@ mod test {
BaseClient, Session,
};
use matrix_sdk_common_macros::async_trait;
use matrix_sdk_test::{async_test, EventBuilder, EventsFile};
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
use serde_json::json;
use std::convert::TryFrom;
@ -1959,10 +1959,8 @@ mod test {
client.event_emitter = Arc::new(RwLock::new(Some(Box::new(emitter))));
// This is needed other wise the `EventBuilder` goes through a de/ser cycle and the `prev_content` is lost.
let event = serde_json::from_str::<serde_json::Value>(include_str!(
"../../test_data/events/member.json"
))
.unwrap();
let event: &serde_json::Value = &test_json::MEMBER;
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
let joined_room = serde_json::json!({
"summary": {},
@ -2054,10 +2052,7 @@ mod test {
client.event_emitter = Arc::new(RwLock::new(Some(Box::new(emitter))));
// This is needed other wise the `EventBuilder` goes through a de/ser cycle and the `prev_content` is lost.
let event = serde_json::from_str::<serde_json::Value>(include_str!(
"../../test_data/events/message_edit.json"
))
.unwrap();
let event: &serde_json::Value = &test_json::MESSAGE_EDIT;
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
let joined_room = serde_json::json!({
@ -2149,10 +2144,7 @@ mod test {
client.event_emitter = Arc::new(RwLock::new(Some(Box::new(emitter))));
// This is needed other wise the `EventBuilder` goes through a de/ser cycle and the `prev_content` is lost.
let event = serde_json::from_str::<serde_json::Value>(include_str!(
"../../test_data/events/reaction.json"
))
.unwrap();
let event: &serde_json::Value = &test_json::REACTION;
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
let joined_room = serde_json::json!({

View File

@ -146,6 +146,8 @@ mod test {
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
use matrix_sdk_test::test_json;
use crate::events::{collections::all::RoomEvent, EventJson};
use crate::identifiers::{RoomId, UserId};
use crate::Room;
@ -157,8 +159,8 @@ mod test {
let mut room = Room::new(&id, &user);
let json = std::fs::read_to_string("../test_data/events/message_text.json").unwrap();
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
let event = serde_json::from_value::<EventJson<RoomEvent>>(json.clone()).unwrap();
let mut msgs = MessageQueue::new();
let message = if let RoomEvent::RoomMessage(msg) = event.deserialize().unwrap() {
@ -207,8 +209,8 @@ mod test {
let mut room = Room::new(&id, &user);
let json = std::fs::read_to_string("../test_data/events/message_text.json").unwrap();
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
let json: &serde_json::Value = &test_json::MESSAGE_TEXT;
let event = serde_json::from_value::<EventJson<RoomEvent>>(json.clone()).unwrap();
let mut msgs = MessageQueue::new();
let message = if let RoomEvent::RoomMessage(msg) = event.deserialize().unwrap() {

View File

@ -120,6 +120,30 @@ lazy_static! {
});
}
lazy_static! {
pub static ref MESSAGE_EDIT: JsonValue = json!({
"content": {
"body": " * edited message",
"m.new_content": {
"body": "edited message",
"msgtype": "m.text"
},
"m.relates_to": {
"event_id": "some event id",
"rel_type": "m.replace"
},
"msgtype": "m.text"
},
"event_id": "edit event id",
"origin_server_ts": 159026265,
"sender": "@alice:matrix.org",
"type": "m.room.message",
"unsigned": {
"age": 85
}
});
}
lazy_static! {
pub static ref MESSAGE_EMOTE: JsonValue = json!({
"content": {
@ -238,6 +262,25 @@ lazy_static! {
});
}
lazy_static! {
pub static ref REACTION: JsonValue = json!({
"content": {
"m.relates_to": {
"event_id": "$MDitXXXXXXuBlpP7S6c6XXXXXXXC2HqZ3peV1NrV4PKA",
"key": "👍",
"rel_type": "m.annotation"
}
},
"event_id": "$QZn9xEXXXXXfd2tAGFH-XXgsffZlVMobk47Tl5Lpdtg",
"origin_server_ts": 159027581,
"sender": "@devinr528:matrix.org",
"type": "m.reaction",
"unsigned": {
"age": 85
}
});
}
lazy_static! {
pub static ref REDACTED_INVALID: JsonValue = json!({
"content": {},

View File

@ -7,5 +7,8 @@
pub mod events;
pub mod sync;
pub use events::{ALIAS, ALIASES, MEMBER, NAME, POWER_LEVELS, PRESENCE, TYPING};
pub use events::{
ALIAS, ALIASES, MEMBER, MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, REACTION,
TYPING,
};
pub use sync::{DEFAULT_SYNC, INVITE_SYNC, LEAVE_SYNC, MORE_SYNC, SYNC};