fix(accounts): break AccountDao sortOrder ties by email
AccountDaoTest (added by #270's coverage lane) asserts email ordering, but AccountDao.observeAll()/getAll() now order by the user-defined sortOrder (#164) with no tiebreaker. Two accounts inserted via plain upsert() both land on the default sortOrder (0), so they came back in rowid/insertion order instead — failing the test deterministically on CI (API 30 & 31): expected [ada, zed], got [zed, ada]. Add `email` as a secondary ORDER BY key. Real accounts always get distinct sortOrders via insertAtEnd()/reorder(), so drag order is untouched; only equal-sortOrder rows now fall back to a stable, deterministic email order. This also matches the "rank by email" convention already used to seed sortOrder in ACCOUNT_MIGRATION_1_2 and AccountDataMigrator.copyAccountTables, so the existing coverage test passes unchanged. No schema/migration change is needed since this only edits a @Query string, not the entity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,10 +11,17 @@ import org.libremail.data.local.entity.AccountEntity
|
||||
|
||||
@Dao
|
||||
interface AccountDao {
|
||||
@Query("SELECT * FROM accounts ORDER BY sortOrder")
|
||||
/**
|
||||
* Every listing surface (Settings, the drawer switcher, the unified-inbox filter chips) follows
|
||||
* the user-defined [AccountEntity.sortOrder] (issue #164); `email` is only a tiebreaker for rows
|
||||
* that share a sortOrder (e.g. inserted via plain [upsert] rather than [insertAtEnd]/[reorder]),
|
||||
* so equal-sortOrder accounts still list in a stable, deterministic order.
|
||||
*/
|
||||
@Query("SELECT * FROM accounts ORDER BY sortOrder, email")
|
||||
fun observeAll(): Flow<List<AccountEntity>>
|
||||
|
||||
@Query("SELECT * FROM accounts ORDER BY sortOrder")
|
||||
/** See [observeAll] — same ordering: sortOrder, then email as a tiebreaker. */
|
||||
@Query("SELECT * FROM accounts ORDER BY sortOrder, email")
|
||||
suspend fun getAll(): List<AccountEntity>
|
||||
|
||||
@Query("SELECT * FROM accounts WHERE id = :id LIMIT 1")
|
||||
|
||||
Reference in New Issue
Block a user