From fc458f3cef6f7321b85b68883672f5f6d2e12ada Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 1 Mar 2022 00:21:10 +0000 Subject: Don't require lots of casting to mock mail server Keep it in the test client --- gentoobrowse-api/unittests/mockDefs.cpp | 2 +- gentoobrowse-api/unittests/mockDefs.h | 2 ++ .../unittests/testNotificationsTriggers.cpp | 5 +---- gentoobrowse-api/unittests/testUsers.cpp | 20 +++++++------------- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp index 1d4018e..7f78b9d 100644 --- a/gentoobrowse-api/unittests/mockDefs.cpp +++ b/gentoobrowse-api/unittests/mockDefs.cpp @@ -59,7 +59,7 @@ Mail::Mail() : TestClient::TestClient() : m(IceTray::Cube::get()), p(IceTray::Cube::get()), n(IceTray::Cube::get()), ms(IceTray::Cube::get()), - u(IceTray::Cube::get()) + mms(std::dynamic_pointer_cast(ms)), u(IceTray::Cube::get()) { BOOST_REQUIRE(m); BOOST_REQUIRE(p); diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h index 963112b..404b2a2 100644 --- a/gentoobrowse-api/unittests/mockDefs.h +++ b/gentoobrowse-api/unittests/mockDefs.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ public: Gentoo::PortagePrxPtr p; Gentoo::NotificationsPtr n; IceTray::Mail::MailServerPtr ms; + IceTray::Mail::MockMailServerPtr mms; Gentoo::UsersPrxPtr u; void lintable_test_files(std::string_view name, const IceTray::Mail::EmailPtr & e) const; diff --git a/gentoobrowse-api/unittests/testNotificationsTriggers.cpp b/gentoobrowse-api/unittests/testNotificationsTriggers.cpp index db53041..b353af8 100644 --- a/gentoobrowse-api/unittests/testNotificationsTriggers.cpp +++ b/gentoobrowse-api/unittests/testNotificationsTriggers.cpp @@ -53,13 +53,10 @@ BOOST_AUTO_TEST_CASE(triggers) BOOST_AUTO_TEST_CASE(send) { - auto ms = std::dynamic_pointer_cast(this->ms); - BOOST_REQUIRE(ms); - BOOST_REQUIRE(!u->get(1)->lastmailshot); m->sendNotifications(); BOOST_REQUIRE(u->get(1)->lastmailshot); - const auto & es = ms->getSentEmails(); + const auto & es = mms->getSentEmails(); BOOST_REQUIRE_EQUAL(1, es.size()); BOOST_REQUIRE_EQUAL("Gentoo Browse: Latest updates", es[0]->subject); BOOST_REQUIRE_EQUAL("Dan Goodliffe", es[0]->to.name); diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp index 1b74006..0f5ee9c 100644 --- a/gentoobrowse-api/unittests/testUsers.cpp +++ b/gentoobrowse-api/unittests/testUsers.cpp @@ -57,15 +57,11 @@ BOOST_AUTO_TEST_CASE(authenticateVerify) BOOST_AUTO_TEST_CASE(create) { - auto ms1 = IceTray::Cube::get(); - BOOST_REQUIRE(ms1); - auto ms = std::dynamic_pointer_cast(ms1); - BOOST_REQUIRE(ms); auto user = u->create("testuser", "testpass", "Test User", "test@user.com"); - BOOST_REQUIRE_EQUAL(1, ms->getSentEmails().size()); - BOOST_REQUIRE_EQUAL("Gentoo Browse: Welcome", ms->getSentEmails().front()->subject); - BOOST_REQUIRE_EQUAL("test@user.com", ms->getSentEmails().front()->to.address); - BOOST_REQUIRE_EQUAL("Test User", ms->getSentEmails().front()->to.name); + BOOST_REQUIRE_EQUAL(1, mms->getSentEmails().size()); + BOOST_REQUIRE_EQUAL("Gentoo Browse: Welcome", mms->getSentEmails().front()->subject); + BOOST_REQUIRE_EQUAL("test@user.com", mms->getSentEmails().front()->to.address); + BOOST_REQUIRE_EQUAL("Test User", mms->getSentEmails().front()->to.name); BOOST_REQUIRE_EQUAL(4, user->userid); BOOST_REQUIRE_EQUAL("testuser", user->username); BOOST_REQUIRE_EQUAL("Test User", user->userrealname); @@ -119,12 +115,10 @@ BOOST_AUTO_TEST_CASE(createAgain) * * return original user * * resend verification */ - auto ms = std::dynamic_pointer_cast(this->ms); - BOOST_REQUIRE(ms); auto user = u->create("testuser", "testpass", "Test User", "recreate@user.com"); - BOOST_REQUIRE_EQUAL(2, ms->getSentEmails().size()); - BOOST_REQUIRE_EQUAL("Gentoo Browse: Welcome", ms->getSentEmails()[1]->subject); - BOOST_REQUIRE_EQUAL("test@user.com", ms->getSentEmails()[1]->to.address); + BOOST_REQUIRE_EQUAL(2, mms->getSentEmails().size()); + BOOST_REQUIRE_EQUAL("Gentoo Browse: Welcome", mms->getSentEmails()[0]->subject); + BOOST_REQUIRE_EQUAL("test@user.com", mms->getSentEmails()[0]->to.address); BOOST_REQUIRE_EQUAL(4, user->userid); BOOST_REQUIRE_EQUAL(36, user->verifyguid.length()); } -- cgit v1.2.3