@@ -1530,6 +1530,102 @@ public function testExportUsers()
15301530 $ this ->assertSame ($ response ["status " ], "completed " );
15311531 }
15321532
1533+ public function testQueryThreadsWithFilter ()
1534+ {
1535+ // Create a thread by sending a message with a parent_id
1536+ $ parentMessage = $ this ->channel ->sendMessage (["text " => "Parent message " ], $ this ->user1 ["id " ]);
1537+ $ threadMessage = $ this ->channel ->sendMessage (
1538+ ["text " => "Thread message " , "parent_id " => $ parentMessage ["message " ]["id " ]],
1539+ $ this ->user2 ["id " ]
1540+ );
1541+
1542+ // Query threads with filter
1543+ $ response = $ this ->client ->queryThreads (
1544+ ["parent_message_id " => ['$eq ' => $ parentMessage ["message " ]["id " ]]],
1545+ null ,
1546+ ["user_id " => $ this ->user1 ["id " ]]
1547+ );
1548+
1549+ // Verify the response
1550+ $ this ->assertTrue (array_key_exists ("threads " , (array )$ response ));
1551+ $ this ->assertGreaterThanOrEqual (1 , count ($ response ["threads " ]));
1552+ }
1553+
1554+ public function testQueryThreadsWithSort ()
1555+ {
1556+ // Create multiple threads
1557+ $ parentMessage1 = $ this ->channel ->sendMessage (["text " => "Parent message 1 " ], $ this ->user1 ["id " ]);
1558+ $ threadMessage1 = $ this ->channel ->sendMessage (
1559+ ["text " => "Thread message 1 " , "parent_id " => $ parentMessage1 ["message " ]["id " ]],
1560+ $ this ->user2 ["id " ]
1561+ );
1562+
1563+ $ parentMessage2 = $ this ->channel ->sendMessage (["text " => "Parent message 2 " ], $ this ->user1 ["id " ]);
1564+ $ threadMessage2 = $ this ->channel ->sendMessage (
1565+ ["text " => "Thread message 2 " , "parent_id " => $ parentMessage2 ["message " ]["id " ]],
1566+ $ this ->user2 ["id " ]
1567+ );
1568+
1569+ // Query threads with sort
1570+ $ response = $ this ->client ->queryThreads (
1571+ [],
1572+ ["created_at " => -1 ],
1573+ ["user_id " => $ this ->user1 ["id " ]]
1574+ );
1575+
1576+ // Verify the response
1577+ $ this ->assertTrue (array_key_exists ("threads " , (array )$ response ));
1578+ $ this ->assertGreaterThanOrEqual (2 , count ($ response ["threads " ]));
1579+ }
1580+
1581+ public function testQueryThreadsWithFilterAndSort ()
1582+ {
1583+ // Create multiple threads
1584+ $ parentMessage1 = $ this ->channel ->sendMessage (["text " => "Parent message 1 " ], $ this ->user1 ["id " ]);
1585+ $ threadMessage1 = $ this ->channel ->sendMessage (
1586+ ["text " => "Thread message 1 " , "parent_id " => $ parentMessage1 ["message " ]["id " ]],
1587+ $ this ->user2 ["id " ]
1588+ );
1589+
1590+ $ parentMessage2 = $ this ->channel ->sendMessage (["text " => "Parent message 2 " ], $ this ->user1 ["id " ]);
1591+ $ threadMessage2 = $ this ->channel ->sendMessage (
1592+ ["text " => "Thread message 2 " , "parent_id " => $ parentMessage2 ["message " ]["id " ]],
1593+ $ this ->user2 ["id " ]
1594+ );
1595+
1596+ // Query threads with both filter and sort
1597+ $ response = $ this ->client ->queryThreads (
1598+ ["created_by_user_id " => ['$eq ' => $ this ->user2 ["id " ]]],
1599+ ["created_at " => -1 ],
1600+ ["user_id " => $ this ->user1 ["id " ]]
1601+ );
1602+
1603+ // Verify the response
1604+ $ this ->assertTrue (array_key_exists ("threads " , (array )$ response ));
1605+ $ this ->assertGreaterThanOrEqual (2 , count ($ response ["threads " ]));
1606+ }
1607+
1608+ public function testQueryThreadsWithoutFilterAndSort ()
1609+ {
1610+ // Create a thread by sending a message with a parent_id
1611+ $ parentMessage = $ this ->channel ->sendMessage (["text " => "Parent message for no filter test " ], $ this ->user1 ["id " ]);
1612+ $ threadMessage = $ this ->channel ->sendMessage (
1613+ ["text " => "Thread message for no filter test " , "parent_id " => $ parentMessage ["message " ]["id " ]],
1614+ $ this ->user2 ["id " ]
1615+ );
1616+
1617+ // Query threads without filter and sort parameters
1618+ $ response = $ this ->client ->queryThreads (
1619+ [], // Empty filter
1620+ null , // No sort
1621+ ["user_id " => $ this ->user1 ["id " ]] // Only providing user_id in options
1622+ );
1623+
1624+ // Verify the response
1625+ $ this ->assertTrue (array_key_exists ("threads " , (array )$ response ));
1626+ $ this ->assertGreaterThanOrEqual (1 , count ($ response ["threads " ]));
1627+ }
1628+
15331629 public function testCreateDraft ()
15341630 {
15351631 $ message = ["text " => "This is a draft message " ];
0 commit comments