style(src-tauri): cargo fmt

Pure mechanical rustfmt reformat (default config, no rustfmt.toml).
This commit is contained in:
soubarna
2026-10-05 17:19:13 +05:30
parent e1031b3ecc
commit b6cf46b883
27 changed files with 4430 additions and 1042 deletions
+50 -14
View File
@@ -5,8 +5,12 @@
//! never held across a network call.
use crate::integrations::erpnext::client::ErpClient;
use crate::integrations::erpnext::config::{self, ErpnextConfig, ErpnextConfigInput, ErpnextConfigView};
use crate::integrations::erpnext::discovery::{self, ic_number_ok, ConnectionTest, ErpnextOptions, LocalFacts};
use crate::integrations::erpnext::config::{
self, ErpnextConfig, ErpnextConfigInput, ErpnextConfigView,
};
use crate::integrations::erpnext::discovery::{
self, ic_number_ok, ConnectionTest, ErpnextOptions, LocalFacts,
};
use crate::integrations::erpnext::push::{self, PaymentPushResult, PushResult};
use crate::integrations::SyncStatus;
use crate::AppState;
@@ -18,12 +22,18 @@ pub fn get_config_impl(conn: &Connection) -> Result<ErpnextConfigView, String> {
}
/// Merges the form with the stored row (blank secret keeps the stored one) without saving.
pub fn resolve_config(conn: &Connection, input: ErpnextConfigInput) -> Result<ErpnextConfig, String> {
pub fn resolve_config(
conn: &Connection,
input: ErpnextConfigInput,
) -> Result<ErpnextConfig, String> {
let stored = config::load(conn)?;
input.resolve(&stored)
}
pub fn save_config_impl(conn: &Connection, input: ErpnextConfigInput) -> Result<ErpnextConfigView, String> {
pub fn save_config_impl(
conn: &Connection,
input: ErpnextConfigInput,
) -> Result<ErpnextConfigView, String> {
let cfg = resolve_config(conn, input)?;
config::save(conn, &cfg)?;
Ok(cfg.view())
@@ -32,7 +42,11 @@ pub fn save_config_impl(conn: &Connection, input: ErpnextConfigInput) -> Result<
/// What the connection test needs from the local database.
pub fn local_facts(conn: &Connection) -> Result<LocalFacts, String> {
let registration: String = conn
.query_row("SELECT gst_registration FROM app_settings WHERE id = 1", [], |r| r.get(0))
.query_row(
"SELECT gst_registration FROM app_settings WHERE id = 1",
[],
|r| r.get(0),
)
.map_err(|e| e.to_string())?;
let mut stmt = conn
.prepare("SELECT number FROM invoices ORDER BY id")
@@ -54,7 +68,11 @@ pub fn local_facts(conn: &Connection) -> Result<LocalFacts, String> {
)
.ok()
.map(|(prefix, padding, next)| crate::db::format_number(&prefix, padding, next));
Ok(LocalFacts { vendor_registered: registration != "unregistered", invalid_numbers, next_number })
Ok(LocalFacts {
vendor_registered: registration != "unregistered",
invalid_numbers,
next_number,
})
}
#[tauri::command]
@@ -65,7 +83,10 @@ pub fn erpnext_get_config(state: State<AppState>) -> Result<ErpnextConfigView, S
/// A blank `apiSecret` keeps the stored secret; a value replaces it; `clearSecret` removes it.
#[tauri::command]
pub fn erpnext_save_config(state: State<AppState>, config: ErpnextConfigInput) -> Result<ErpnextConfigView, String> {
pub fn erpnext_save_config(
state: State<AppState>,
config: ErpnextConfigInput,
) -> Result<ErpnextConfigView, String> {
let conn = state.db.lock().map_err(|e| e.to_string())?;
save_config_impl(&conn, config)
}
@@ -105,7 +126,10 @@ fn saved_client(state: &AppState) -> Result<ErpClient, String> {
config::load(&conn)?
};
if cfg.base_url.trim().is_empty() || cfg.api_key.trim().is_empty() || !cfg.api_secret.is_set() {
return Err("ERPNext is not set up yet: enter the address, API key and API secret in Settings.".into());
return Err(
"ERPNext is not set up yet: enter the address, API key and API secret in Settings."
.into(),
);
}
Ok(ErpClient::from_config(&cfg)?)
}
@@ -134,7 +158,10 @@ pub async fn erpnext_push_invoices(
}
#[tauri::command]
pub async fn erpnext_push_payment(state: State<'_, AppState>, payment_id: i64) -> Result<PaymentPushResult, String> {
pub async fn erpnext_push_payment(
state: State<'_, AppState>,
payment_id: i64,
) -> Result<PaymentPushResult, String> {
let http = saved_client(&state)?;
Ok(push::push_payment(&state.db, &http, payment_id).await)
}
@@ -165,15 +192,22 @@ mod tests {
use serde_json::json;
fn input(extra: serde_json::Value) -> ErpnextConfigInput {
let mut base = json!({ "baseUrl": "https://erp.example.com", "apiKey": "key1", "company": "Test Co" });
base.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());
let mut base =
json!({ "baseUrl": "https://erp.example.com", "apiKey": "key1", "company": "Test Co" });
base.as_object_mut()
.unwrap()
.extend(extra.as_object().unwrap().clone());
serde_json::from_value(base).unwrap()
}
#[test]
fn saved_config_is_returned_without_the_secret() {
let conn = crate::db::open_in_memory().unwrap();
let view = save_config_impl(&conn, input(json!({ "apiSecret": "super-secret-value", "submitOnPush": true }))).unwrap();
let view = save_config_impl(
&conn,
input(json!({ "apiSecret": "super-secret-value", "submitOnPush": true })),
)
.unwrap();
assert!(view.api_secret_set);
let shown = serde_json::to_string(&get_config_impl(&conn).unwrap()).unwrap();
assert!(!shown.contains("super-secret-value"));
@@ -190,7 +224,8 @@ mod tests {
#[test]
fn test_values_are_resolved_without_saving() {
let conn = crate::db::open_in_memory().unwrap();
let resolved = resolve_config(&conn, input(json!({ "apiSecret": "typed-not-saved" }))).unwrap();
let resolved =
resolve_config(&conn, input(json!({ "apiSecret": "typed-not-saved" }))).unwrap();
assert_eq!(resolved.api_secret.expose(), "typed-not-saved");
assert!(!get_config_impl(&conn).unwrap().api_secret_set);
}
@@ -203,7 +238,8 @@ mod tests {
assert!(facts.invalid_numbers.is_empty());
assert!(facts.next_number.is_some());
conn.execute("UPDATE app_settings SET gst_registration = 'regular'", []).unwrap();
conn.execute("UPDATE app_settings SET gst_registration = 'regular'", [])
.unwrap();
conn.execute(
"INSERT INTO invoices (number, invoice_date, created_at, updated_at)
VALUES ('INV/2026-001', '2026-04-01', 'n', 'n'), ('INVOICE/2026/000001', '2026-04-01', 'n', 'n')",