Skip to content

Commit

Permalink
cargo fmt and clipppppppppy
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorPlatz committed Nov 29, 2023
1 parent cd030a6 commit 70765df
Showing 1 changed file with 82 additions and 68 deletions.
150 changes: 82 additions & 68 deletions src/tests/api/model_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ use sea_orm::DbErr;
use tonic::{metadata, Code, Request};

use crate::{
api::{server::server::{ecdar_api_server::EcdarApi, DeleteModelRequest, ModelInfo, UpdateModelRequest, ComponentsInfo, Component, component::Rep, CreateModelRequest}, auth::TokenType},
entities::{model, access, session, in_use},
api::{
auth::TokenType,
server::server::{
component::Rep, ecdar_api_server::EcdarApi, Component, ComponentsInfo,
CreateModelRequest, DeleteModelRequest, ModelInfo, UpdateModelRequest,
},
},
entities::{access, in_use, model, session},
tests::api::helpers::{get_mock_concrete_ecdar_api, get_mock_services},
};

Expand Down Expand Up @@ -291,7 +297,7 @@ async fn update_name_returns_ok() {
let new_model_name = "new_name".to_string();

let mut update_model_request = Request::new(UpdateModelRequest {
id: model_id.clone(),
id: model_id,
name: Some(new_model_name.clone()),
components_info: None,
owner_id: None,
Expand All @@ -303,7 +309,8 @@ async fn update_name_returns_ok() {
);

update_model_request.metadata_mut().insert(
"uid", metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
"uid",
metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
);

mock_services
Expand All @@ -326,11 +333,11 @@ async fn update_name_returns_ok() {
.returning(move |_, _| {
Ok(Some(access::Model {
id: 1,
user_id: user_id,
model_id: model_id,
user_id,
model_id,
role: "Editor".to_string(),
}))
});
});

mock_services
.session_context_mock
Expand All @@ -339,13 +346,15 @@ async fn update_name_returns_ok() {
predicate::eq(TokenType::AccessToken),
predicate::eq("access_token".to_string()),
)
.returning(move |_, _| Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc()-Duration::seconds(100),
user_id: user_id,
})));
.returning(move |_, _| {
Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc() - Duration::seconds(100),
user_id,
}))
});

mock_services
.model_context_mock
Expand All @@ -364,7 +373,7 @@ async fn update_name_returns_ok() {
.expect_get_by_id()
.returning(move |_| {
Ok(Some(in_use::Model {
model_id: model_id,
model_id,
session_id: 1,
latest_activity: Utc::now().naive_utc(),
}))
Expand Down Expand Up @@ -395,17 +404,15 @@ async fn update_components_info_returns_ok() {
let user_id = 1;
let model_id = 1;
let components_info_non_json = ComponentsInfo {
components: vec![
Component {
rep: Some(Rep::Json("a".to_owned())),
}
],
components: vec![Component {
rep: Some(Rep::Json("a".to_owned())),
}],
components_hash: 1234456,
};
let components_info = serde_json::to_value(components_info_non_json.clone()).unwrap();

let mut update_model_request = Request::new(UpdateModelRequest {
id: model_id.clone(),
id: model_id,
name: None,
components_info: Some(components_info_non_json.clone()),
owner_id: None,
Expand All @@ -417,7 +424,8 @@ async fn update_components_info_returns_ok() {
);

update_model_request.metadata_mut().insert(
"uid", metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
"uid",
metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
);

mock_services
Expand All @@ -440,11 +448,11 @@ async fn update_components_info_returns_ok() {
.returning(move |_, _| {
Ok(Some(access::Model {
id: 1,
user_id: user_id,
model_id: model_id,
user_id,
model_id,
role: "Editor".to_string(),
}))
});
});

mock_services
.session_context_mock
Expand All @@ -453,13 +461,15 @@ async fn update_components_info_returns_ok() {
predicate::eq(TokenType::AccessToken),
predicate::eq("access_token".to_string()),
)
.returning(move |_, _| Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc()-Duration::seconds(100),
user_id: user_id,
})));
.returning(move |_, _| {
Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc() - Duration::seconds(100),
user_id,
}))
});

mock_services
.model_context_mock
Expand All @@ -478,7 +488,7 @@ async fn update_components_info_returns_ok() {
.expect_get_by_id()
.returning(move |_| {
Ok(Some(in_use::Model {
model_id: model_id,
model_id,
session_id: 1,
latest_activity: Utc::now().naive_utc(),
}))
Expand Down Expand Up @@ -511,10 +521,10 @@ async fn update_owner_id_returns_ok() {
let new_owner_id = 2;

let mut update_model_request = Request::new(UpdateModelRequest {
id: model_id.clone(),
id: model_id,
name: None,
components_info: None,
owner_id: Some(new_owner_id.clone()),
owner_id: Some(new_owner_id),
});

update_model_request.metadata_mut().insert(
Expand All @@ -523,7 +533,8 @@ async fn update_owner_id_returns_ok() {
);

update_model_request.metadata_mut().insert(
"uid", metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
"uid",
metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
);

mock_services
Expand All @@ -546,11 +557,11 @@ async fn update_owner_id_returns_ok() {
.returning(move |_, _| {
Ok(Some(access::Model {
id: 1,
user_id: user_id,
model_id: model_id,
user_id,
model_id,
role: "Editor".to_string(),
}))
});
});

mock_services
.session_context_mock
Expand All @@ -559,13 +570,15 @@ async fn update_owner_id_returns_ok() {
predicate::eq(TokenType::AccessToken),
predicate::eq("access_token".to_string()),
)
.returning(move |_, _| Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc()-Duration::seconds(100),
user_id: user_id,
})));
.returning(move |_, _| {
Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc() - Duration::seconds(100),
user_id,
}))
});

mock_services
.model_context_mock
Expand All @@ -575,7 +588,7 @@ async fn update_owner_id_returns_ok() {
id: model_id,
name: Default::default(),
components_info: Default::default(),
owner_id: new_owner_id.clone(),
owner_id: new_owner_id,
})
});

Expand All @@ -584,7 +597,7 @@ async fn update_owner_id_returns_ok() {
.expect_get_by_id()
.returning(move |_| {
Ok(Some(in_use::Model {
model_id: model_id,
model_id,
session_id: 1,
latest_activity: Utc::now().naive_utc(),
}))
Expand Down Expand Up @@ -616,21 +629,19 @@ async fn update_returns_ok() {
let model_id = 1;
let new_model_name = "new_name".to_string();
let new_components_info_non_json = ComponentsInfo {
components: vec![
Component {
rep: Some(Rep::Json("a".to_owned())),
}
],
components: vec![Component {
rep: Some(Rep::Json("a".to_owned())),
}],
components_hash: 1234456,
};
let new_components_info = serde_json::to_value(new_components_info_non_json.clone()).unwrap();
let new_owner_id = 2;

let mut update_model_request = Request::new(UpdateModelRequest {
id: model_id.clone(),
id: model_id,
name: Some(new_model_name.clone()),
components_info: Some(new_components_info_non_json.clone()),
owner_id: Some(new_owner_id.clone()),
owner_id: Some(new_owner_id),
});

update_model_request.metadata_mut().insert(
Expand All @@ -639,7 +650,8 @@ async fn update_returns_ok() {
);

update_model_request.metadata_mut().insert(
"uid", metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
"uid",
metadata::MetadataValue::from_str(user_id.to_string().as_str()).unwrap(),
);

mock_services
Expand All @@ -662,11 +674,11 @@ async fn update_returns_ok() {
.returning(move |_, _| {
Ok(Some(access::Model {
id: 1,
user_id: user_id,
model_id: model_id,
user_id,
model_id,
role: "Editor".to_string(),
}))
});
});

mock_services
.session_context_mock
Expand All @@ -675,13 +687,15 @@ async fn update_returns_ok() {
predicate::eq(TokenType::AccessToken),
predicate::eq("access_token".to_string()),
)
.returning(move |_, _| Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc()-Duration::seconds(100),
user_id: user_id,
})));
.returning(move |_, _| {
Ok(Some(session::Model {
id: 1,
refresh_token: "refresh_token".to_string(),
access_token: "access_token".to_string(),
updated_at: Utc::now().naive_utc() - Duration::seconds(100),
user_id,
}))
});

mock_services
.model_context_mock
Expand All @@ -691,7 +705,7 @@ async fn update_returns_ok() {
id: model_id,
name: new_model_name.clone(),
components_info: new_components_info.clone(),
owner_id: new_owner_id.clone(),
owner_id: new_owner_id,
})
});

Expand All @@ -700,7 +714,7 @@ async fn update_returns_ok() {
.expect_get_by_id()
.returning(move |_| {
Ok(Some(in_use::Model {
model_id: model_id,
model_id,
session_id: 1,
latest_activity: Utc::now().naive_utc(),
}))
Expand Down

0 comments on commit 70765df

Please sign in to comment.