From 34162de1ed2c0f3a21a9a54a243bbb3f74fbea57 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 10 Jun 2021 13:07:15 +0200 Subject: [PATCH] add test for UpdateUserInfo, fix CheckUsername Test --- .../JSONInterface/TestJsonCheckUsername.cpp | 6 ++- .../JSONInterface/TestJsonUpdateUserInfos.cpp | 52 +++++++++++++++++++ .../JSONInterface/TestJsonUpdateUserInfos.h | 23 ++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.cpp create mode 100644 login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.h diff --git a/login_server/src/cpp/test/JSONInterface/TestJsonCheckUsername.cpp b/login_server/src/cpp/test/JSONInterface/TestJsonCheckUsername.cpp index d399689ee..64e70055a 100644 --- a/login_server/src/cpp/test/JSONInterface/TestJsonCheckUsername.cpp +++ b/login_server/src/cpp/test/JSONInterface/TestJsonCheckUsername.cpp @@ -68,7 +68,6 @@ TEST(TestJsonCheckUsername, UsernameWithoutGroup) ASSERT_TRUE(msg.isString()); ASSERT_EQ(msg.toString(), "no group given"); - delete result; } @@ -89,6 +88,8 @@ TEST(TestJsonCheckUsername, ExistingUsername) ASSERT_FALSE(msg.isEmpty()); ASSERT_TRUE(msg.isString()); ASSERT_EQ(msg.toString(), "username already in use"); + + delete result; } TEST(TestJsonCheckUsername, NewUsername) @@ -103,6 +104,8 @@ TEST(TestJsonCheckUsername, NewUsername) ASSERT_FALSE(state.isEmpty()); ASSERT_TRUE(state.isString()); ASSERT_EQ(state.toString(), "success"); + + delete result; } TEST(TestJsonCheckUsername, UsernameExistInOtherGroup) @@ -118,6 +121,7 @@ TEST(TestJsonCheckUsername, UsernameExistInOtherGroup) ASSERT_TRUE(state.isString()); ASSERT_EQ(state.toString(), "success"); + delete result; } diff --git a/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.cpp b/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.cpp new file mode 100644 index 000000000..506fbb80f --- /dev/null +++ b/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.cpp @@ -0,0 +1,52 @@ +#include "gtest/gtest.h" + +#include "JSONInterface/JsonUpdateUserInfos.h" +#include "TestJsonUpdateUserInfos.h" + + +void TestJsonUpdateUserInfos::SetUp() +{ + auto sm = SessionManager::getInstance(); + sm->init(); + mUserSession = sm->getNewSession(); + mUserSession->loadUser("Jeet_bb@gmail.com", "TestP4ssword&H"); +} + +void TestJsonUpdateUserInfos::TearDown() +{ + auto sm = SessionManager::getInstance(); + if (!mUserSession) { + sm->releaseSession(mUserSession); + } + sm->deinitalize(); +} + +Poco::JSON::Object::Ptr TestJsonUpdateUserInfos::chooseAccount(const Poco::JSON::Object::Ptr update) +{ + Poco::JSON::Object::Ptr params = new Poco::JSON::Object; + params->set("session_id", mUserSession->getHandle()); + params->set("email", mUserSession->getNewUser()->getModel()->getEmail()); + params->set("update", update); + return params; +} + +TEST_F(TestJsonUpdateUserInfos, EmptyOldPassword) +{ + JsonUpdateUserInfos jsonCall; + Poco::JSON::Object::Ptr update = new Poco::JSON::Object; + + update->set("User.password", "haLL1o_/%s"); + + auto params = chooseAccount(update); + auto result = jsonCall.handle(params); + + auto errors = result->get("errors"); + ASSERT_TRUE(errors.isArray()); + //User.password_old not found + Poco::JSON::Array error_array = errors.extract(); + + ASSERT_EQ(error_array.size(), 1); + ASSERT_EQ(error_array.getElement(0), "User.password_old not found"); + + delete result; +} \ No newline at end of file diff --git a/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.h b/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.h new file mode 100644 index 000000000..4c759ce67 --- /dev/null +++ b/login_server/src/cpp/test/JSONInterface/TestJsonUpdateUserInfos.h @@ -0,0 +1,23 @@ +#ifndef __GRADIDO_LOGIN_SERVER_TEST_JSON_INTERFACE_TEST_JSON_UPDATE_USER_INFOS_H +#define __GRADIDO_LOGIN_SERVER_TEST_JSON_INTERFACE_TEST_JSON_UPDATE_USER_INFOS_H + +#include "gtest/gtest.h" +#include "SingletonManager/SessionManager.h" + +#include "Poco/JSON/Object.h" + +class TestJsonUpdateUserInfos : public ::testing::Test +{ + +protected: + void SetUp() override; + void TearDown() override; + + Poco::JSON::Object::Ptr chooseAccount(const Poco::JSON::Object::Ptr update); + + Session* mUserSession; + + +}; + +#endif //__GRADIDO_LOGIN_SERVER_TEST_JSON_INTERFACE_TEST_JSON_UPDATE_USER_INFOS_H \ No newline at end of file