#include #include #include #include #include #include #include #include #include "app.hpp" #include "config.hpp" #include "data.hpp" #include "data_mock.hpp" using ::testing::_; using ::testing::Return; 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 = "."; 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(); app = std::make_unique(config, std::move(data), std::move(auth)); } Configuration config; std::unique_ptr app; const DataSourceMock* data_source; }; 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(); }