test(search): cover sort order of searchEmailsStructured and getEmailsByAddress #534

Merged
guettlibot merged 1 commits from refs/pull/534/head into main 2026-06-07 18:24:30 +00:00
guettlibot commented 2026-06-07 18:21:47 +00:00 (Migrated from codeberg.org)

Summary

Issue #485 reports search showing the oldest mail at the top. PR #520 already fixed the two largest culprits (searchEmails and searchEmailsGlobal) by switching the FTS query from ORDER BY rank to ORDER BY received_at DESC and re-sorting the merged FTS + notes results.

The remaining two search paths surfaced from the UI — searchEmailsStructured (advanced search) and getEmailsByAddress (the per-address email list) — already used OrderingTerm.desc(receivedAt), but had no regression test, so a future change to either could silently reintroduce the bug this issue describes.

Changes

  • Add searchEmailsStructured returns results sorted by receivedAt descending
  • Add getEmailsByAddress returns results sorted by receivedAt descending

No production code changes — the existing implementations already sort newest-first; this just locks in the contract.

Test plan

  • fvm flutter test test/unit/email_repository_impl_test.dart — all 73 tests pass, including the two new ones.
  • fvm dart analyze test/unit/email_repository_impl_test.dart — no issues.
  • fvm dart format — no formatting changes.

Closes #485

## Summary Issue #485 reports search showing the oldest mail at the top. PR #520 already fixed the two largest culprits (`searchEmails` and `searchEmailsGlobal`) by switching the FTS query from `ORDER BY rank` to `ORDER BY received_at DESC` and re-sorting the merged FTS + notes results. The remaining two search paths surfaced from the UI — `searchEmailsStructured` (advanced search) and `getEmailsByAddress` (the per-address email list) — already used `OrderingTerm.desc(receivedAt)`, but had no regression test, so a future change to either could silently reintroduce the bug this issue describes. ## Changes - Add `searchEmailsStructured returns results sorted by receivedAt descending` - Add `getEmailsByAddress returns results sorted by receivedAt descending` No production code changes — the existing implementations already sort newest-first; this just locks in the contract. ## Test plan - [x] `fvm flutter test test/unit/email_repository_impl_test.dart` — all 73 tests pass, including the two new ones. - [x] `fvm dart analyze test/unit/email_repository_impl_test.dart` — no issues. - [x] `fvm dart format` — no formatting changes. Closes #485
Sign in to join this conversation.