From e9686b6ab684785d5f9acbc98942beae94817562 Mon Sep 17 00:00:00 2001 From: MetroWind Date: Sun, 21 Sep 2025 21:34:34 -0700 Subject: Implement dir handler. Unit test WIP. --- src/app_test.cpp | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'src/app_test.cpp') diff --git a/src/app_test.cpp b/src/app_test.cpp index 06f2084..d1f41a5 100644 --- a/src/app_test.cpp +++ b/src/app_test.cpp @@ -19,46 +19,47 @@ using ::testing::HasSubstr; using ::testing::FieldsAre; using ::testing::ContainsRegex; -// class UserAppTest : public testing::Test -// { -// protected: -// UserAppTest() -// { -// config.base_url = "http://localhost:8080/"; -// config.listen_address = "localhost"; -// config.listen_port = 8080; -// config.data_dir = "."; +class UserAppTest : public testing::Test +{ +protected: + UserAppTest() + { + config.base_url = "http://localhost:8080/"; + config.listen_address = "localhost"; + config.listen_port = 8080; + config.data_dir = "."; -// auto auth = std::make_unique(); + auto auth = std::make_unique(); -// mw::UserInfo expected_user; -// expected_user.name = "mw"; -// expected_user.id = "mw"; -// mw::Tokens token; -// token.access_token = "aaa"; -// EXPECT_CALL(*auth, getUser(std::move(token))) -// .Times(::testing::AtLeast(0)) -// .WillRepeatedly(Return(expected_user)); -// auto data = std::make_unique(); -// data_source = data.get(); + mw::UserInfo expected_user; + expected_user.name = "mw"; + expected_user.id = "mw"; + mw::Tokens token; + token.access_token = "aaa"; + EXPECT_CALL(*auth, getUser(std::move(token))) + .Times(::testing::AtLeast(0)) + .WillRepeatedly(Return(expected_user)); + auto data = std::make_unique(); + data_source = data.get(); -// app = std::make_unique(config, std::move(data), std::move(auth)); -// } + app = std::make_unique(config, std::move(data), std::move(auth)); + } -// Configuration config; -// std::unique_ptr app; -// const DataSourceMock* data_source; -// }; + Configuration config; + std::unique_ptr app; + const DataSourceMock* data_source; +}; -// TEST_F(UserAppTest, CanDenyAccessToLinkList) -// { -// EXPECT_TRUE(mw::isExpected(app->start())); -// { -// mw::HTTPSession client; -// ASSIGN_OR_FAIL(const mw::HTTPResponse* res, client.get( -// mw::HTTPRequest("http://localhost:8080/_/links"))); -// EXPECT_EQ(res->status, 401); -// } -// app->stop(); -// app->wait(); -// } +TEST_F(UserAppTest, CanShowItemsOfDefaultUser) +{ + EXPECT_TRUE(mw::isExpected(app->start())); + { + mw::HTTPSession client; + ASSIGN_OR_FAIL(const mw::HTTPResponse* res, client.get( + mw::HTTPRequest("http://localhost:8080/"))); + EXPECT_EQ(res->status, 301); + EXPECT_EQ(res->header.at("Location"), "http://localhost:8080/mw"); + } + app->stop(); + app->wait(); +} -- cgit v1.2.3-70-g09d2