feat(prices): Rust Tauri command fetch_price + tests #155
Labels
No labels
autopilot:pending-human
source:analyste
source:defenseur
source:human
source:medic
status:approved
status:blocked
status:in-progress
status:needs-clarification
status:needs-fix
status:ready
status:review
status:triage
type:bug
type:feature
type:infra
type:refactor
type:schema
type:security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: maximus/Simpl-Resultat#155
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Implement the Rust Tauri command
fetch_price(symbol, date) -> Result<PriceResponse, FetchPriceError>insrc-tauri/src/commands/balance_commands.rsand renameSIMPL_API_URL→MAXIMUS_API_URLeverywhere insrc-tauri/.Contract reference
docs/api-contract-prices.md§2 (endpoint), §3 (headers), §4 (success), §5 (errors), §12.1 (tests).Fichiers concernés
src-tauri/Cargo.toml(addmockito = "1.6"to[dev-dependencies])src-tauri/src/commands/balance_commands.rs(addfetch_pricefunction +FetchPriceErrorenum +PriceResponsestruct)src-tauri/src/commands/license_commands.rs(renameSIMPL_API_URL→MAXIMUS_API_URL, lines 300-301)src-tauri/src/lib.rs(registerfetch_priceininvoke_handler)src-tauri/src/commands/balance_commands.rs(new#[cfg(test)] mod testssection)Depends on
Scope
Cargo.toml[dev-dependencies]:mockito = "1.6"SIMPL_API_URL→MAXIMUS_API_URLinlicense_commands.rs:300-301(default URLhttps://api.lacompagniemaximus.comunchanged)balance_commands.rs, define types:pub struct PriceResponse { symbol, date, actual_date: Option<String>, price: f64, currency, source, fetched_at, cached: bool }pub enum FetchPriceError { Auth, PremiumRequired, SymbolNotFound, RateLimit { retry_after_s: u64 }, ProviderUnavailable, Network, Internal }(impl Display)pub async fn fetch_price(symbol: String, date: String) -> Result<PriceResponse, String>:activation_tokenvia existingactivation_pathaccessors (DO NOT duplicate token loading — reuselicense_commands::read_activation_tokenor equivalent helper)reqwest::Client::builder().user_agent("simpl-resultat").build().map_err(|e| e.to_string())?format!("{}/v1/prices?symbol={}&date={}", base_url(), symbol, date)wherebase_url()readsMAXIMUS_API_URLwith defaultAuthorization: Bearer <token>+Accept: application/json(the UA is set on the client builder)error.codeto typedFetchPriceError. Serialize the enum to a stable string for the JS layer (it does the i18n mapping)lib.rs::run()invoke_handlerbalance_commands.rsmod tests(usemockito::Server::new_async()):it_returns_price_on_200it_returns_auth_error_on_401it_returns_premium_required_on_403it_returns_symbol_not_found_on_404it_parses_retry_after_on_429(from JSON bodyerror.retry_after)it_returns_provider_unavailable_on_502it_sends_only_authorization_accept_user_agent— privacy headers test (usemock.match_header(...)or interceptor to assert allowed list exactly)Critères d'acceptation
cargo test fetch_pricegreen (≥ 7 tests)cargo clippy --all-targets -- -D warningsclean{Authorization, Accept, User-Agent, Host}(noAccept-Language, no cookies, noX-*)MAXIMUS_API_URLreferenced in 2 files (license_commands.rs + balance_commands.rs), no remainingSIMPL_API_URLinsrc-tauri/Décisions prises ce soir
MAXIMUS_API_URL(anciennementSIMPL_API_URL) — cohérence avec le nom du repo serveur. Migration incluse dans cette issue.mockitoversion pinnée à1.6(stable actuelle, API moderne).FetchPriceErrorreste côté Rust ; le mapping vers les clés i18n se fait côté TS (issue #156).Spec source
docs/api-contract-prices.mdmaximus referenced this issue2026-05-04 00:38:30 +00:00