289 lines
9.4 KiB
C++
289 lines
9.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#if defined(US_SDK_FULL)
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#include <ubiservices/core/JSON/json.h>
|
|
#include <ubiservices/services/user/userJobsHelper.h>
|
|
#include <ubiservices/services/profile/profileType.h>
|
|
#include <ubiservices/services/user/legalOptins.h>
|
|
#include <usCommon/options.h>
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestUser);
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
namespace UserInfoErrorPrivate
|
|
{
|
|
bool extractData(const Json& source, UserInfoError& target);
|
|
|
|
bool extractData(const Json& source)
|
|
{
|
|
UserInfoError dummy;
|
|
return extractData(source, dummy);
|
|
}
|
|
}
|
|
|
|
namespace LegalOptInsPrivate
|
|
{
|
|
bool extractData(const Json& source, LegalOptIns& target);
|
|
|
|
bool extractData(const Json& source)
|
|
{
|
|
LegalOptIns dummy;
|
|
return extractData(source, dummy);
|
|
}
|
|
}
|
|
|
|
typedef LeakChecker UNIT_USER;
|
|
|
|
#endif
|
|
|
|
namespace TestUser_BF
|
|
{
|
|
//{
|
|
// "userId": "string",
|
|
// "firstName": "string",
|
|
// "lastName": "string",
|
|
// "username": "string",
|
|
// "country": "string",
|
|
// "dateOfBirth": "string",
|
|
// "email": "string",
|
|
// "gender": "string",
|
|
// "communicationOptIn": "bool",
|
|
// "communicationThirdPartyOptIn": "bool",
|
|
// "preferredLanguage": "string",
|
|
// "status": {
|
|
// "autoGeneratedUsername": "bool",
|
|
// "dateOfBirthApproximated": "bool",
|
|
// "invalidEmail": "bool",
|
|
// "missingRequiredInformation": "bool",
|
|
// "recoveringPassword": "bool",
|
|
// "passwordUpdateRequired": "bool",
|
|
// "changeEmailPending": "bool",
|
|
// "reserved": "bool",
|
|
// "generalStatus": "string"
|
|
// },
|
|
// "dateCreated": "string",
|
|
// "hasAcceptedLegalOptins": "bool"
|
|
//}
|
|
|
|
|
|
Json getStatusValidJson()
|
|
{
|
|
JsonWriter writer;
|
|
writer["autoGeneratedUsername"] = false;
|
|
writer["dateOfBirthApproximated"] = false;
|
|
writer["invalidEmail"] = false;
|
|
writer["missingRequiredInformation"] = false;
|
|
writer["pendingDeactivation"] = false;
|
|
writer["recoveringPassword"] = false;
|
|
writer["passwordUpdateRequired"] = false;
|
|
writer["reserved"] = false;
|
|
writer["changeEmailPending"] = false;
|
|
writer["generalStatus"] = "pendingActivation";
|
|
return writer.getJson();
|
|
}
|
|
|
|
enum ProfileType
|
|
{
|
|
uplay = 0,
|
|
xbl,
|
|
wiiu,
|
|
psn
|
|
};
|
|
|
|
Vector<Json> getProfile(const Vector<ProfileType>& profileTypes)
|
|
{
|
|
Vector<Json> profiles;
|
|
for(Vector<ProfileType>::const_iterator it = profileTypes.begin(); it != profileTypes.end(); ++it)
|
|
{
|
|
JsonWriter writer;
|
|
switch(*it)
|
|
{
|
|
case xbl:
|
|
writer["profileId"] = "acca7977-bdfe-4df6-86dc-4b2a65f9c782";
|
|
writer["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["platformType"] = "xbl";
|
|
writer["idOnPlatform"] = "2535285332402925";
|
|
writer["nameOnPlatform"]= "ussdk001";
|
|
break;
|
|
case wiiu:
|
|
writer["profileId"] = "8f6c7f6e-286c-42d6-9202-860c02b59823";
|
|
writer["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["platformType"] = "wiiu";
|
|
writer["idOnPlatform"] = "1799895225";
|
|
writer["nameOnPlatform"]= "ussdk001";
|
|
break;
|
|
case psn:
|
|
writer["profileId"] = "1530d07d-eecb-4bac-a358-951613a51985";
|
|
writer["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["platformType"] = "psn";
|
|
writer["idOnPlatform"] = "6800812194353234709";
|
|
writer["nameOnPlatform"]= "ussdk001";
|
|
break;
|
|
case uplay:
|
|
default:
|
|
writer["profileId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["platformType"] = "uplay";
|
|
writer["idOnPlatform"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["nameOnPlatform"] = "ussdk001";
|
|
break;
|
|
}
|
|
profiles.push_back(writer.getJson());
|
|
}
|
|
return profiles;
|
|
}
|
|
|
|
void addLevelOneData(JsonWriter& writer)
|
|
{
|
|
writer["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
writer["firstName"] = "FirstNameTest";
|
|
writer["lastName"] = "LastNameTest";
|
|
writer["country"] = "CA";
|
|
writer["dateOfBirth"] = "1977-01-01T00:00:00.0000000";
|
|
writer["email"] = NS_COMMON::Options::email().c_str();
|
|
writer["gender"] = "F";
|
|
writer["communicationOptIn"] = true;
|
|
writer["communicationThirdPartyOptIn"] = true;
|
|
writer["preferredLanguage"] = "CA";
|
|
writer["hasAcceptedLegalOptins"] = true;
|
|
}
|
|
|
|
String getFullValidJson()
|
|
{
|
|
JsonWriter writer;
|
|
writer["status"] = getStatusValidJson();
|
|
addLevelOneData(writer);
|
|
|
|
return writer.renderContent();
|
|
}
|
|
|
|
#if !defined(US_DLL)
|
|
String getFullJsonInvalidProfile()
|
|
{
|
|
JsonWriter writer;
|
|
writer["status"] = getStatusValidJson();
|
|
Vector<ProfileType> platforms;
|
|
platforms.push_back(uplay); platforms.push_back(xbl); platforms.push_back(psn);
|
|
Vector<Json> profiles = getProfile(platforms);
|
|
{
|
|
// Adding Invalid WiiU
|
|
JsonWriter profileWriter;
|
|
profileWriter["profileId"] = "8f6c7f6e-286c-42d6-9202-860c02b59823";
|
|
profileWriter["userId"] = "4d9061de-7c20-4cc9-9f55-b8d6228da6ae";
|
|
profileWriter["platformType"] = "wiiu";
|
|
profileWriter["idOnPlatform"] = "1799895225";
|
|
profileWriter["nameOnPlatform"].setToNull();// Null item
|
|
profiles.push_back(profileWriter.getJson());
|
|
}
|
|
writer["profiles"] = profiles;
|
|
addLevelOneData(writer);
|
|
|
|
return writer.renderContent();
|
|
}
|
|
#endif
|
|
|
|
}
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
TEST_F(UNIT_USER, LOCAL_ParseJsonError)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
JsonWriter errorWriter;
|
|
JsonWriter validationArrayWriter(JsonWriterType::Array);
|
|
|
|
JsonWriter firstErrorWriter;
|
|
const uint32 ERROR_CODE = 1011u;
|
|
firstErrorWriter[_T("ErrorCode")] = ERROR_CODE;
|
|
const String fieldName(_T("username"));
|
|
firstErrorWriter[_T("Field")] = fieldName;
|
|
const String suggestion(_T("ezio2013,ezi0,ioez"));
|
|
firstErrorWriter[_T("FieldValueSuggestion")] = suggestion;
|
|
const String message(_T("Username not available"));
|
|
firstErrorWriter[_T("Message")] = message;
|
|
|
|
validationArrayWriter.addItemToArray(firstErrorWriter.getJson());
|
|
errorWriter["validationReports"] = validationArrayWriter.getJson();
|
|
|
|
Vector<UserInfoError> validationErrors;
|
|
const String jsonString = errorWriter.renderContent();
|
|
Json errorReader(jsonString);
|
|
UserJobsHelper::parseValidationJSON(errorReader, validationErrors);
|
|
|
|
EXPECT_EQ(1u, validationErrors.size());
|
|
UserInfoError firstError = *(validationErrors.begin());
|
|
|
|
EXPECT_EQ(ERROR_CODE, static_cast<uint32>(firstError.m_errorCode));
|
|
EXPECT_EQ(fieldName, firstError.m_field);
|
|
EXPECT_EQ(suggestion, firstError.m_valueSuggestion);
|
|
EXPECT_EQ(message, firstError.m_message);
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(86u, 86, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_USER, LOCAL_LegalOptinsJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
JsonWriter writer;
|
|
{
|
|
writer["legalOptinsKey"] = "key";
|
|
writer["communicationOptInDefaultValue"] = false;
|
|
writer["policyAcceptance"] = "privacyAcceptance";
|
|
writer["policyAcceptanceDefaultValue"] = false;
|
|
writer["policyAcceptanceIsRequired"] = true;
|
|
writer["policyLocaleCode"] = "en-US";
|
|
writer["privacyPolicyContent"] = "privacy";
|
|
writer["termOfUseContent"] = "TOU";
|
|
writer["termOfSaleContent"] = "TOS";
|
|
}
|
|
|
|
SAVE_ALLOC_COUNT(count1);
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(8u, 8, count1);
|
|
EXPECT_FALSE(LegalOptInsPrivate::extractData(Json(writer.renderContent())));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(39u, 39, count1);
|
|
|
|
writer["ageRequired"] = 84; // Add missing data
|
|
EXPECT_TRUE(LegalOptInsPrivate::extractData(Json(writer.renderContent())));
|
|
|
|
writer["Extra"] = 42; // Add extra data
|
|
EXPECT_TRUE(LegalOptInsPrivate::extractData(Json(writer.renderContent())));
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1137u, 1137, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_USER, LOCAL_UserInfoErrorJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
JsonWriter writer;
|
|
{
|
|
writer["ErrorCode"] = 3;
|
|
writer["Field"] = "DummyField";
|
|
writer["Message"] = "DummyMessage";
|
|
writer["FieldValueSuggestion"] = "DummySuggestion";
|
|
}
|
|
|
|
// Note : No check on mandatory fields,
|
|
// since it is already an error structure
|
|
// We don't raise a new error if the error retrieved is incorrect.
|
|
EXPECT_TRUE(UserInfoErrorPrivate::extractData(Json(writer.renderContent())));
|
|
|
|
writer["Extra"] = 42; // add extra data
|
|
EXPECT_TRUE(UserInfoErrorPrivate::extractData(Json(writer.renderContent())));
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(65u, 65, testCount);
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif // defined(US_SDK_FULL)
|