2021-04-16 10:45:21 +00:00
|
|
|
use std::{collections::HashMap, panic};
|
2020-04-06 11:12:02 +00:00
|
|
|
|
2020-05-08 07:49:55 +00:00
|
|
|
use http::Response;
|
2020-07-30 23:22:48 +00:00
|
|
|
use matrix_sdk_common::{
|
|
|
|
api::r0::sync::sync_events::Response as SyncResponse,
|
|
|
|
events::{
|
2021-05-12 14:21:44 +00:00
|
|
|
presence::PresenceEvent, AnyGlobalAccountDataEvent, AnySyncEphemeralRoomEvent,
|
|
|
|
AnySyncRoomEvent, AnySyncStateEvent,
|
2020-07-30 23:22:48 +00:00
|
|
|
},
|
2020-08-04 22:56:26 +00:00
|
|
|
identifiers::{room_id, RoomId},
|
2021-04-16 10:45:21 +00:00
|
|
|
IncomingResponse,
|
2020-04-07 00:59:44 +00:00
|
|
|
};
|
2020-05-08 14:12:21 +00:00
|
|
|
pub use matrix_sdk_test_macros::async_test;
|
2021-05-12 10:56:29 +00:00
|
|
|
use serde_json::Value as JsonValue;
|
2020-05-08 14:12:21 +00:00
|
|
|
|
2020-06-21 18:01:04 +00:00
|
|
|
pub mod test_json;
|
|
|
|
|
2020-06-20 21:18:20 +00:00
|
|
|
/// Embedded event files
|
2020-05-08 14:12:21 +00:00
|
|
|
#[derive(Debug)]
|
2020-06-21 18:01:04 +00:00
|
|
|
pub enum EventsJson {
|
2020-05-08 14:12:21 +00:00
|
|
|
Alias,
|
|
|
|
Aliases,
|
|
|
|
Create,
|
|
|
|
FullyRead,
|
|
|
|
HistoryVisibility,
|
|
|
|
JoinRules,
|
|
|
|
Member,
|
2020-07-01 12:50:42 +00:00
|
|
|
MemberNameChange,
|
2020-05-08 14:12:21 +00:00
|
|
|
MessageEmote,
|
|
|
|
MessageNotice,
|
|
|
|
MessageText,
|
|
|
|
Name,
|
|
|
|
PowerLevels,
|
|
|
|
Presence,
|
|
|
|
RedactedInvalid,
|
|
|
|
RedactedState,
|
|
|
|
Redacted,
|
|
|
|
Redaction,
|
|
|
|
RoomAvatar,
|
|
|
|
Tag,
|
|
|
|
Topic,
|
|
|
|
Typing,
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:09:10 +00:00
|
|
|
/// The `EventBuilder` struct can be used to easily generate valid sync responses for testing.
|
|
|
|
/// These can be then fed into either `Client` or `Room`.
|
|
|
|
///
|
|
|
|
/// It supports generated a number of canned events, such as a member entering a room, his power
|
|
|
|
/// level and display name changing and similar. It also supports insertion of custom events in the
|
|
|
|
/// form of `EventsJson` values.
|
|
|
|
///
|
|
|
|
/// **Important** You *must* use the *same* builder when sending multiple sync responses to
|
|
|
|
/// a single client. Otherwise, the subsequent responses will be *ignored* by the client because
|
|
|
|
/// the `next_batch` sync token will not be rotated properly.
|
|
|
|
///
|
|
|
|
/// # Example usage
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use matrix_sdk_test::{EventBuilder, EventsJson};
|
|
|
|
///
|
|
|
|
/// let mut builder = EventBuilder::new();
|
|
|
|
///
|
|
|
|
/// // response1 now contains events that add an example member to the room and change their power
|
|
|
|
/// // level
|
|
|
|
/// let response1 = builder
|
2020-07-14 09:06:31 +00:00
|
|
|
/// .add_room_event(EventsJson::Member)
|
|
|
|
/// .add_room_event(EventsJson::PowerLevels)
|
2020-06-30 15:09:10 +00:00
|
|
|
/// .build_sync_response();
|
|
|
|
///
|
|
|
|
/// // response2 is now empty (nothing changed)
|
|
|
|
/// let response2 = builder.build_sync_response();
|
|
|
|
///
|
|
|
|
/// // response3 contains a display name change for member example
|
|
|
|
/// let response3 = builder
|
2020-07-14 09:06:31 +00:00
|
|
|
/// .add_room_event(EventsJson::MemberNameChange)
|
2020-06-30 15:09:10 +00:00
|
|
|
/// .build_sync_response();
|
|
|
|
/// ```
|
|
|
|
|
2020-04-07 00:59:44 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct EventBuilder {
|
|
|
|
/// The events that determine the state of a `Room`.
|
2020-07-18 12:37:43 +00:00
|
|
|
joined_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
|
2020-05-13 13:57:09 +00:00
|
|
|
/// The events that determine the state of a `Room`.
|
2020-07-18 12:37:43 +00:00
|
|
|
invited_room_events: HashMap<RoomId, Vec<AnySyncStateEvent>>,
|
2020-05-13 13:57:09 +00:00
|
|
|
/// The events that determine the state of a `Room`.
|
2020-07-18 12:37:43 +00:00
|
|
|
left_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
|
2020-04-07 00:59:44 +00:00
|
|
|
/// The presence events that determine the presence state of a `RoomMember`.
|
|
|
|
presence_events: Vec<PresenceEvent>,
|
|
|
|
/// The state events that determine the state of a `Room`.
|
2020-07-18 12:37:43 +00:00
|
|
|
state_events: Vec<AnySyncStateEvent>,
|
2020-04-07 12:55:42 +00:00
|
|
|
/// The ephemeral room events that determine the state of a `Room`.
|
2020-07-18 12:37:43 +00:00
|
|
|
ephemeral: Vec<AnySyncEphemeralRoomEvent>,
|
2020-04-07 12:55:42 +00:00
|
|
|
/// The account data events that determine the state of a `Room`.
|
2021-05-12 14:21:44 +00:00
|
|
|
account_data: Vec<AnyGlobalAccountDataEvent>,
|
2020-06-09 13:10:41 +00:00
|
|
|
/// Internal counter to enable the `prev_batch` and `next_batch` of each sync response to vary.
|
|
|
|
batch_counter: i64,
|
2020-04-07 12:55:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 00:59:44 +00:00
|
|
|
impl EventBuilder {
|
2020-06-09 13:10:41 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
let builder: EventBuilder = Default::default();
|
|
|
|
builder
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:55:42 +00:00
|
|
|
/// Add an event to the room events `Vec`.
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_ephemeral(&mut self, json: EventsJson) -> &mut Self {
|
2020-06-21 18:01:04 +00:00
|
|
|
let val: &JsonValue = match json {
|
|
|
|
EventsJson::Typing => &test_json::TYPING,
|
|
|
|
_ => panic!("unknown ephemeral event {:?}", json),
|
2020-05-08 14:12:21 +00:00
|
|
|
};
|
|
|
|
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncEphemeralRoomEvent>(val.clone()).unwrap();
|
2020-06-25 00:30:53 +00:00
|
|
|
self.ephemeral.push(event);
|
2020-04-07 00:59:44 +00:00
|
|
|
self
|
2020-04-06 11:12:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 00:59:44 +00:00
|
|
|
/// Add an event to the room events `Vec`.
|
2020-05-08 14:12:21 +00:00
|
|
|
#[allow(clippy::match_single_binding, unused)]
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_account(&mut self, json: EventsJson) -> &mut Self {
|
2020-06-21 18:01:04 +00:00
|
|
|
let val: &JsonValue = match json {
|
|
|
|
_ => panic!("unknown account event {:?}", json),
|
2020-05-08 14:12:21 +00:00
|
|
|
};
|
|
|
|
|
2021-05-12 14:21:44 +00:00
|
|
|
let event = serde_json::from_value::<AnyGlobalAccountDataEvent>(val.clone()).unwrap();
|
2020-06-25 00:30:53 +00:00
|
|
|
self.account_data.push(event);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an event to the room events `Vec`.
|
|
|
|
pub fn add_room_event(&mut self, json: EventsJson) -> &mut Self {
|
|
|
|
let val: &JsonValue = match json {
|
|
|
|
EventsJson::Member => &test_json::MEMBER,
|
2020-07-01 12:50:42 +00:00
|
|
|
EventsJson::MemberNameChange => &test_json::MEMBER_NAME_CHANGE,
|
2020-06-25 00:30:53 +00:00
|
|
|
EventsJson::PowerLevels => &test_json::POWER_LEVELS,
|
|
|
|
_ => panic!("unknown room event json {:?}", json),
|
|
|
|
};
|
|
|
|
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
|
2020-06-25 00:30:53 +00:00
|
|
|
|
2020-08-04 22:56:26 +00:00
|
|
|
self.add_joined_event(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"), event);
|
2020-04-07 00:59:44 +00:00
|
|
|
self
|
|
|
|
}
|
2020-04-06 11:12:02 +00:00
|
|
|
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_custom_joined_event(
|
|
|
|
&mut self,
|
2020-05-14 08:57:21 +00:00
|
|
|
room_id: &RoomId,
|
2020-05-13 13:57:09 +00:00
|
|
|
event: serde_json::Value,
|
2020-06-25 00:30:53 +00:00
|
|
|
) -> &mut Self {
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
|
2020-06-25 00:30:53 +00:00
|
|
|
self.add_joined_event(room_id, event);
|
2020-05-13 13:57:09 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-07-18 12:37:43 +00:00
|
|
|
fn add_joined_event(&mut self, room_id: &RoomId, event: AnySyncRoomEvent) {
|
2020-05-13 13:57:09 +00:00
|
|
|
self.joined_room_events
|
|
|
|
.entry(room_id.clone())
|
|
|
|
.or_insert_with(Vec::new)
|
|
|
|
.push(event);
|
|
|
|
}
|
|
|
|
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_custom_invited_event(
|
|
|
|
&mut self,
|
|
|
|
room_id: &RoomId,
|
|
|
|
event: serde_json::Value,
|
|
|
|
) -> &mut Self {
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncStateEvent>(event).unwrap();
|
2020-05-13 14:25:42 +00:00
|
|
|
self.invited_room_events
|
|
|
|
.entry(room_id.clone())
|
|
|
|
.or_insert_with(Vec::new)
|
2020-06-20 21:18:20 +00:00
|
|
|
.push(event);
|
2020-05-13 13:57:09 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_custom_left_event(
|
|
|
|
&mut self,
|
2020-05-13 14:25:42 +00:00
|
|
|
room_id: &RoomId,
|
2020-05-13 13:57:09 +00:00
|
|
|
event: serde_json::Value,
|
2020-06-25 00:30:53 +00:00
|
|
|
) -> &mut Self {
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
|
2020-05-13 14:25:42 +00:00
|
|
|
self.left_room_events
|
|
|
|
.entry(room_id.clone())
|
|
|
|
.or_insert_with(Vec::new)
|
2020-06-25 00:30:53 +00:00
|
|
|
.push(event);
|
2020-04-07 00:59:44 +00:00
|
|
|
self
|
|
|
|
}
|
2020-04-06 11:12:02 +00:00
|
|
|
|
2020-04-07 00:59:44 +00:00
|
|
|
/// Add a state event to the state events `Vec`.
|
2020-06-25 00:30:53 +00:00
|
|
|
pub fn add_state_event(&mut self, json: EventsJson) -> &mut Self {
|
2020-06-21 18:01:04 +00:00
|
|
|
let val: &JsonValue = match json {
|
|
|
|
EventsJson::Alias => &test_json::ALIAS,
|
|
|
|
EventsJson::Aliases => &test_json::ALIASES,
|
|
|
|
EventsJson::Name => &test_json::NAME,
|
2020-06-25 00:30:53 +00:00
|
|
|
EventsJson::Member => &test_json::MEMBER,
|
|
|
|
EventsJson::PowerLevels => &test_json::POWER_LEVELS,
|
2020-06-21 18:01:04 +00:00
|
|
|
_ => panic!("unknown state event {:?}", json),
|
2020-05-08 14:12:21 +00:00
|
|
|
};
|
|
|
|
|
2020-07-18 12:37:43 +00:00
|
|
|
let event = serde_json::from_value::<AnySyncStateEvent>(val.clone()).unwrap();
|
2020-06-25 00:30:53 +00:00
|
|
|
self.state_events.push(event);
|
2020-04-07 00:59:44 +00:00
|
|
|
self
|
|
|
|
}
|
2020-04-06 11:12:02 +00:00
|
|
|
|
2020-05-08 14:12:21 +00:00
|
|
|
/// Add an presence event to the presence events `Vec`.
|
2020-06-24 08:42:58 +00:00
|
|
|
pub fn add_presence_event(&mut self, json: EventsJson) -> &mut Self {
|
2020-06-21 18:01:04 +00:00
|
|
|
let val: &JsonValue = match json {
|
|
|
|
EventsJson::Presence => &test_json::PRESENCE,
|
|
|
|
_ => panic!("unknown presence event {:?}", json),
|
2020-05-08 14:12:21 +00:00
|
|
|
};
|
|
|
|
|
2020-06-25 00:30:53 +00:00
|
|
|
let event = serde_json::from_value::<PresenceEvent>(val.clone()).unwrap();
|
2020-04-07 00:59:44 +00:00
|
|
|
self.presence_events.push(event);
|
|
|
|
self
|
|
|
|
}
|
2020-04-06 11:12:02 +00:00
|
|
|
|
2021-04-21 14:10:37 +00:00
|
|
|
/// Builds a sync response as a JSON Value containing the events we queued
|
|
|
|
/// so far.
|
|
|
|
///
|
|
|
|
/// The next response returned by `build_sync_response` will then be empty
|
|
|
|
/// if no further events were queued.
|
|
|
|
///
|
|
|
|
/// This method is raw JSON equivalent to
|
|
|
|
/// [build_sync_response()](#method.build_sync_response), use
|
|
|
|
/// [build_sync_response()](#method.build_sync_response) if you need a typed
|
|
|
|
/// response.
|
|
|
|
pub fn build_json_sync_response(&mut self) -> JsonValue {
|
2020-08-04 22:56:26 +00:00
|
|
|
let main_room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
2020-05-13 13:57:09 +00:00
|
|
|
|
2020-06-09 13:10:41 +00:00
|
|
|
// First time building a sync response, so initialize the `prev_batch` to a default one.
|
|
|
|
let prev_batch = self.generate_sync_token();
|
|
|
|
self.batch_counter += 1;
|
|
|
|
let next_batch = self.generate_sync_token();
|
|
|
|
|
2020-05-13 13:57:09 +00:00
|
|
|
// TODO generalize this.
|
|
|
|
let joined_room = serde_json::json!({
|
|
|
|
"summary": {},
|
|
|
|
"account_data": {
|
|
|
|
"events": self.account_data
|
|
|
|
},
|
|
|
|
"ephemeral": {
|
|
|
|
"events": self.ephemeral
|
|
|
|
},
|
|
|
|
"state": {
|
|
|
|
"events": self.state_events
|
|
|
|
},
|
|
|
|
"timeline": {
|
|
|
|
"events": self.joined_room_events.remove(&main_room_id).unwrap_or_default(),
|
|
|
|
"limited": true,
|
2020-06-09 13:10:41 +00:00
|
|
|
"prev_batch": prev_batch
|
2020-05-13 13:57:09 +00:00
|
|
|
},
|
|
|
|
"unread_notifications": {
|
|
|
|
"highlight_count": 0,
|
|
|
|
"notification_count": 11
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-13 14:25:42 +00:00
|
|
|
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
2020-05-13 13:57:09 +00:00
|
|
|
|
2020-05-13 14:25:42 +00:00
|
|
|
joined_rooms.insert(main_room_id, joined_room);
|
2020-05-13 13:57:09 +00:00
|
|
|
|
|
|
|
for (room_id, events) in self.joined_room_events.drain() {
|
|
|
|
let joined_room = serde_json::json!({
|
|
|
|
"summary": {},
|
|
|
|
"account_data": {
|
|
|
|
"events": [],
|
|
|
|
},
|
|
|
|
"ephemeral": {
|
|
|
|
"events": [],
|
|
|
|
},
|
|
|
|
"state": {
|
|
|
|
"events": [],
|
|
|
|
},
|
|
|
|
"timeline": {
|
|
|
|
"events": events,
|
|
|
|
"limited": true,
|
2020-06-09 13:10:41 +00:00
|
|
|
"prev_batch": prev_batch
|
2020-05-13 13:57:09 +00:00
|
|
|
},
|
|
|
|
"unread_notifications": {
|
|
|
|
"highlight_count": 0,
|
|
|
|
"notification_count": 11
|
|
|
|
}
|
|
|
|
});
|
2020-05-13 14:25:42 +00:00
|
|
|
joined_rooms.insert(room_id, joined_room);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut left_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
|
|
|
|
|
|
|
for (room_id, events) in self.left_room_events.drain() {
|
|
|
|
let room = serde_json::json!({
|
|
|
|
"state": {
|
|
|
|
"events": [],
|
|
|
|
},
|
|
|
|
"timeline": {
|
|
|
|
"events": events,
|
|
|
|
"limited": false,
|
2020-06-09 13:10:41 +00:00
|
|
|
"prev_batch": prev_batch
|
2020-05-13 14:25:42 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
left_rooms.insert(room_id, room);
|
2020-05-13 13:57:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 08:57:21 +00:00
|
|
|
let mut invited_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
|
|
|
|
|
|
|
for (room_id, events) in self.invited_room_events.drain() {
|
|
|
|
let room = serde_json::json!({
|
|
|
|
"invite_state": {
|
|
|
|
"events": events,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
invited_rooms.insert(room_id, room);
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:55:42 +00:00
|
|
|
let body = serde_json::json! {
|
|
|
|
{
|
|
|
|
"device_one_time_keys_count": {},
|
2020-06-09 13:10:41 +00:00
|
|
|
"next_batch": next_batch,
|
2020-04-07 12:55:42 +00:00
|
|
|
"device_lists": {
|
|
|
|
"changed": [],
|
|
|
|
"left": []
|
|
|
|
},
|
|
|
|
"rooms": {
|
2020-05-14 08:57:21 +00:00
|
|
|
"invite": invited_rooms,
|
2020-05-13 14:25:42 +00:00
|
|
|
"join": joined_rooms,
|
|
|
|
"leave": left_rooms,
|
2020-04-07 12:55:42 +00:00
|
|
|
},
|
|
|
|
"to_device": {
|
|
|
|
"events": []
|
|
|
|
},
|
|
|
|
"presence": {
|
|
|
|
"events": []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-04-21 14:10:37 +00:00
|
|
|
|
|
|
|
// Clear state so that the next sync response will be empty if nothing
|
|
|
|
// was added.
|
|
|
|
self.clear();
|
|
|
|
|
|
|
|
body
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds a `SyncResponse` containing the events we queued so far.
|
|
|
|
///
|
|
|
|
/// The next response returned by `build_sync_response` will then be empty
|
|
|
|
/// if no further events were queued.
|
|
|
|
///
|
|
|
|
/// This method is high level and typed equivalent to
|
|
|
|
/// [build_json_sync_response()](#method.build_json_sync_response), use
|
|
|
|
/// [build_json_sync_response()](#method.build_json_sync_response) if you
|
|
|
|
/// need an untyped response.
|
|
|
|
pub fn build_sync_response(&mut self) -> SyncResponse {
|
|
|
|
let body = self.build_json_sync_response();
|
|
|
|
|
2020-05-07 14:22:18 +00:00
|
|
|
let response = Response::builder()
|
|
|
|
.body(serde_json::to_vec(&body).unwrap())
|
|
|
|
.unwrap();
|
2020-06-30 15:09:10 +00:00
|
|
|
|
2021-04-16 10:45:21 +00:00
|
|
|
SyncResponse::try_from_http_response(response).unwrap()
|
2020-04-06 13:11:38 +00:00
|
|
|
}
|
2020-06-09 13:10:41 +00:00
|
|
|
|
|
|
|
fn generate_sync_token(&self) -> String {
|
|
|
|
format!("t392-516_47314_0_7_1_1_1_11444_{}", self.batch_counter)
|
|
|
|
}
|
2020-06-30 15:09:10 +00:00
|
|
|
|
|
|
|
pub fn clear(&mut self) {
|
|
|
|
self.account_data.clear();
|
|
|
|
self.ephemeral.clear();
|
|
|
|
self.invited_room_events.clear();
|
|
|
|
self.joined_room_events.clear();
|
|
|
|
self.left_room_events.clear();
|
|
|
|
self.presence_events.clear();
|
|
|
|
self.state_events.clear();
|
|
|
|
}
|
2020-04-06 11:12:02 +00:00
|
|
|
}
|
2020-05-08 14:12:21 +00:00
|
|
|
|
|
|
|
/// Embedded sync reponse files
|
|
|
|
pub enum SyncResponseFile {
|
2020-06-06 21:00:29 +00:00
|
|
|
All,
|
2020-05-08 14:12:21 +00:00
|
|
|
Default,
|
|
|
|
DefaultWithSummary,
|
|
|
|
Invite,
|
|
|
|
Leave,
|
2020-12-15 10:15:42 +00:00
|
|
|
Voip,
|
2020-05-08 14:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get specific API responses for testing
|
|
|
|
pub fn sync_response(kind: SyncResponseFile) -> SyncResponse {
|
2020-06-21 18:01:04 +00:00
|
|
|
let data: &JsonValue = match kind {
|
|
|
|
SyncResponseFile::All => &test_json::MORE_SYNC,
|
|
|
|
SyncResponseFile::Default => &test_json::SYNC,
|
2020-06-22 19:40:51 +00:00
|
|
|
SyncResponseFile::DefaultWithSummary => &test_json::DEFAULT_SYNC_SUMMARY,
|
2020-06-21 18:01:04 +00:00
|
|
|
SyncResponseFile::Invite => &test_json::INVITE_SYNC,
|
|
|
|
SyncResponseFile::Leave => &test_json::LEAVE_SYNC,
|
2020-12-15 10:15:42 +00:00
|
|
|
SyncResponseFile::Voip => &test_json::VOIP_SYNC,
|
2020-05-08 14:12:21 +00:00
|
|
|
};
|
|
|
|
|
2020-06-21 18:01:04 +00:00
|
|
|
let response = Response::builder()
|
|
|
|
.body(data.to_string().as_bytes().to_vec())
|
|
|
|
.unwrap();
|
2021-04-16 10:45:21 +00:00
|
|
|
SyncResponse::try_from_http_response(response).unwrap()
|
2020-05-08 14:12:21 +00:00
|
|
|
}
|
2021-01-24 13:29:59 +00:00
|
|
|
|
|
|
|
pub fn response_from_file(json: &serde_json::Value) -> Response<Vec<u8>> {
|
|
|
|
Response::builder()
|
|
|
|
.status(200)
|
|
|
|
.body(json.to_string().as_bytes().to_vec())
|
|
|
|
.unwrap()
|
|
|
|
}
|