diff options
Diffstat (limited to 'gentoobrowse-api/unittests/testUsers.cpp')
-rw-r--r-- | gentoobrowse-api/unittests/testUsers.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp index 4af063b..6d1ce02 100644 --- a/gentoobrowse-api/unittests/testUsers.cpp +++ b/gentoobrowse-api/unittests/testUsers.cpp @@ -1,10 +1,12 @@ #define BOOST_TEST_MODULE TestUsers +#include <boost/test/data/test_case.hpp> #include <boost/test/unit_test.hpp> #include "mockDefs.h" #include "user-models.h" #include "users.h" #include <Ice/Optional.h> +#include <compileTimeFormatter.h> #include <ext/alloc_traits.h> #include <icecube.h> #include <mail.h> @@ -71,6 +73,44 @@ BOOST_AUTO_TEST_CASE(create) BOOST_REQUIRE_EQUAL(36, user->verifyguid.length()); } +auto genUsername = [n = 0]() mutable { + return AdHoc::scprintf<"genUsername%?">(n++); +}; +auto genEmail = [n = 0]() mutable { + return AdHoc::scprintf<"email%?@test.com">(n++); +}; + +const auto EMPTY = boost::unit_test::data::make({""}); +const auto URLS = boost::unit_test::data::make( + {"before https://something", "before https://something after", "https://something after", "http://something"}); +const auto EMAILS = boost::unit_test::data::make({"something@something.com"}); +const auto BAD_EMAILS = boost::unit_test::data::make( + {"@something.com", "something@", "something", "some thing@something.com", "something@some thing.com"}); + +BOOST_DATA_TEST_CASE(create_reject_username, EMPTY + URLS, username) +{ + auto ms = std::dynamic_pointer_cast<IceTray::Mail::MockMailServer>(IceTray::Cube::get<IceTray::Mail::MailServer>()); + BOOST_CHECK_THROW(u->create(username, "testpass", "Test User", genEmail()), Gentoo::Rejected); + BOOST_REQUIRE(ms); + BOOST_CHECK(ms->getSentEmails().empty()); +} + +BOOST_DATA_TEST_CASE(create_reject_realname, EMPTY + URLS, realname) +{ + auto ms = std::dynamic_pointer_cast<IceTray::Mail::MockMailServer>(IceTray::Cube::get<IceTray::Mail::MailServer>()); + BOOST_CHECK_THROW(u->create(genUsername(), "testpass", realname, genEmail()), Gentoo::Rejected); + BOOST_REQUIRE(ms); + BOOST_CHECK(ms->getSentEmails().empty()); +} + +BOOST_DATA_TEST_CASE(create_reject_email, EMPTY + URLS + BAD_EMAILS, email) +{ + auto ms = std::dynamic_pointer_cast<IceTray::Mail::MockMailServer>(IceTray::Cube::get<IceTray::Mail::MailServer>()); + BOOST_CHECK_THROW(u->create(genUsername(), "testpass", "Test User", email), Gentoo::Rejected); + BOOST_REQUIRE(ms); + BOOST_CHECK(ms->getSentEmails().empty()); +} + BOOST_AUTO_TEST_CASE(get) { auto user = u->get(1); |