fix: ascending id order in list_definitions_for_child (NQ-71-001)
This commit is contained in:
@@ -511,19 +511,20 @@ async def list_definitions_for_child(
|
||||
"""Return the definitions assigned to ``child_id`` (rich view).
|
||||
|
||||
``child_id`` must be a plain int (bools and floats rejected, since
|
||||
SQLite would bind ``True`` onto child 1). Ordering follows the DAO's
|
||||
``list_by_child`` (newest definition first), so the result is
|
||||
deterministic. Each entry is a :class:`CreatedQuestDefinition`
|
||||
snapshot bundling the definition with its decoded rule, assignees and
|
||||
windows.
|
||||
SQLite would bind ``True`` onto child 1). Results are ordered by
|
||||
rising definition id, matching ``list_active_definitions`` and
|
||||
``list_definitions_firing_on``. Each entry is a
|
||||
:class:`CreatedQuestDefinition` snapshot bundling the definition with
|
||||
its decoded rule, assignees and windows.
|
||||
"""
|
||||
_validate_child_id(child_id)
|
||||
dao = QuestDefinitionsDao(database)
|
||||
definitions = await dao.list_by_child(child_id)
|
||||
return [
|
||||
bundles = [
|
||||
await _bundle_definition(database, dao, definition)
|
||||
for definition in definitions
|
||||
]
|
||||
return sorted(bundles, key=lambda bundle: bundle.definition.id)
|
||||
|
||||
|
||||
async def list_definitions_firing_on(
|
||||
|
||||
@@ -1505,20 +1505,21 @@ def test_list_definitions_for_child_returns_only_that_child(tmp_path) -> None:
|
||||
database, "Walk dog", _daily_rule(), [bo.id], ["afternoon"]
|
||||
)
|
||||
|
||||
# DAO list_by_child orders newest-first (id DESC), active or not.
|
||||
# The helper returns the given child's definitions in ascending
|
||||
# id order, consistent with list_active_definitions.
|
||||
result = await list_definitions_for_child(database, child.id)
|
||||
assert [bundle.definition.id for bundle in result] == [
|
||||
both.definition.id,
|
||||
ada_only.definition.id,
|
||||
both.definition.id,
|
||||
]
|
||||
assert result[1].rule == _daily_rule()
|
||||
assert [c.id for c in result[1].assignees] == [child.id]
|
||||
assert [w.window for w in result[1].windows] == ["morning"]
|
||||
assert result[0].rule == _daily_rule()
|
||||
assert [c.id for c in result[0].assignees] == [child.id]
|
||||
assert [w.window for w in result[0].windows] == ["morning"]
|
||||
|
||||
bo_result = await list_definitions_for_child(database, bo.id)
|
||||
assert [bundle.definition.id for bundle in bo_result] == [
|
||||
bo_only.definition.id,
|
||||
both.definition.id,
|
||||
bo_only.definition.id,
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user