From a2b0e93303c1b769d21d1f9a723eadadc4647bb2 Mon Sep 17 00:00:00 2001 From: kamathmanu <manuriddle@gmail.com> Date: Fri, 8 Jan 2021 15:46:10 -0500 Subject: [PATCH] Continue fixing ClientAPI tests; Rearranged nesting order since the PUT wasn't working when nested in the join_room. TODO: figure out why the room is not added to directory --- lib/http/client.cpp | 1 + tests/client_api.cpp | 134 ++++++++++++++++++++++++++++++------------- 2 files changed, 96 insertions(+), 39 deletions(-) diff --git a/lib/http/client.cpp b/lib/http/client.cpp index 237c5ed32..6c5e82667 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -986,6 +986,7 @@ Client::put_room_visibility(const std::string &room_id, + mtx::client::utils::url_encode(room_id); std::cout << api_path << "\n"; put<mtx::requests::RoomVisibility>(api_path, req, cb); + std::cout << "Does ths work?\n"; } void diff --git a/tests/client_api.cpp b/tests/client_api.cpp index 450bba75c..e80c16377 100644 --- a/tests/client_api.cpp +++ b/tests/client_api.cpp @@ -1599,7 +1599,7 @@ TEST(ClientAPI, PublicRooms) mtx::requests::CreateRoom req; req.name = "Public Room"; req.topic = "Test"; - req.visibility = Visibility::Public; + req.visibility = Visibility::Private; req.invite = {"@bob:localhost"}; // req.room_alias_name = "foo"; @@ -1608,57 +1608,113 @@ TEST(ClientAPI, PublicRooms) check_error(err); auto room_id = res.room_id; - bob->join_room(room_id.to_string(), [alice, bob, room_id](const mtx::responses::RoomId &, RequestErr err) { - check_error(err); - - // TEST 1: endpoints to set and get the visibility of the room we just created - mtx::requests::RoomVisibility r; - r.visibility = mtx::requests::Visibility::Private; + // TEST 1: endpoints to set and get the visibility of the room we just created + mtx::requests::RoomVisibility r; + r.visibility = mtx::requests::Visibility::Public; - std::cout << "HERE\n"; + std::cout << "HERE\n"; alice->put_room_visibility(room_id.to_string(), r, [alice, bob, room_id](RequestErr err){ check_error(err); - std::cout << "NOW IM HERE\n"; + std::cout << "PLS WORK!\n"; alice->get_room_visibility ("", [alice, room_id](const mtx::responses::RoomVisibility &, RequestErr err) { - check_error(err); - // ASSERT_TRUE(err); - // EXPECT_EQ(mtx::errors::to_string(err->matrix_error.errcode), - // "M_NOT_FOUND"); + ASSERT_TRUE(err); + EXPECT_EQ(mtx::errors::to_string(err->matrix_error.errcode), + "M_NOT_FOUND"); }); - // alice->get_room_visibility - // (room_id, [alice](const mtx::responses::RoomVisibility &res, RequestErr err){ + std::atomic<bool> done = false; + + alice->get_room_visibility + (room_id.to_string(), [alice, bob, room_id, &done](const mtx::responses::RoomVisibility &res, RequestErr err){ - // check_error(err); - // EXPECT_EQ(visibilityToString(res.visibility), "public"); + check_error(err); + EXPECT_EQ(visibilityToString(res.visibility), "public"); + done = true; - // // TEST 2: endpoints to add and list the public rooms on the server - // mtx::requests::PublicRooms room_req; - // room_req.limit = 1; - // room_req.include_all_networks = true; - // json j = room_req; - // std::cout << j.dump(4) << "\n"; - - // alice->post_public_rooms - // (room_req, [alice](const mtx::responses::PublicRooms &, RequestErr err) { - // check_error(err); - - // alice->get_public_rooms - // ([alice](const mtx::responses::PublicRooms &res, RequestErr err) { - // check_error(err); - // std::cout << res.chunk.size() << std::endl; - // EXPECT_EQ(res.chunk[0].name, "Public Room"); - // EXPECT_EQ(res.chunk[0].topic, "Test"); - // EXPECT_EQ(res.chunk[0].num_joined_members, 2); - // }, "", 1); - // }); - // }); + // TEST 2: endpoints to add and list the public rooms on the server + mtx::requests::PublicRooms room_req; + room_req.limit = 1; + room_req.include_all_networks = true; + json j = room_req; + std::cout << j.dump(4) << "\n"; + + while (!done) { + sleep(); + } + + alice->post_public_rooms + (room_req, [alice, bob, room_id, room_req](const mtx::responses::PublicRooms &, RequestErr err) { + check_error(err); + + std::cout << "POST req\n"; + + // alice->get_public_rooms + // ([alice, bob, room_id](const mtx::responses::PublicRooms &res, RequestErr err) { + // check_error(err); + // std::cout << res.chunk.size() << std::endl; + // EXPECT_EQ(res.chunk[0].name, "Public Room"); + // EXPECT_EQ(res.chunk[0].topic, "Test"); + // EXPECT_EQ(res.chunk[0].num_joined_members, 2); + // }, "", 1); + }); + }); }); - }); + + // bob->join_room(room_id.to_string(), [alice, bob, room_id](const mtx::responses::RoomId &, RequestErr err) { + // check_error(err); + + // // TEST 1: endpoints to set and get the visibility of the room we just created + // mtx::requests::RoomVisibility r; + // r.visibility = mtx::requests::Visibility::Private; + + // std::cout << "HERE\n"; + + // alice->put_room_visibility(room_id.to_string(), r, [alice, bob, room_id](RequestErr err){ + // check_error(err); + + // std::cout << "PLS WORK!\n"; + + // alice->get_room_visibility + // ("", [alice, room_id](const mtx::responses::RoomVisibility &, RequestErr err) { + // check_error(err); + // ASSERT_TRUE(err); + // EXPECT_EQ(mtx::errors::to_string(err->matrix_error.errcode), + // "M_NOT_FOUND"); + // }); + + // // alice->get_room_visibility + // // (room_id, [alice](const mtx::responses::RoomVisibility &res, RequestErr err){ + + // // check_error(err); + // // EXPECT_EQ(visibilityToString(res.visibility), "public"); + + // // // TEST 2: endpoints to add and list the public rooms on the server + // // mtx::requests::PublicRooms room_req; + // // room_req.limit = 1; + // // room_req.include_all_networks = true; + // // json j = room_req; + // // std::cout << j.dump(4) << "\n"; + + // // alice->post_public_rooms + // // (room_req, [alice](const mtx::responses::PublicRooms &, RequestErr err) { + // // check_error(err); + + // // alice->get_public_rooms + // // ([alice](const mtx::responses::PublicRooms &res, RequestErr err) { + // // check_error(err); + // // std::cout << res.chunk.size() << std::endl; + // // EXPECT_EQ(res.chunk[0].name, "Public Room"); + // // EXPECT_EQ(res.chunk[0].topic, "Test"); + // // EXPECT_EQ(res.chunk[0].num_joined_members, 2); + // // }, "", 1); + // // }); + // // }); + // }); + // }); }); alice->close(); bob->close(); -- GitLab