mirror of
https://github.com/ankitects/anki.git
synced 2026-09-10 07:29:19 -04:00
## Linked issue Closes #5383 ## Summary / motivation `rslib/src/decks/service.rs`: the Protobuf entry point for all deck operations, it had 0% test coverage. This PR adds a golden `#[cfg(test)]` suite that exercises the happy path, error paths, boundary cases, and key invariants of the `DecksService` layer and its proto↔domain conversions. No production code was changed: the module is a thin routing/conversion layer with no logic that warranted refactoring. Testing at this boundary is additive rather than duplicative: `reparent_decks`, `remove_decks_and_child_decks` and the proto↔domain conversions had no direct unit tests before. Coverage of `decks/service.rs` goes from **0% → ~99.7% of lines** ## How to test ### Details - `just check` passes (fmt, clippy, rust_test, and the rest of the suite). - Run just this module: `cargo test -p anki decks::service::tests`. - Coverage inspected with `just test-rust --coverage --html` - `decks/service.rs` reports ~99.7% line coverage. Scenarios covered: - proto↔domain conversions: full-field `Deck` round trip for both kinds, `missing kind → InvalidInput`, `FilteredDeckForUpdate` field preservation and `config: None → default`. - create/retrieve, update (common + kind-specific persistence), rename with descendant cascade, delete + card removal, reparent (incl. `new_parent == 0`). - name/tree listing: `include_filtered`, empty vs non-empty default skipping, child-name filtering, `deck_tree` counts by `now`, legacy tree JSON. - current deck, collapsed-scope isolation, legacy JSON paths (incl. `preserve_usn_and_mtime`), and filtered-deck build. - Error paths assert the specific `AnkiError` variant (`NotFound` / `InvalidInput`), not just `is_err()`.
Anki's Rust code.