#include "WidgetTest.hpp" #include #include #include #include #include #include #include using namespace testing; class HomeFactoryMock { public: MOCK_CONST_METHOD1(impl, std::unique_ptr< eedb::HomePage >(Wt::WWidget &)); }; class WebApplicationTest : public testing::Test { public: WebApplicationTest() : authPage{nullptr} { sut = new eedb::WebApplication(env, // session.getPtr(), login.getPtr(), [this]() { authPage.reset(new eedb::AuthPageMock(*login)); EXPECT_CALL(*authPage, registerOnNeedVerification(_)).WillOnce(SaveArg< 0 >(&_needVerificationCB)); EXPECT_CALL(*authPage, registerOnUserWeakLogin(_)).WillOnce(SaveArg< 0 >(&_weakLoginCB)); EXPECT_CALL(*authPage, registerOnLoginAttempt(_)).WillOnce(SaveArg< 0 >(&_onLoginAttempt)); EXPECT_CALL(*authPage, registerOnUserStrongLogin(_)).WillOnce(SaveArg< 0 >(&_strongLoginCB)); EXPECT_CALL(*authPage, registerOnUserLogout(_)).WillOnce(SaveArg< 0 >(&_userLogoutCB)); EXPECT_CALL(*authPage, processEnvironment()); return authPage.getPtr(); }, [this](auto & page) { return this->homePageFactory->impl(page); }, nullptr); } protected: Wt::Test::WTestEnvironment env; UniquePtrMockWrapper< Wt::Auth::Login > login; UniquePtrMockWrapper< eedb::SessionMock > session; UniquePtrMockWrapper< eedb::AuthPageMock > authPage; UniquePtrMockWrapper< HomeFactoryMock > homePageFactory; UniquePtrMockWrapper< eedb::HomePageMock > homePage; std::function< void(eedb::User *, nlohmann::json) > _strongLoginCB; std::function< void(eedb::User *, nlohmann::json) > _weakLoginCB; std::function< void(eedb::User *, nlohmann::json) > _onLoginAttempt; std::function< void() > _userLogoutCB; std::function< void() > _needVerificationCB; eedb::WebApplication * sut; }; TEST_F(WebApplicationTest, strongLoginTrigersHomepageCreation) { EXPECT_CALL(*homePageFactory, impl(Ref(*authPage))).WillOnce(Return(ByMove(homePage.getPtr()))); EXPECT_CALL(*session, login(_, _)); _strongLoginCB(nullptr, {}); } TEST_F(WebApplicationTest, weakLoginTrigersHomepageCreation) { EXPECT_CALL(*homePageFactory, impl(Ref(*authPage))).WillOnce(Return(ByMove(homePage.getPtr()))); EXPECT_CALL(*session, login(_, _)); _weakLoginCB(nullptr, {}); } TEST_F(WebApplicationTest, loginAttemptIsSaved) { EXPECT_CALL(*session, loginAttempt(_, _)); _onLoginAttempt(nullptr, {}); } TEST_F(WebApplicationTest, logout) { EXPECT_CALL(*session, logout()); _userLogoutCB(); }