mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix test compile errors
This commit is contained in:
parent
b8332d28c1
commit
6b7557314c
@ -4,4 +4,4 @@ pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(8);
|
||||
pub const PING_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
pub const MAX_PAYLOAD_SIZE: usize = 262_144; // max payload size is 256k
|
||||
|
||||
pub const IGNORE_ROUTES: [&str; 2] = ["/api/register", "/api/auth/"];
|
||||
pub const IGNORE_ROUTES: [&str; 2] = ["/api/register", "/api/auth"];
|
||||
|
@ -2,8 +2,6 @@ use crate::user_service::{LoggedUser, AUTHORIZED_USERS};
|
||||
use actix_service::{Service, Transform};
|
||||
use actix_web::{
|
||||
dev::{ServiceRequest, ServiceResponse},
|
||||
http::{HeaderName, HeaderValue, Method},
|
||||
web::Data,
|
||||
Error,
|
||||
HttpResponse,
|
||||
ResponseError,
|
||||
@ -11,15 +9,11 @@ use actix_web::{
|
||||
|
||||
use crate::config::IGNORE_ROUTES;
|
||||
use actix_web::{body::AnyBody, dev::MessageBody};
|
||||
use flowy_net::{config::HEADER_TOKEN, errors::ServerError, response::FlowyResponse};
|
||||
use futures::{
|
||||
future::{ok, LocalBoxFuture, Ready},
|
||||
Future,
|
||||
};
|
||||
use flowy_net::{config::HEADER_TOKEN, errors::ServerError};
|
||||
use futures::future::{ok, LocalBoxFuture, Ready};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
error::Error as StdError,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
@ -59,7 +53,7 @@ where
|
||||
self.service.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&self, mut req: ServiceRequest) -> Self::Future {
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
let mut authenticate_pass: bool = false;
|
||||
for ignore_route in IGNORE_ROUTES.iter() {
|
||||
if req.path().starts_with(ignore_route) {
|
||||
|
@ -12,7 +12,7 @@ use crate::{
|
||||
use anyhow::Context;
|
||||
use chrono::Utc;
|
||||
use flowy_net::errors::invalid_params;
|
||||
use flowy_user::entities::parser::UserId;
|
||||
|
||||
use flowy_workspace::{
|
||||
entities::{
|
||||
app::parser::{AppDesc, AppName},
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
|
||||
use crate::user_service::LoggedUser;
|
||||
use actix_web::{
|
||||
web::{Data, Path, Payload},
|
||||
web::{Data, Payload},
|
||||
HttpResponse,
|
||||
};
|
||||
use flowy_net::errors::ServerError;
|
||||
|
@ -10,7 +10,6 @@ use flowy_net::{
|
||||
errors::{invalid_params, ServerError},
|
||||
response::FlowyResponse,
|
||||
};
|
||||
use flowy_user::entities::parser::UserId;
|
||||
|
||||
use crate::{
|
||||
user_service::LoggedUser,
|
||||
|
@ -18,7 +18,7 @@ impl std::convert::Into<AnyBody> for FlowyResponse {
|
||||
fn into(self) -> AnyBody {
|
||||
match serde_json::to_string(&self) {
|
||||
Ok(body) => AnyBody::from(body),
|
||||
Err(err) => AnyBody::Empty,
|
||||
Err(_) => AnyBody::Empty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), User
|
||||
let payload: Bytes = CreateWorkspaceRequest {
|
||||
name: DEFAULT_WORKSPACE_NAME.to_string(),
|
||||
desc: DEFAULT_WORKSPACE_DESC.to_string(),
|
||||
user_id: user_id.to_string(),
|
||||
}
|
||||
.into_bytes()
|
||||
.unwrap();
|
||||
@ -52,21 +51,12 @@ pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), User
|
||||
let request = ModuleRequest::new(CreateWorkspace).payload(payload);
|
||||
let result = EventDispatch::sync_send(request)
|
||||
.parse::<Workspace, DispatchError>()
|
||||
.map_err(|e| {
|
||||
ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed)
|
||||
.error(e)
|
||||
.build()
|
||||
})?;
|
||||
.map_err(|e| ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed).error(e).build())?;
|
||||
|
||||
let workspace = result.map_err(|e| {
|
||||
ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed)
|
||||
.error(e)
|
||||
.build()
|
||||
})?;
|
||||
let workspace = result.map_err(|e| ErrorBuilder::new(ErrorCode::CreateDefaultWorkspaceFailed).error(e).build())?;
|
||||
|
||||
let query: Bytes = QueryWorkspaceRequest {
|
||||
workspace_id: Some(workspace.id.clone()),
|
||||
user_id: user_id.to_string(),
|
||||
}
|
||||
.into_bytes()
|
||||
.unwrap();
|
||||
|
@ -6,7 +6,6 @@ use crate::{
|
||||
use crate::{entities::UpdateUserParams, services::server::UserServerAPI};
|
||||
use flowy_infra::future::ResultFuture;
|
||||
use flowy_net::{config::*, request::HttpRequestBuilder};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct UserServer {}
|
||||
impl UserServer {
|
||||
|
@ -2,6 +2,6 @@ mod app_handler;
|
||||
mod view_handler;
|
||||
mod workspace_handler;
|
||||
|
||||
pub use app_handler::*;
|
||||
pub use view_handler::*;
|
||||
pub use workspace_handler::*;
|
||||
pub(crate) use app_handler::*;
|
||||
pub(crate) use view_handler::*;
|
||||
pub(crate) use workspace_handler::*;
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
sql_tables::app::{AppTable, AppTableChangeset, AppTableSql},
|
||||
};
|
||||
use flowy_dispatch::prelude::DispatchFuture;
|
||||
use flowy_net::request::HttpRequestBuilder;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) struct AppController {
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use app_controller::*;
|
||||
pub use view_controller::*;
|
||||
pub use workspace_controller::*;
|
||||
pub(crate) use app_controller::*;
|
||||
pub(crate) use view_controller::*;
|
||||
pub(crate) use workspace_controller::*;
|
||||
|
||||
mod app_controller;
|
||||
mod database;
|
||||
|
@ -59,7 +59,7 @@ impl WorkspaceServerAPI for WorkspaceServerMock {
|
||||
}
|
||||
|
||||
fn read_view(&self, _token: &str, _params: QueryViewParams) -> ResultFuture<Option<View>, WorkspaceError> {
|
||||
ResultFuture::new(async { Ok((None)) })
|
||||
ResultFuture::new(async { Ok(None) })
|
||||
}
|
||||
|
||||
fn delete_view(&self, _token: &str, _params: DeleteViewParams) -> ResultFuture<(), WorkspaceError> {
|
||||
|
@ -1,12 +1,12 @@
|
||||
use crate::{
|
||||
entities::view::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams, View},
|
||||
entities::view::{CreateViewParams, UpdateViewParams, View},
|
||||
errors::WorkspaceError,
|
||||
module::WorkspaceDatabase,
|
||||
observable::{send_observable, WorkspaceObservable},
|
||||
services::server::Server,
|
||||
sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql},
|
||||
};
|
||||
use flowy_net::request::HttpRequestBuilder;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) struct ViewController {
|
||||
|
@ -8,8 +8,8 @@ use crate::{
|
||||
};
|
||||
use flowy_dispatch::prelude::DispatchFuture;
|
||||
use flowy_infra::kv::KVStore;
|
||||
use flowy_net::request::HttpRequestBuilder;
|
||||
use std::{future::Future, sync::Arc};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) struct WorkspaceController {
|
||||
pub user: Arc<dyn WorkspaceUser>,
|
||||
|
@ -18,14 +18,9 @@ pub fn create_workspace(name: &str, desc: &str) -> (String, Workspace) {
|
||||
let request = CreateWorkspaceRequest {
|
||||
name: name.to_owned(),
|
||||
desc: desc.to_owned(),
|
||||
user_id: user_id.clone(),
|
||||
};
|
||||
|
||||
let workspace = builder
|
||||
.event(CreateWorkspace)
|
||||
.request(request)
|
||||
.sync_send()
|
||||
.parse::<Workspace>();
|
||||
let workspace = builder.event(CreateWorkspace).request(request).sync_send().parse::<Workspace>();
|
||||
|
||||
(user_id, workspace)
|
||||
}
|
||||
@ -38,10 +33,7 @@ pub fn read_workspaces(request: QueryWorkspaceRequest) -> Option<Workspace> {
|
||||
.parse::<RepeatedWorkspace>();
|
||||
|
||||
debug_assert_eq!(repeated_workspace.len(), 1);
|
||||
repeated_workspace
|
||||
.drain(..1)
|
||||
.collect::<Vec<Workspace>>()
|
||||
.pop()
|
||||
repeated_workspace.drain(..1).collect::<Vec<Workspace>>().pop()
|
||||
}
|
||||
|
||||
pub fn create_app(name: &str, desc: &str, workspace_id: &str) -> App {
|
||||
@ -65,25 +57,13 @@ pub fn delete_app(app_id: &str) {
|
||||
app_id: app_id.to_string(),
|
||||
};
|
||||
|
||||
AnnieTestBuilder::new()
|
||||
.event(DeleteApp)
|
||||
.request(delete_app_request)
|
||||
.sync_send();
|
||||
AnnieTestBuilder::new().event(DeleteApp).request(delete_app_request).sync_send();
|
||||
}
|
||||
|
||||
pub fn update_app(request: UpdateAppRequest) {
|
||||
AnnieTestBuilder::new()
|
||||
.event(UpdateApp)
|
||||
.request(request)
|
||||
.sync_send();
|
||||
}
|
||||
pub fn update_app(request: UpdateAppRequest) { AnnieTestBuilder::new().event(UpdateApp).request(request).sync_send(); }
|
||||
|
||||
pub fn read_app(request: QueryAppRequest) -> App {
|
||||
let app = AnnieTestBuilder::new()
|
||||
.event(ReadApp)
|
||||
.request(request)
|
||||
.sync_send()
|
||||
.parse::<App>();
|
||||
let app = AnnieTestBuilder::new().event(ReadApp).request(request).sync_send().parse::<App>();
|
||||
|
||||
app
|
||||
}
|
||||
@ -112,17 +92,6 @@ pub fn create_view() -> View {
|
||||
create_view_with_request(request)
|
||||
}
|
||||
|
||||
pub fn update_view(request: UpdateViewRequest) {
|
||||
AnnieTestBuilder::new()
|
||||
.event(UpdateView)
|
||||
.request(request)
|
||||
.sync_send();
|
||||
}
|
||||
pub fn update_view(request: UpdateViewRequest) { AnnieTestBuilder::new().event(UpdateView).request(request).sync_send(); }
|
||||
|
||||
pub fn read_view(request: QueryViewRequest) -> View {
|
||||
AnnieTestBuilder::new()
|
||||
.event(ReadView)
|
||||
.request(request)
|
||||
.sync_send()
|
||||
.parse::<View>()
|
||||
}
|
||||
pub fn read_view(request: QueryViewRequest) -> View { AnnieTestBuilder::new().event(ReadView).request(request).sync_send().parse::<View>() }
|
||||
|
@ -10,11 +10,8 @@ fn workspace_create_success() { let _ = create_workspace("First workspace", "");
|
||||
|
||||
#[test]
|
||||
fn workspace_read_all() {
|
||||
let (user_id, _) = create_workspace(
|
||||
"Workspace A",
|
||||
"workspace_create_and_then_get_workspace_success",
|
||||
);
|
||||
let request = QueryWorkspaceRequest::new(&user_id);
|
||||
let (_, _) = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success");
|
||||
let request = QueryWorkspaceRequest::new();
|
||||
let workspaces = AnnieTestBuilder::new()
|
||||
.event(ReadWorkspaces)
|
||||
.request(request)
|
||||
@ -26,21 +23,18 @@ fn workspace_read_all() {
|
||||
|
||||
#[test]
|
||||
fn workspace_create_and_then_get_workspace() {
|
||||
let (user_id, workspace) = create_workspace(
|
||||
"Workspace A",
|
||||
"workspace_create_and_then_get_workspace_success",
|
||||
);
|
||||
let request = QueryWorkspaceRequest::new(&user_id).workspace_id(&workspace.id);
|
||||
let (_user_id, workspace) = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success");
|
||||
let request = QueryWorkspaceRequest::new().workspace_id(&workspace.id);
|
||||
let workspace_from_db = read_workspaces(request).unwrap();
|
||||
assert_eq!(workspace.name, workspace_from_db.name);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workspace_create_with_apps() {
|
||||
let (user_id, workspace) = create_workspace("Workspace", "");
|
||||
let (_user_id, workspace) = create_workspace("Workspace", "");
|
||||
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
|
||||
|
||||
let request = QueryWorkspaceRequest::new(&user_id).workspace_id(&workspace.id);
|
||||
let request = QueryWorkspaceRequest::new().workspace_id(&workspace.id);
|
||||
let workspace_from_db = read_workspaces(request).unwrap();
|
||||
assert_eq!(&app, workspace_from_db.apps.first_or_crash());
|
||||
}
|
||||
@ -49,21 +43,10 @@ fn workspace_create_with_apps() {
|
||||
fn workspace_create_with_invalid_name() {
|
||||
for name in invalid_workspace_name_test_case() {
|
||||
let builder = AnnieTestBuilder::new();
|
||||
let user_id = builder.user_detail.as_ref().unwrap().id.clone();
|
||||
|
||||
let request = CreateWorkspaceRequest {
|
||||
name,
|
||||
desc: "".to_owned(),
|
||||
user_id: user_id.clone(),
|
||||
};
|
||||
let request = CreateWorkspaceRequest { name, desc: "".to_owned() };
|
||||
|
||||
assert_eq!(
|
||||
builder
|
||||
.event(CreateWorkspace)
|
||||
.request(request)
|
||||
.sync_send()
|
||||
.error()
|
||||
.code,
|
||||
builder.event(CreateWorkspace).request(request).sync_send().error().code,
|
||||
ErrorCode::WorkspaceNameInvalid
|
||||
)
|
||||
}
|
||||
@ -73,21 +56,10 @@ fn workspace_create_with_invalid_name() {
|
||||
fn workspace_update_with_invalid_name() {
|
||||
for name in invalid_workspace_name_test_case() {
|
||||
let builder = AnnieTestBuilder::new();
|
||||
let user_id = builder.user_detail.as_ref().unwrap().id.clone();
|
||||
|
||||
let request = CreateWorkspaceRequest {
|
||||
name,
|
||||
desc: "".to_owned(),
|
||||
user_id: user_id.clone(),
|
||||
};
|
||||
let request = CreateWorkspaceRequest { name, desc: "".to_owned() };
|
||||
|
||||
assert_eq!(
|
||||
builder
|
||||
.event(CreateWorkspace)
|
||||
.request(request)
|
||||
.sync_send()
|
||||
.error()
|
||||
.code,
|
||||
builder.event(CreateWorkspace).request(request).sync_send().error().code,
|
||||
ErrorCode::WorkspaceNameInvalid
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user