style: use 2-space indentation across entire codebase
Add rustfmt.toml with tab_spaces = 2 and reformat all source files, tests, and README code examples to use 2-space indentation.
This commit is contained in:
+81
-81
@@ -5,75 +5,75 @@ use wiremock::{Mock, ResponseTemplate};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_field_success() {
|
||||
let (mock_server, client) = common::setup().await;
|
||||
let (mock_server, client) = common::setup().await;
|
||||
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/100"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"id": 100,
|
||||
"appId": 1,
|
||||
"name": "Text Field",
|
||||
"type": "Text",
|
||||
"status": "Enabled",
|
||||
"isRequired": true,
|
||||
"isUnique": false
|
||||
})))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/100"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"id": 100,
|
||||
"appId": 1,
|
||||
"name": "Text Field",
|
||||
"type": "Text",
|
||||
"status": "Enabled",
|
||||
"isRequired": true,
|
||||
"isUnique": false
|
||||
})))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
|
||||
let field = client.get_field(100).await.unwrap();
|
||||
assert_eq!(field.id, 100);
|
||||
assert_eq!(field.app_id, 1);
|
||||
assert_eq!(field.name.as_deref(), Some("Text Field"));
|
||||
assert!(field.is_required);
|
||||
assert!(!field.is_unique);
|
||||
let field = client.get_field(100).await.unwrap();
|
||||
assert_eq!(field.id, 100);
|
||||
assert_eq!(field.app_id, 1);
|
||||
assert_eq!(field.name.as_deref(), Some("Text Field"));
|
||||
assert!(field.is_required);
|
||||
assert!(!field.is_unique);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_field_list_type() {
|
||||
let (mock_server, client) = common::setup().await;
|
||||
let (mock_server, client) = common::setup().await;
|
||||
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/200"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"id": 200,
|
||||
"appId": 1,
|
||||
"name": "Status",
|
||||
"type": "List",
|
||||
"status": "Enabled",
|
||||
"isRequired": false,
|
||||
"isUnique": false,
|
||||
"multiplicity": "SingleSelect",
|
||||
"listId": 50,
|
||||
"values": [
|
||||
{
|
||||
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
"name": "Active",
|
||||
"sortOrder": 1,
|
||||
"numericValue": 1.0,
|
||||
"color": "#00ff00"
|
||||
}
|
||||
]
|
||||
})))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/200"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"id": 200,
|
||||
"appId": 1,
|
||||
"name": "Status",
|
||||
"type": "List",
|
||||
"status": "Enabled",
|
||||
"isRequired": false,
|
||||
"isUnique": false,
|
||||
"multiplicity": "SingleSelect",
|
||||
"listId": 50,
|
||||
"values": [
|
||||
{
|
||||
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
"name": "Active",
|
||||
"sortOrder": 1,
|
||||
"numericValue": 1.0,
|
||||
"color": "#00ff00"
|
||||
}
|
||||
]
|
||||
})))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
|
||||
let field = client.get_field(200).await.unwrap();
|
||||
assert_eq!(
|
||||
field.multiplicity,
|
||||
Some(onspring::Multiplicity::SingleSelect)
|
||||
);
|
||||
assert_eq!(field.list_id, Some(50));
|
||||
let values = field.values.unwrap();
|
||||
assert_eq!(values.len(), 1);
|
||||
assert_eq!(values[0].name, "Active");
|
||||
let field = client.get_field(200).await.unwrap();
|
||||
assert_eq!(
|
||||
field.multiplicity,
|
||||
Some(onspring::Multiplicity::SingleSelect)
|
||||
);
|
||||
assert_eq!(field.list_id, Some(50));
|
||||
let values = field.values.unwrap();
|
||||
assert_eq!(values.len(), 1);
|
||||
assert_eq!(values[0].name, "Active");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_batch_get_fields() {
|
||||
let (mock_server, client) = common::setup().await;
|
||||
let (mock_server, client) = common::setup().await;
|
||||
|
||||
Mock::given(method("POST"))
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/Fields/batch-get"))
|
||||
.and(body_json(serde_json::json!([1, 2])))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
@@ -86,16 +86,16 @@ async fn test_batch_get_fields() {
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
|
||||
let result = client.batch_get_fields(&[1, 2]).await.unwrap();
|
||||
assert_eq!(result.count, Some(2));
|
||||
assert_eq!(result.items.unwrap().len(), 2);
|
||||
let result = client.batch_get_fields(&[1, 2]).await.unwrap();
|
||||
assert_eq!(result.count, Some(2));
|
||||
assert_eq!(result.items.unwrap().len(), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_list_fields_for_app() {
|
||||
let (mock_server, client) = common::setup().await;
|
||||
let (mock_server, client) = common::setup().await;
|
||||
|
||||
Mock::given(method("GET"))
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/appId/5"))
|
||||
.and(query_param("PageNumber", "1"))
|
||||
.and(query_param("PageSize", "25"))
|
||||
@@ -113,30 +113,30 @@ async fn test_list_fields_for_app() {
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
|
||||
let paging = onspring::PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 25,
|
||||
};
|
||||
let result = client.list_fields(5, Some(paging)).await.unwrap();
|
||||
assert_eq!(result.total_records, Some(3));
|
||||
assert_eq!(result.items.unwrap().len(), 3);
|
||||
let paging = onspring::PagingRequest {
|
||||
page_number: 1,
|
||||
page_size: 25,
|
||||
};
|
||||
let result = client.list_fields(5, Some(paging)).await.unwrap();
|
||||
assert_eq!(result.total_records, Some(3));
|
||||
assert_eq!(result.items.unwrap().len(), 3);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_field_not_found() {
|
||||
let (mock_server, client) = common::setup().await;
|
||||
let (mock_server, client) = common::setup().await;
|
||||
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/999"))
|
||||
.respond_with(ResponseTemplate::new(404))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/Fields/id/999"))
|
||||
.respond_with(ResponseTemplate::new(404))
|
||||
.mount(&mock_server)
|
||||
.await;
|
||||
|
||||
let result = client.get_field(999).await;
|
||||
assert!(result.is_err());
|
||||
if let Err(onspring::OnspringError::Api { status_code, .. }) = result {
|
||||
assert_eq!(status_code, 404);
|
||||
} else {
|
||||
panic!("Expected Api error");
|
||||
}
|
||||
let result = client.get_field(999).await;
|
||||
assert!(result.is_err());
|
||||
if let Err(onspring::OnspringError::Api { status_code, .. }) = result {
|
||||
assert_eq!(status_code, 404);
|
||||
} else {
|
||||
panic!("Expected Api error");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user