TestUnarchiveChildChat covers the deterministic branches of the Server.UnarchiveChat child path: happy path, archived-parent reject, and already-active no-op.
(t *testing.T)
| 1588 | // Server.UnarchiveChat child path: happy path, archived-parent reject, |
| 1589 | // and already-active no-op. |
| 1590 | func TestUnarchiveChildChat(t *testing.T) { |
| 1591 | t.Parallel() |
| 1592 | |
| 1593 | t.Run("ChildWithActiveParentUnarchives", func(t *testing.T) { |
| 1594 | t.Parallel() |
| 1595 | |
| 1596 | db, ps := dbtestutil.NewDB(t) |
| 1597 | replica := newTestServer(t, db, ps, uuid.New()) |
| 1598 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1599 | user, org, model := seedChatDependencies(t, db) |
| 1600 | |
| 1601 | parent, child := insertParentWithArchivedChild(ctx, t, db, user, org, model) |
| 1602 | |
| 1603 | require.NoError(t, replica.UnarchiveChat(ctx, child)) |
| 1604 | |
| 1605 | dbChild, err := db.GetChatByID(ctx, child.ID) |
| 1606 | require.NoError(t, err) |
| 1607 | require.False(t, dbChild.Archived, "child should be unarchived") |
| 1608 | |
| 1609 | dbParent, err := db.GetChatByID(ctx, parent.ID) |
| 1610 | require.NoError(t, err) |
| 1611 | require.False(t, dbParent.Archived, "parent should stay active") |
| 1612 | }) |
| 1613 | |
| 1614 | t.Run("ChildWithArchivedParentRejected", func(t *testing.T) { |
| 1615 | t.Parallel() |
| 1616 | |
| 1617 | db, ps := dbtestutil.NewDB(t) |
| 1618 | replica := newTestServer(t, db, ps, uuid.New()) |
| 1619 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1620 | user, org, model := seedChatDependencies(t, db) |
| 1621 | |
| 1622 | parent, child := insertParentWithArchivedChild(ctx, t, db, user, org, model) |
| 1623 | _, err := db.ArchiveChatByID(ctx, parent.ID) |
| 1624 | require.NoError(t, err) |
| 1625 | |
| 1626 | err = replica.UnarchiveChat(ctx, child) |
| 1627 | require.ErrorIs(t, err, chatd.ErrChildUnarchiveParentArchived) |
| 1628 | |
| 1629 | dbChild, err := db.GetChatByID(ctx, child.ID) |
| 1630 | require.NoError(t, err) |
| 1631 | require.True(t, dbChild.Archived, "child should remain archived") |
| 1632 | }) |
| 1633 | |
| 1634 | t.Run("AlreadyActiveChildNoOp", func(t *testing.T) { |
| 1635 | t.Parallel() |
| 1636 | |
| 1637 | db, ps := dbtestutil.NewDB(t) |
| 1638 | replica := newTestServer(t, db, ps, uuid.New()) |
| 1639 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1640 | user, org, model := seedChatDependencies(t, db) |
| 1641 | |
| 1642 | _, child := insertParentWithActiveChild(t, db, user, org, model) |
| 1643 | |
| 1644 | require.NoError(t, replica.UnarchiveChat(ctx, child)) |
| 1645 | |
| 1646 | dbChild, err := db.GetChatByID(ctx, child.ID) |
| 1647 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected