test workspace server api

This commit is contained in:
appflowy 2021-09-02 23:32:37 +08:00
parent 9d667b6c96
commit 3a12d5ae79
5 changed files with 25 additions and 25 deletions

View File

@ -64,9 +64,11 @@ where
if !authenticate_pass {
if let Some(header) = req.headers().get(HEADER_TOKEN) {
let logger_user: LoggedUser = header.try_into().unwrap();
if AUTHORIZED_USERS.is_authorized(&logger_user) {
authenticate_pass = true;
let result: Result<LoggedUser, ServerError> = header.try_into();
if let Ok(logged_user) = result {
if AUTHORIZED_USERS.is_authorized(&logged_user) {
authenticate_pass = true;
}
}
}
}

View File

@ -20,9 +20,10 @@ pub trait UserServerAPI {
}
pub(crate) fn construct_user_server() -> Arc<dyn UserServerAPI + Send + Sync> {
if cfg!(feature = "http_server") {
Arc::new(UserServer {})
} else {
Arc::new(UserServerMock {})
}
// if cfg!(feature = "http_server") {
// Arc::new(UserServer {})
// } else {
// Arc::new(UserServerMock {})
// }
Arc::new(UserServer {})
}

View File

@ -7,7 +7,7 @@ use flowy_workspace::entities::{
#[test]
fn app_create() {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
dbg!(&app);
}
@ -15,7 +15,7 @@ fn app_create() {
#[test]
#[should_panic]
fn app_delete() {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
delete_app(&app.id);
let query = QueryAppRequest::new(&app.id);
@ -24,7 +24,7 @@ fn app_delete() {
#[test]
fn app_read() {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let query = QueryAppRequest::new(&app.id);
let app_from_db = read_app(query);
@ -33,13 +33,13 @@ fn app_read() {
#[test]
fn app_create_with_view() {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let request_a = CreateViewRequest {
belong_to_id: app.id.clone(),
name: "View A".to_string(),
desc: "".to_string(),
thumbnail: None,
thumbnail: Some("http://1.png".to_string()),
view_type: ViewType::Doc,
};
@ -47,7 +47,7 @@ fn app_create_with_view() {
belong_to_id: app.id.clone(),
name: "View B".to_string(),
desc: "".to_string(),
thumbnail: None,
thumbnail: Some("http://1.png".to_string()),
view_type: ViewType::Doc,
};
@ -77,7 +77,7 @@ fn app_set_trash_flag_2() {
}
fn create_app_with_trash_flag() -> String {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let request = UpdateAppRequest {
app_id: app.id.clone(),

View File

@ -11,18 +11,15 @@ pub(crate) fn invalid_workspace_name_test_case() -> Vec<String> {
.collect::<Vec<_>>()
}
pub fn create_workspace(name: &str, desc: &str) -> (String, Workspace) {
pub fn create_workspace(name: &str, desc: &str) -> Workspace {
let builder = AnnieTestBuilder::new();
let user_id = builder.user_detail.as_ref().unwrap().id.clone();
let request = CreateWorkspaceRequest {
name: name.to_owned(),
desc: desc.to_owned(),
};
let workspace = builder.event(CreateWorkspace).request(request).sync_send().parse::<Workspace>();
(user_id, workspace)
workspace
}
pub fn read_workspaces(request: QueryWorkspaceRequest) -> Option<Workspace> {
@ -79,13 +76,13 @@ pub fn create_view_with_request(request: CreateViewRequest) -> View {
}
pub fn create_view() -> View {
let workspace = create_workspace("Workspace", "").1;
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let request = CreateViewRequest {
belong_to_id: app.id.clone(),
name: "View A".to_string(),
desc: "".to_string(),
thumbnail: None,
thumbnail: Some("http://1.png".to_string()),
view_type: ViewType::Doc,
};

View File

@ -10,7 +10,7 @@ fn workspace_create_success() { let _ = create_workspace("First workspace", "");
#[test]
fn workspace_read_all() {
let (_, _) = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success");
let _ = create_workspace("Workspace A", "workspace_create_and_then_get_workspace_success");
let request = QueryWorkspaceRequest::new();
let workspaces = AnnieTestBuilder::new()
.event(ReadWorkspaces)
@ -23,7 +23,7 @@ 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 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);
@ -31,7 +31,7 @@ fn workspace_create_and_then_get_workspace() {
#[test]
fn workspace_create_with_apps() {
let (_user_id, workspace) = create_workspace("Workspace", "");
let workspace = create_workspace("Workspace", "");
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let request = QueryWorkspaceRequest::new().workspace_id(&workspace.id);