Bartosz Sypytkowski fd5299a13d
move to latest appflowy collab version (#5894)
* chore: move to latest appflowy collab version

* chore: filter mapping

* chore: remove mutex folder

* chore: cleanup borrow checker issues

* chore: fixed flowy user crate compilation errors

* chore: removed parking lot crate

* chore: adjusting non locking approach

* chore: remove with folder method

* chore: fix folder manager

* chore: fixed workspace database compilation errors

* chore: initialize database plugins

* chore: fix locks in flowy core

* chore: remove supabase

* chore: async traits

* chore: add mutexes in dart ffi

* chore: post rebase fixes

* chore: remove supabase dart code

* chore: fix deadlock

* chore: fix page_id is empty

* chore: use data source to init collab

* chore: fix user awareness test

* chore: fix database deadlock

* fix: initialize user awareness

* chore: fix open workspace test

* chore: fix import csv

* chore: fix update row meta deadlock

* chore: fix document size test

* fix: timestamp set/get type convert

* fix: calculation

* chore: revert Arc to Rc

* chore: attach plugin to database and database row

* chore: async get row

* chore: clippy

* chore: fix tauri build

* chore: clippy

* fix: duplicate view deadlock

* chore: fmt

* chore: tauri build

---------

Co-authored-by: nathan <nathan@appflowy.io>
2024-08-18 11:16:42 +08:00

121 lines
2.7 KiB
Rust

use crate::EventIntegrationTest;
use flowy_user::errors::{internal_error, FlowyError};
use lib_dispatch::prelude::{
AFPluginDispatcher, AFPluginEventResponse, AFPluginFromBytes, AFPluginRequest, ToBytes, *,
};
use std::rc::Rc;
use std::{
convert::TryFrom,
fmt::{Debug, Display},
hash::Hash,
};
#[derive(Clone)]
pub struct EventBuilder {
context: TestContext,
}
impl EventBuilder {
pub fn new(sdk: EventIntegrationTest) -> Self {
Self {
context: TestContext::new(sdk),
}
}
pub fn payload<P>(mut self, payload: P) -> Self
where
P: ToBytes,
{
match payload.into_bytes() {
Ok(bytes) => {
let module_request = self.get_request();
self.context.request = Some(module_request.payload(bytes))
},
Err(e) => {
tracing::error!("Set payload failed: {:?}", e);
},
}
self
}
pub fn event<Event>(mut self, event: Event) -> Self
where
Event: Eq + Hash + Debug + Clone + Display,
{
self.context.request = Some(AFPluginRequest::new(event));
self
}
pub async fn async_send(mut self) -> Self {
let request = self.get_request();
let resp = AFPluginDispatcher::async_send(self.dispatch().as_ref(), request).await;
self.context.response = Some(resp);
self
}
pub fn parse<R>(self) -> R
where
R: AFPluginFromBytes,
{
let response = self.get_response();
match response.clone().parse::<R, FlowyError>() {
Ok(Ok(data)) => data,
Ok(Err(e)) => {
panic!("Parser {:?} failed: {:?}", std::any::type_name::<R>(), e)
},
Err(e) => {
panic!("Parser {:?} failed: {:?}", std::any::type_name::<R>(), e)
},
}
}
pub fn try_parse<R>(self) -> Result<R, FlowyError>
where
R: AFPluginFromBytes,
{
let response = self.get_response();
response.parse::<R, FlowyError>().map_err(internal_error)?
}
pub fn error(self) -> Option<FlowyError> {
let response = self.get_response();
<AFPluginData<FlowyError>>::try_from(response.payload)
.ok()
.map(|data| data.into_inner())
}
fn dispatch(&self) -> Rc<AFPluginDispatcher> {
self.context.sdk.dispatcher()
}
fn get_response(&self) -> AFPluginEventResponse {
self
.context
.response
.as_ref()
.expect("must call sync_send/async_send first")
.clone()
}
fn get_request(&mut self) -> AFPluginRequest {
self.context.request.take().expect("must call event first")
}
}
#[derive(Clone)]
pub struct TestContext {
pub sdk: EventIntegrationTest,
request: Option<AFPluginRequest>,
response: Option<AFPluginEventResponse>,
}
impl TestContext {
pub fn new(sdk: EventIntegrationTest) -> Self {
Self {
sdk,
request: None,
response: None,
}
}
}