1427 lines
57 KiB
C++
1427 lines
57 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#if defined(US_SDK_LIGHT_MOBILE)
|
|
#error This file shall not be part of the solution
|
|
#endif
|
|
#include "tests/common/testJsonHelper.h"
|
|
#include "tests/fixture/authenticationFixture.h"
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include <ubiservices/core/JSON/json.h>
|
|
#include "ubiservices/core/types/dateTime.h"
|
|
#include "ubiservices/core/types/dateTimeHelper.h"
|
|
#if defined(US_SDK_FULL)
|
|
#include <ubiservices/services/battlepass/notificationTiersBanked.h>
|
|
#endif
|
|
#include "ubiservices/services/club/clubClient.h"
|
|
#include "ubiservices/services/club/notificationChallengeBanked.h"
|
|
#include "ubiservices/services/club/notificationChallengeCompleted.h"
|
|
#include "ubiservices/services/club/notificationChallengeParticipationStarted.h"
|
|
#include "ubiservices/services/club/notificationChallengeThresholdReached.h"
|
|
#include "ubiservices/services/club/notificationActionCompleted.h"
|
|
#include "ubiservices/services/club/notificationRewardPurchased.h"
|
|
#include "ubiservices/services/friend/notificationFriendRelationshipUpdate.h"
|
|
#include <ubiservices/services/notification/notificationCustom.h>
|
|
#include <ubiservices/services/notification/notificationUbiServices.h>
|
|
#include "ubiservices/services/parameters/parametersClient.h"
|
|
#include "ubiservices/services/secondaryStoreInstantiation/notificationInstancesUpdate.h"
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestMessaging);
|
|
|
|
typedef LeakChecker UNIT_NOTIFICATION;
|
|
typedef AuthenticationFixture<1, false> UNIT_NOTIFICATION_NOLOGIN;
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
class NotificationUbiServicesTest : public NotificationUbiServices
|
|
{
|
|
public:
|
|
NotificationUbiServicesTest()
|
|
: NotificationUbiServices()
|
|
{
|
|
}
|
|
};
|
|
|
|
namespace NotificationUbiServicesPrivate
|
|
{
|
|
bool extractData(const Json& source, NotificationUbiServices& target);
|
|
|
|
bool extractData(const Json& source)
|
|
{
|
|
NotificationUbiServicesTest dummy;
|
|
return extractData(source, dummy);
|
|
}
|
|
}
|
|
|
|
namespace TestClub_BF
|
|
{
|
|
void loginNewUser(Facade& facade);
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_SDK_FULL)
|
|
namespace TestBattlepass_BF
|
|
{
|
|
const size_t TIERS_TIER_COUNT = 3;
|
|
const size_t TIERS_REWARDS_COUNT = 3;
|
|
const char* const TIER_BANKED_SEASON_ID = "00000000-1111-2222-3333-444444444444";
|
|
const uint8 TIER_BANKED_TIERS_VALUES[TIERS_TIER_COUNT] = { 5,20,50 };
|
|
const char* const TIER_BANKED_REWARDS_ITEMIDS[TIERS_REWARDS_COUNT] = { "00000000-1111-2222-3333-444444444444","00000000-1111-2222-3333-444444444444","00000000-1111-2222-3333-444444444444" };
|
|
const uint32 TIER_BANKED_REWARDS_QUANTITY[TIERS_REWARDS_COUNT] = { 5,20,50 };
|
|
const char* const TIER_BANKED_REWARDS_TRACKS_TEXT[TIERS_REWARDS_COUNT] = { "Free","Invalid","Premium" };
|
|
const NotificationRewardTrackType TIER_BANKED_REWARDS_TRACKS[TIERS_REWARDS_COUNT] = { NotificationRewardTrackType::Free,
|
|
NotificationRewardTrackType::Unknown,
|
|
NotificationRewardTrackType::Premium };
|
|
Json getMockNotificationTiersBanked()
|
|
{
|
|
JsonWriter writer;
|
|
writer["notificationType"] = "BATTLEPASS_TIERS_BANKED";
|
|
writer["sourceApplicationId"] = "2222bbbb-2222-bbbb-2222-bbbb2222bbbb";
|
|
writer["sourceProfileId"] = "1111aaaa-1111-aaaa-1111-aaaa1111aaaa";
|
|
writer["spaceId"] = "12121212-3434-5656-7878-909090909090";
|
|
writer["datePosted"] = "2017-02-02T15:21:00Z";
|
|
writer["extraField"] = "Should be able to parse with extra field";
|
|
|
|
JsonWriter content;
|
|
{
|
|
struct Local
|
|
{
|
|
static Json rewardsGenerator(const String& itemId, uint32 quantity, const String& track)
|
|
{
|
|
JsonWriter rewardsWriter;
|
|
rewardsWriter["itemId"] = itemId;
|
|
rewardsWriter["quantity"] = quantity;
|
|
rewardsWriter["track"] = track;
|
|
return rewardsWriter.getJson();
|
|
}
|
|
|
|
static Json tiersGenerator(uint32 tier)
|
|
{
|
|
JsonWriter rewardsWriter(JsonWriterType::Array);
|
|
for (int i = 0; i < TIERS_REWARDS_COUNT; ++i)
|
|
{
|
|
rewardsWriter.addItemToArray(Local::rewardsGenerator(TIER_BANKED_REWARDS_ITEMIDS[i], TIER_BANKED_REWARDS_QUANTITY[i], TIER_BANKED_REWARDS_TRACKS_TEXT[i]));
|
|
}
|
|
|
|
JsonWriter thresholdWriter;
|
|
thresholdWriter["tier"] = tier;
|
|
thresholdWriter["rewards"] = rewardsWriter.getJson();
|
|
return thresholdWriter.getJson();
|
|
}
|
|
};
|
|
|
|
content["seasonId"] = TIER_BANKED_SEASON_ID;
|
|
JsonWriter tiersWriter(JsonWriterType::Array);
|
|
tiersWriter.addItemToArray(Local::tiersGenerator(TIER_BANKED_TIERS_VALUES[0]));
|
|
tiersWriter.addItemToArray(Local::tiersGenerator(TIER_BANKED_TIERS_VALUES[1]));
|
|
tiersWriter.addItemToArray(Local::tiersGenerator(TIER_BANKED_TIERS_VALUES[2]));
|
|
content["tiers"] = tiersWriter.getJson();
|
|
writer["content"] = content.getJson();
|
|
}
|
|
|
|
return writer.getJson();
|
|
}
|
|
};
|
|
#endif
|
|
|
|
namespace TestNotificationInstancesUpdate_BF
|
|
{
|
|
const char * INSTANCE_ID = "11111111-2222-3333-4444-555566667777";
|
|
const char * ITEM_ID = "11111111-2222-3333-4444-555566667777";
|
|
const char * INSTANCE_ACTION = "CREATE";
|
|
|
|
const DateTime LAST_MODIFIED(2015, 01, 10, 14, 03, 58);
|
|
const DateTime EXPIRATION_DATE(2016, 02, 10, 14, 03, 58);
|
|
|
|
const int32 PART_NUMBER = 1;
|
|
const int32 PART_COUNT = 2;
|
|
|
|
void checkNotificationContent(NotificationInstancesUpdate& notification)
|
|
{
|
|
EXPECT_EQ(PART_NUMBER, notification.m_transactionPartNumber);
|
|
EXPECT_EQ(PART_COUNT, notification.m_transactionPartCount);
|
|
|
|
EXPECT_EQ(1u, notification.m_instancesUpdates.size());
|
|
if (notification.m_instancesUpdates.size() == 1u)
|
|
{
|
|
EXPECT_EQ(INSTANCE_ID, notification.m_instancesUpdates[0].m_instance.m_instanceId);
|
|
EXPECT_EQ(ITEM_ID, notification.m_instancesUpdates[0].m_instance.m_itemId);
|
|
EXPECT_EQ(LAST_MODIFIED, notification.m_instancesUpdates[0].m_instance.m_lastModified);
|
|
EXPECT_TRUE(notification.m_instancesUpdates[0].m_instance.m_expirationDate.isSpecified());
|
|
if (notification.m_instancesUpdates[0].m_instance.m_expirationDate.isSpecified())
|
|
{
|
|
EXPECT_EQ(EXPIRATION_DATE, notification.m_instancesUpdates[0].m_instance.m_expirationDate.value());
|
|
}
|
|
EXPECT_EQ("value1", notification.m_instancesUpdates[0].m_instance.m_attributes["key1"].getValueString());
|
|
EXPECT_EQ("value2", notification.m_instancesUpdates[0].m_instance.m_attributes["key2"].getValueString());
|
|
EXPECT_EQ("value3", notification.m_instancesUpdates[0].m_instance.m_obj["key3"].getValueString());
|
|
EXPECT_EQ("value4", notification.m_instancesUpdates[0].m_instance.m_obj["key4"].getValueString());
|
|
|
|
EXPECT_EQ(INSTANCE_ACTION, notification.m_instancesUpdates[0].m_action);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace TestNotificationPlayer_BF
|
|
{
|
|
const char * SPACE_ID = MOCKED_GUID_ID1;
|
|
const char * APP_ID = "7777aaaa-1111-aaaa-1111-aaaa1111aaaa";
|
|
const char * PROFILE_ID = "9999dddd-1111-aaaa-1111-aaaa1111aaaa";
|
|
const DateTime DATE_POSTED(2019, 01, 02, 03, 04, 05);
|
|
|
|
template <typename FIELD_TYPE>
|
|
FIELD_TYPE getValue(const char* field, JsonWriter& writer)
|
|
{
|
|
return;
|
|
}
|
|
template <>
|
|
String getValue<String>(const char* field, JsonWriter& writer)
|
|
{
|
|
return writer[field].getJson().getValueString();
|
|
}
|
|
template <>
|
|
int32 getValue<int32>(const char* field, JsonWriter& writer)
|
|
{
|
|
return writer[field].getJson().getValueInteger();
|
|
}
|
|
template <>
|
|
Json getValue<Json>(const char* field, JsonWriter& writer)
|
|
{
|
|
return writer[field].getJson();
|
|
}
|
|
|
|
template <typename EXTRACTED_TYPE, typename FIELD_TYPE>
|
|
static void checkField(const char* field, JsonWriter& rootWriter, JsonWriter& fieldWriter, bool isNullAllowed = false)
|
|
{
|
|
EXTRACTED_TYPE notification;
|
|
FIELD_TYPE previousValue = getValue<FIELD_TYPE>(field, fieldWriter);
|
|
|
|
fieldWriter[field] = "INVALID";
|
|
EXPECT_FALSE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
fieldWriter[field].setToNull();
|
|
if (isNullAllowed)
|
|
{
|
|
EXPECT_TRUE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
}
|
|
else
|
|
{
|
|
EXPECT_FALSE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
}
|
|
|
|
// restore previous valid value
|
|
fieldWriter[field] = previousValue;
|
|
EXPECT_TRUE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
}
|
|
|
|
template <typename EXTRACTED_TYPE, typename FIELD_TYPE>
|
|
static void checkFieldBestEffort(const char* field, JsonWriter& rootWriter, JsonWriter& fieldWriter)
|
|
{
|
|
EXTRACTED_TYPE notification;
|
|
FIELD_TYPE previousValue = getValue<FIELD_TYPE>(field, fieldWriter);
|
|
|
|
fieldWriter[field] = "INVALID";
|
|
// parsing is always succesful because of the best effort approach
|
|
EXPECT_TRUE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
|
|
fieldWriter[field].setToNull();
|
|
// parsing is always succesful because of the best effort approach
|
|
EXPECT_TRUE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
|
|
fieldWriter[field] = previousValue;
|
|
EXPECT_TRUE(notification.parseContent(rootWriter.renderContent())) << "Field is : " << field;
|
|
}
|
|
|
|
template <typename T>
|
|
void checkNotificationPlayerValid(T& notification)
|
|
{
|
|
EXPECT_EQ(SPACE_ID, notification.m_spaceId);
|
|
EXPECT_EQ(APP_ID, notification.m_applicationId);
|
|
EXPECT_TRUE(notification.m_sourceApplicationId.isSpecified());
|
|
if (notification.m_sourceApplicationId.isSpecified())
|
|
{
|
|
EXPECT_EQ(APP_ID, notification.m_sourceApplicationId.value());
|
|
}
|
|
EXPECT_TRUE(notification.m_sourceProfileId.isSpecified());
|
|
if (notification.m_sourceProfileId.isSpecified())
|
|
{
|
|
EXPECT_EQ(PROFILE_ID, notification.m_sourceProfileId.value());
|
|
}
|
|
EXPECT_EQ(DATE_POSTED, notification.m_datePosted);
|
|
}
|
|
|
|
template <typename T>
|
|
void checkNotificationPlayerFields(JsonWriter& writer)
|
|
{
|
|
// Check non-null fields
|
|
{
|
|
const Vector<const char *> fields =
|
|
{
|
|
"notificationType",
|
|
"spaceId",
|
|
"datePosted"
|
|
};
|
|
for (auto field : fields)
|
|
{
|
|
checkField<T, String>(field, writer, writer, false);
|
|
}}
|
|
|
|
// Check null fields
|
|
{
|
|
const Vector<const char *> nullFields =
|
|
{
|
|
"sourceApplicationId",
|
|
"sourceProfileId",
|
|
};
|
|
|
|
for (auto field : nullFields)
|
|
{
|
|
checkField<T, String>(field, writer, writer, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void addMandatoryFieldsExceptContent(JsonWriter& writer, const char* notificationType)
|
|
{
|
|
writer["notificationType"] = notificationType;
|
|
writer["spaceId"] = SPACE_ID;
|
|
writer["datePosted"] = DateTimeHelper::formatDateISO8601(DATE_POSTED);
|
|
writer["extraField"] = "Should be able to parse with extra field";
|
|
};
|
|
|
|
void addOptionalFields(JsonWriter& writer)
|
|
{
|
|
writer["sourceApplicationId"] = APP_ID;
|
|
writer["sourceProfileId"] = PROFILE_ID;
|
|
};
|
|
|
|
JsonWriter renderNotificationPlayerJson(const char * notificationType)
|
|
{
|
|
JsonWriter writer;
|
|
addMandatoryFieldsExceptContent(writer, notificationType);
|
|
addOptionalFields(writer);
|
|
return writer;
|
|
}
|
|
}
|
|
namespace TestNotificationFriendRelationshipUpdate_BF
|
|
{
|
|
const char * FROM_PROFILE_ID = "88881111-2222-3333-4444-555566668888";
|
|
const char * STATE = "PendingReceivedInvite";
|
|
const DateTime LAST_MODIFIED(2019, 04, 05, 06, 03, 34);
|
|
|
|
JsonWriter renderContent()
|
|
{
|
|
JsonWriter contentWriter;
|
|
|
|
contentWriter["lastModified"] = DateTimeHelper::formatDateISO8601(LAST_MODIFIED);
|
|
contentWriter["fromProfileId"] = FROM_PROFILE_ID;
|
|
contentWriter["state"] = STATE;
|
|
|
|
// prsing should work with extra field
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
|
|
return contentWriter;
|
|
};
|
|
|
|
JsonWriter renderNotification()
|
|
{
|
|
// add the common notification player fields
|
|
JsonWriter writer(TestNotificationPlayer_BF::renderNotificationPlayerJson("FRIENDS_RELATIONSHIP_UPDATE"));
|
|
|
|
// add the content, which is specific for each player notification
|
|
JsonWriter contentWriter(TestNotificationFriendRelationshipUpdate_BF::renderContent());
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
return writer;
|
|
};
|
|
|
|
void checkNotificationContent(NotificationFriendRelationshipUpdate& notification)
|
|
{
|
|
EXPECT_EQ(LAST_MODIFIED, notification.m_lastModified);
|
|
EXPECT_EQ(FROM_PROFILE_ID, notification.m_fromProfileId);
|
|
EXPECT_EQ(FriendInfoClub::PendingReceivedInvite, notification.m_relationshipState);
|
|
}
|
|
}
|
|
using TestNotificationInstancesUpdate_BF::checkNotificationContent;
|
|
using namespace TestNotificationPlayer_BF;
|
|
|
|
#if !defined(US_DLL)
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationUbiServicesParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
{
|
|
NotificationUbiServicesTest notification;
|
|
EXPECT_FALSE(NotificationUbiServicesPrivate::extractData(Json(""), notification)) << "Parsing invalid JSON shall fail";
|
|
|
|
EXPECT_TRUE(notification.m_content.isEmpty());
|
|
EXPECT_EQ(NotificationUbiServicesType::Unknown, notification.m_type);
|
|
EXPECT_TRUE(notification.m_unknownType.isEmpty());
|
|
}
|
|
|
|
SAVE_ALLOC_COUNT(count1);
|
|
JsonWriter writer;
|
|
writer["notificationType"] = "myMessageType";
|
|
//writer["content"] = "Content"; // mandatory field missing
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(10u, 10, count1);
|
|
|
|
{
|
|
NotificationUbiServicesTest notification;
|
|
EXPECT_FALSE(NotificationUbiServicesPrivate::extractData(writer.getJson(), notification)) << "Parsing missing mandatory field shall fail";
|
|
|
|
EXPECT_TRUE(notification.m_content.isEmpty());
|
|
EXPECT_EQ(NotificationUbiServicesType::Unknown, notification.m_type);
|
|
EXPECT_TRUE(notification.m_unknownType.isEmpty());
|
|
}
|
|
|
|
// Add missing mandatory field
|
|
writer["content"] = "myMessageContent";
|
|
{
|
|
NotificationUbiServicesTest notification;
|
|
EXPECT_TRUE(NotificationUbiServicesPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_EQ(NotificationUbiServicesType::Unknown, notification.m_type);
|
|
EXPECT_FALSE(notification.m_unknownType.isEmpty());
|
|
}
|
|
|
|
// Add extra field
|
|
writer["extraField"] = 42;
|
|
{
|
|
NotificationUbiServicesTest notification;
|
|
EXPECT_TRUE(NotificationUbiServicesPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_EQ(NotificationUbiServicesType::Unknown, notification.m_type);
|
|
EXPECT_FALSE(notification.m_unknownType.isEmpty());
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(387u, 387, testCount);
|
|
}
|
|
|
|
|
|
class NotificationCustomTest : public NotificationCustom
|
|
{
|
|
public:
|
|
NotificationCustomTest()
|
|
: NotificationCustom()
|
|
{
|
|
}
|
|
};
|
|
|
|
namespace NotificationCustomPrivate
|
|
{
|
|
bool extractData(const Json& source, NotificationCustom& target);
|
|
|
|
bool extractData(const Json& source)
|
|
{
|
|
NotificationCustomTest dummy;
|
|
return extractData(source, dummy);
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationCustomParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
EXPECT_FALSE(NotificationCustomPrivate::extractData(Json(""))) << "Parsing invalid JSON shall fail";
|
|
|
|
SAVE_ALLOC_COUNT(count1);
|
|
JsonWriter writer;
|
|
writer["datePosted"] = "2014-08-04T15:21:00Z";
|
|
writer["notificationType"] = "myMessageType";
|
|
//writer["content"] = "Content"; // mandatory field missing
|
|
writer["spaceId"] = "1111aaaa-1111-aaaa-1111-aaaa1111aaaa";
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(10u, 10, count1);
|
|
|
|
EXPECT_FALSE(NotificationCustomPrivate::extractData(writer.getJson())) << "Parsing missing mandatory field shall fail";
|
|
|
|
// Add missing mandatory field
|
|
writer["content"] = "myMessageContent";
|
|
{
|
|
NotificationCustomTest notification;
|
|
EXPECT_TRUE(NotificationCustomPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_FALSE(notification.m_sourceApplicationId.isValid());
|
|
EXPECT_FALSE(notification.m_sourceProfileId.isValid());
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_TRUE(notification.m_datePosted.isValid());
|
|
EXPECT_FALSE(notification.m_type.isEmpty());
|
|
}
|
|
|
|
// Change content to json (another supported type)
|
|
writer["content"] = "{ \"field\":\"value\"}";
|
|
{
|
|
NotificationCustomTest notification;
|
|
EXPECT_TRUE(NotificationCustomPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_FALSE(notification.m_sourceApplicationId.isValid());
|
|
EXPECT_FALSE(notification.m_sourceProfileId.isValid());
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_TRUE(notification.m_datePosted.isValid());
|
|
EXPECT_FALSE(notification.m_type.isEmpty());
|
|
}
|
|
|
|
writer["sourceProfileId"] = "1111aaaa-1111-aaaa-1111-aaaa1111aaaa";
|
|
writer["sourceApplicationId"] = "2222bbbb-2222-bbbb-2222-bbbb2222bbbb";
|
|
{
|
|
NotificationCustomTest notification;
|
|
EXPECT_TRUE(NotificationCustomPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_TRUE(notification.m_sourceApplicationId.isValid());
|
|
EXPECT_TRUE(notification.m_sourceProfileId.isValid());
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_TRUE(notification.m_datePosted.isValid());
|
|
EXPECT_FALSE(notification.m_type.isEmpty());
|
|
}
|
|
|
|
// Add extra field
|
|
writer["extraField"] = 42;
|
|
{
|
|
NotificationCustomTest notification;
|
|
EXPECT_TRUE(NotificationCustomPrivate::extractData(writer.getJson(), notification));
|
|
|
|
EXPECT_TRUE(notification.m_sourceApplicationId.isValid());
|
|
EXPECT_TRUE(notification.m_sourceProfileId.isValid());
|
|
EXPECT_FALSE(notification.m_content.isEmpty());
|
|
EXPECT_TRUE(notification.m_datePosted.isValid());
|
|
EXPECT_FALSE(notification.m_type.isEmpty());
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(387u, 387, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationPlayerParsing)
|
|
{
|
|
|
|
{
|
|
NotificationChallengeCompleted notification;
|
|
EXPECT_FALSE(notification.parseContent(Json("").renderContent())) << "Parsing invalid JSON shall fail";
|
|
}
|
|
|
|
JsonWriter writer;
|
|
addMandatoryFieldsExceptContent(writer, "CLUB_CHALLENGE_COMPLETED");
|
|
{
|
|
NotificationChallengeCompleted notification;
|
|
EXPECT_FALSE(notification.parseContent(writer.renderContent())) << "Parsing should fail when a mandatory field is missing";
|
|
}
|
|
|
|
JsonWriter contentWriter;
|
|
contentWriter["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
contentWriter["type"] = "Player";
|
|
contentWriter["progression"] = 123.123f;
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationChallengeCompleted notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent())) << "Parsing should be successful if only the optional fields are missing";
|
|
}
|
|
|
|
addOptionalFields(writer);
|
|
{
|
|
NotificationChallengeCompleted notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent())) << "Parsing should be successful if all the fields are present and have correct values.";
|
|
|
|
checkNotificationPlayerValid<NotificationChallengeCompleted>(notification);
|
|
}
|
|
|
|
{
|
|
checkNotificationPlayerFields<NotificationChallengeCompleted>(writer);
|
|
}
|
|
}
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationActionCompletedParsing)
|
|
{
|
|
/*{
|
|
"notificationType": "CLUB_ACTION_COMPLETED",
|
|
"sourceApplicationId": "2222bbbb-2222-bbbb-2222-bbbb2222bbbb",
|
|
"sourceProfileId": "9999dddd-1111-aaaa-1111-aaaa1111aaaa",
|
|
"spaceId": "1111aaaa-1111-aaaa-1111-aaaa1111aaaa",
|
|
"datePosted": "2017-02-02T15:21:00Z",
|
|
"content": {
|
|
"actionId": "string"
|
|
"type": "string" // possible values "XP", "Unit", "Condition"
|
|
}
|
|
}*/
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_ACTION_COMPLETED"));
|
|
|
|
// Add missing mandatory fields with error
|
|
JsonWriter contentWriter;
|
|
contentWriter["type"] = "ErrorType";
|
|
const String actionId = "10000"; // The actionId is a string from "0" to "10000". Not much validation to do on a string.
|
|
contentWriter["actionId"] = actionId;
|
|
contentWriter["actionIdEx"] = actionId;
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationActionCompleted notification;
|
|
EXPECT_FALSE(notification.parseContent(writer.renderContent())) << "Parsing wrong content type shall fail";
|
|
}
|
|
|
|
// Fix content field to allowed value
|
|
contentWriter["type"] = "Condition";
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationActionCompleted notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
|
|
EXPECT_EQ(ActionType::Condition, notification.m_actionType);
|
|
}
|
|
|
|
contentWriter["type"] = "Unit";
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationActionCompleted notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
|
|
EXPECT_EQ(ActionType::Unit, notification.m_actionType);
|
|
}
|
|
|
|
contentWriter["type"] = "XP";
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationActionCompleted notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
|
|
EXPECT_EQ(notification.m_actionId, actionId);
|
|
EXPECT_EQ(ActionType::XP, notification.m_actionType);
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationRewardPurchasedParsing)
|
|
{
|
|
/*{
|
|
"notificationType": "CLUB_REWARD_PURCHASED",
|
|
"sourceApplicationId" : "2222bbbb-2222-bbbb-2222-bbbb2222bbbb",
|
|
"sourceProfileId": "9999dddd-1111-aaaa-1111-aaaa1111aaaa",
|
|
"spaceId" : "1111aaaa-1111-aaaa-1111-aaaa1111aaaa",
|
|
"datePosted" : "2017-02-02T15:21:00Z",
|
|
"content" : {
|
|
"rewardId": "REWARDID"
|
|
}
|
|
}*/
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_REWARD_PURCHASED"));
|
|
|
|
// Add missing mandatory field
|
|
JsonWriter contentWriter;
|
|
contentWriter["rewardId"] = "REWARDID";
|
|
writer["content"] = contentWriter.getJson();
|
|
{
|
|
NotificationRewardPurchased notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
|
|
EXPECT_FALSE(notification.m_rewardId.isEmpty());
|
|
}
|
|
|
|
// Test invalid and null values
|
|
checkNotificationPlayerFields<NotificationRewardPurchased>(writer);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationChallengeBankedParsing)
|
|
{
|
|
//{
|
|
// "notificationType": " CLUB_CHALLENGE_BANKED",
|
|
// "sourceApplicationId" : "string",
|
|
// "sourceProfileId": "string",
|
|
// "spaceId" : "string",
|
|
// "datePosted" : "string"
|
|
// "content" :
|
|
// {
|
|
// "challengeId": "guid",
|
|
// "thresholds" decimal[],
|
|
// "thresholdsBanked": decimal[],
|
|
// "type" "string" // possible values are "Player", "Community"
|
|
// }
|
|
//}
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_CHALLENGE_BANKED"));
|
|
|
|
JsonWriter contentWriter;
|
|
contentWriter["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
contentWriter["type"] = "Player";
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
|
|
JsonWriter thresholdsWriter(JsonWriterType::Array);
|
|
thresholdsWriter.addItemToArray(1000.0);
|
|
contentWriter["thresholds"] = thresholdsWriter.getJson();
|
|
|
|
JsonWriter thresholdsBankedWriter(JsonWriterType::Array);
|
|
thresholdsBankedWriter.addItemToArray(2000.0);
|
|
contentWriter["thresholdsBanked"] = thresholdsBankedWriter.getJson();
|
|
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
NotificationChallengeBanked notificationValid;
|
|
EXPECT_TRUE(notificationValid.parseContent(writer.renderContent())) << "Parsing should be valid";
|
|
|
|
{ // Challenge Id Checks
|
|
writer["content"]["challengeId"] = "INVALID";
|
|
NotificationChallengeBanked notificationChallengeId;
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"].setToNull();
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(ChallengeId("3333cccc-3333-cccc-2222-cccc3333cccc"), notificationChallengeId.m_challengeId);
|
|
}
|
|
|
|
{ // Type Checks
|
|
writer["content"]["type"] = "INVALID";
|
|
NotificationChallengeBanked notificationType;
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"].setToNull();
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"] = "player";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("profile", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Profile, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "community";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("community", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Community, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "season";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("season", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Season, notificationType.m_category);
|
|
}
|
|
|
|
{ // Thresholds Checks
|
|
writer["content"]["thresholds"] = "INVALID";
|
|
NotificationChallengeBanked notificationThresholds;
|
|
EXPECT_FALSE(notificationThresholds.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["thresholds"].setToNull();
|
|
EXPECT_FALSE(notificationThresholds.parseContent(writer.renderContent()));
|
|
|
|
thresholdsWriter.addItemToArray(3000.0);
|
|
Vector<Json> thresholds = thresholdsWriter.getJson().getItems();
|
|
writer["content"]["thresholds"] = thresholdsWriter.getJson();
|
|
EXPECT_TRUE(notificationThresholds.parseContent(writer.renderContent()));
|
|
ASSERT_EQ(thresholds.size(), notificationThresholds.m_thresholds.size());
|
|
for (size_t i = 0; i < thresholds.size(); ++i)
|
|
{
|
|
EXPECT_EQ(thresholds[i].getValueDouble(),
|
|
static_cast<double>(notificationThresholds.m_thresholds[i]));
|
|
}
|
|
}
|
|
|
|
{ // Thresholds Banked Checks
|
|
writer["content"]["thresholdsBanked"] = "INVALID";
|
|
NotificationChallengeBanked notificationThresholdsBanked;
|
|
EXPECT_FALSE(notificationThresholdsBanked.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["thresholdsBanked"].setToNull();
|
|
EXPECT_FALSE(notificationThresholdsBanked.parseContent(writer.renderContent()));
|
|
|
|
thresholdsBankedWriter.addItemToArray(4000.0);
|
|
Vector<Json> thresholdsBanked = thresholdsBankedWriter.getJson().getItems();
|
|
writer["content"]["thresholdsBanked"] = thresholdsBankedWriter.getJson();
|
|
EXPECT_TRUE(notificationThresholdsBanked.parseContent(writer.renderContent()));
|
|
ASSERT_EQ(thresholdsBanked.size(), notificationThresholdsBanked.m_thresholdsBanked.size());
|
|
for (size_t i = 0; i < thresholdsBanked.size(); ++i)
|
|
{
|
|
EXPECT_EQ(thresholdsBanked[i].getValueDouble(),
|
|
static_cast<double>(notificationThresholdsBanked.m_thresholdsBanked[i]));
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationChallengeThresholdReachedParsing)
|
|
{
|
|
// {
|
|
// "notificationType": " CLUB_CHALLENGE_THRESHOLD_REACHED",
|
|
// "sourceApplicationId": "string",
|
|
// "sourceProfileId": "string",
|
|
// "spaceId": "string",
|
|
// "datePosted": "string"
|
|
// "content":
|
|
// {
|
|
// "challengeId": "guid",
|
|
// "thresholds" decimal[],
|
|
// "thresholdReached": decimal,
|
|
// "completed": bool,
|
|
// "type" "string" // possible values are "Player", "Community"
|
|
// }
|
|
// }
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_CHALLENGE_THRESHOLD_REACHED"));
|
|
|
|
JsonWriter contentWriter;
|
|
contentWriter["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
contentWriter["type"] = "Player";
|
|
contentWriter["thresholdReached"] = 123.123f;
|
|
contentWriter["completed"] = true;
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
|
|
JsonWriter thresholdsWriter(JsonWriterType::Array);
|
|
thresholdsWriter.addItemToArray(1000.0);
|
|
contentWriter["thresholds"] = thresholdsWriter.getJson();
|
|
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
NotificationChallengeThresholdReached notificationValid;
|
|
EXPECT_TRUE(notificationValid.parseContent(writer.renderContent())) << "Parsing should be valid";
|
|
|
|
{ // Challenge Id Checks
|
|
writer["content"]["challengeId"] = "INVALID";
|
|
NotificationChallengeThresholdReached notificationChallengeId;
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"].setToNull();
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(ChallengeId("3333cccc-3333-cccc-2222-cccc3333cccc"), notificationChallengeId.m_challengeId);
|
|
}
|
|
|
|
{ // Type Checks
|
|
writer["content"]["type"] = "INVALID";
|
|
NotificationChallengeThresholdReached notificationType;
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"].setToNull();
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"] = "player";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("profile", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Profile, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "community";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("community", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Community, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "season";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("season", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Season, notificationType.m_category);
|
|
}
|
|
|
|
{ // Thresholds Checks
|
|
writer["content"]["thresholds"] = "INVALID";
|
|
NotificationChallengeThresholdReached notificationThresholds;
|
|
EXPECT_FALSE(notificationThresholds.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["thresholds"].setToNull();
|
|
EXPECT_FALSE(notificationThresholds.parseContent(writer.renderContent()));
|
|
|
|
thresholdsWriter.addItemToArray(3000.0);
|
|
Vector<Json> thresholds = thresholdsWriter.getJson().getItems();
|
|
writer["content"]["thresholds"] = thresholdsWriter.getJson();
|
|
EXPECT_TRUE(notificationThresholds.parseContent(writer.renderContent()));
|
|
ASSERT_EQ(thresholds.size(), notificationThresholds.m_thresholds.size());
|
|
for (size_t i = 0; i < thresholds.size(); ++i)
|
|
{
|
|
EXPECT_EQ(thresholds[i].getValueDouble(),
|
|
static_cast<double>(notificationThresholds.m_thresholds[i]));
|
|
}
|
|
}
|
|
|
|
{ // Threshold Reached Checks
|
|
writer["content"]["thresholdReached"] = "INVALID";
|
|
NotificationChallengeThresholdReached notificationThresholdReached;
|
|
EXPECT_FALSE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["thresholdReached"].setToNull();
|
|
EXPECT_FALSE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["thresholdReached"] = 123.123f;
|
|
EXPECT_TRUE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(123.123f, notificationThresholdReached.m_thresholdReached);
|
|
}
|
|
|
|
{ // Completed Checks
|
|
writer["content"]["completed"] = "INVALID";
|
|
NotificationChallengeThresholdReached notificationThresholdReached;
|
|
EXPECT_FALSE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["completed"].setToNull();
|
|
EXPECT_FALSE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["completed"] = true;
|
|
EXPECT_TRUE(notificationThresholdReached.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(true, notificationThresholdReached.m_completed);
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationChallengeParticipationStartedParsing)
|
|
{
|
|
//{
|
|
// "notificationType": " CLUB_CHALLENGE_PARTICIPATION",
|
|
// "sourceApplicationId" : "string",
|
|
// "sourceProfileId": "string",
|
|
// "spaceId" : "string",
|
|
// "datePosted" : "string"
|
|
// "content" :
|
|
// {
|
|
// "challengeId": "guid",
|
|
// "type" "string" // possible values are "Player", "Community"
|
|
// }
|
|
//}
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_CHALLENGE_PARTICIPATION"));
|
|
|
|
JsonWriter contentWriter;
|
|
contentWriter["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
contentWriter["type"] = "Player";
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
|
|
JsonWriter thresholdsWriter(JsonWriterType::Array);
|
|
thresholdsWriter.addItemToArray(1000.0);
|
|
contentWriter["thresholds"] = thresholdsWriter.getJson();
|
|
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
NotificationChallengeParticipationStarted notificationValid;
|
|
EXPECT_TRUE(notificationValid.parseContent(writer.renderContent())) << "Parsing should be valid";
|
|
|
|
{ // Challenge Id Checks
|
|
writer["content"]["challengeId"] = "INVALID";
|
|
NotificationChallengeParticipationStarted notificationChallengeId;
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"].setToNull();
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(ChallengeId("3333cccc-3333-cccc-2222-cccc3333cccc"), notificationChallengeId.m_challengeId);
|
|
}
|
|
|
|
{ // Type Checks
|
|
writer["content"]["type"] = "INVALID";
|
|
NotificationChallengeParticipationStarted notificationType;
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"].setToNull();
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"] = "player";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("profile", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Profile, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "community";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("community", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Community, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "season";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("season", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Season, notificationType.m_category);
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationChallengeCompletedParsing)
|
|
{
|
|
//{
|
|
// "notificationType": "CLUB_CHALLENGE_COMPLETED",
|
|
// "sourceApplicationId" : "string",
|
|
// "sourceProfileId": "string",
|
|
// "spaceId" : "string",
|
|
// "datePosted" : "string"
|
|
// "content" :
|
|
// {
|
|
// "challengeId": "guid",
|
|
// "progression": decimal,
|
|
// "type" "string" // possible values are "Player", "Community"
|
|
// }
|
|
//}
|
|
|
|
JsonWriter writer(renderNotificationPlayerJson("CLUB_CHALLENGE_COMPLETED"));
|
|
|
|
JsonWriter contentWriter;
|
|
contentWriter["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
contentWriter["type"] = "Player";
|
|
contentWriter["progression"] = 123.123f;
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
NotificationChallengeCompleted notificationValid;
|
|
EXPECT_TRUE(notificationValid.parseContent(writer.renderContent())) << "Parsing should be valid";
|
|
|
|
{ // Challenge Id Checks
|
|
writer["content"]["challengeId"] = "INVALID";
|
|
NotificationChallengeCompleted notificationChallengeId;
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"].setToNull();
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["challengeId"] = "3333cccc-3333-cccc-2222-cccc3333cccc";
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(ChallengeId("3333cccc-3333-cccc-2222-cccc3333cccc"), notificationChallengeId.m_challengeId);
|
|
}
|
|
|
|
{ // Type Checks
|
|
writer["content"]["type"] = "INVALID";
|
|
NotificationChallengeCompleted notificationType;
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"].setToNull();
|
|
EXPECT_FALSE(notificationType.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["type"] = "player";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("profile", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Profile, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "community";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("community", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Community, notificationType.m_category);
|
|
|
|
writer["content"]["type"] = "season";
|
|
EXPECT_TRUE(notificationType.parseContent(writer.renderContent()));
|
|
EXPECT_STRCASEEQ("season", notificationType.m_categoryText.getUtf8());
|
|
EXPECT_EQ(ClubNotificationCategory::Season, notificationType.m_category);
|
|
}
|
|
|
|
{ // Progression Checks
|
|
writer["content"]["progression"] = "INVALID";
|
|
NotificationChallengeCompleted notificationChallengeId;
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["progression"].setToNull();
|
|
EXPECT_FALSE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
|
|
writer["content"]["progression"] = 123;
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(123, notificationChallengeId.m_progression);
|
|
|
|
writer["content"]["progression"] = 123.123f;
|
|
EXPECT_TRUE(notificationChallengeId.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(123.123f, notificationChallengeId.m_progression);
|
|
}
|
|
}
|
|
#if defined(US_SDK_FULL)
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationInstancesUpdateParsing)
|
|
{
|
|
//{
|
|
// "notificationType": "SSI_INSTANCES_UPDATE",
|
|
// "sourceApplicationId" : "string",
|
|
// "sourceProfileId" : "string",
|
|
// "spaceId" : "string",
|
|
// "datePosted" : "string"
|
|
// "content" :
|
|
// {
|
|
// "transactionPartNumber": integer,
|
|
// "transactionPartCount" : integer,
|
|
// "instances" :
|
|
// [
|
|
// {
|
|
// "instanceId": "string",
|
|
// "itemId" : "string",
|
|
// "revision" : "int",
|
|
// "attributes" : {},
|
|
// "obj" : {},
|
|
// "lastModified" : "string"
|
|
// "expirationDate" : "string"
|
|
// "action" : "string"
|
|
// }
|
|
// ]
|
|
// }
|
|
//}
|
|
|
|
// add the common notification player fields
|
|
JsonWriter writer(renderNotificationPlayerJson("SSI_INSTANCES_UPDATE"));
|
|
|
|
// add the content, which is specific for each player notification
|
|
JsonWriter contentWriter;
|
|
{
|
|
contentWriter["transactionPartNumber"] = TestNotificationInstancesUpdate_BF::PART_NUMBER;
|
|
contentWriter["transactionPartCount"] = TestNotificationInstancesUpdate_BF::PART_COUNT;
|
|
JsonWriter instanceWriter;
|
|
{
|
|
instanceWriter["instanceId"] = TestNotificationInstancesUpdate_BF::INSTANCE_ID;
|
|
instanceWriter["itemId"] = TestNotificationInstancesUpdate_BF::ITEM_ID;
|
|
JsonWriter attributesWriter;
|
|
{
|
|
attributesWriter["key1"] = "value1";
|
|
attributesWriter["key2"] = "value2";
|
|
}
|
|
instanceWriter["attributes"] = attributesWriter.getJson();
|
|
JsonWriter objWriter;
|
|
{
|
|
objWriter["key3"] = "value3";
|
|
objWriter["key4"] = "value4";
|
|
}
|
|
instanceWriter["obj"] = objWriter.getJson();
|
|
instanceWriter["lastModified"] = DateTimeHelper::formatDateISO8601(TestNotificationInstancesUpdate_BF::LAST_MODIFIED);
|
|
instanceWriter["expirationDate"] = DateTimeHelper::formatDateISO8601(TestNotificationInstancesUpdate_BF::EXPIRATION_DATE);
|
|
instanceWriter["action"] = TestNotificationInstancesUpdate_BF::INSTANCE_ACTION;
|
|
}
|
|
contentWriter["instances"].addItemToArray(instanceWriter.getJson());
|
|
contentWriter["extraField"] = "Should be able to parse with extra field";
|
|
}
|
|
writer["content"] = contentWriter.getJson();
|
|
|
|
{
|
|
NotificationInstancesUpdate notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent())) << "Parsing should be successful";
|
|
// check only the notification content, not the common notification player fields
|
|
checkNotificationContent(notification);
|
|
}
|
|
|
|
// Check invalid or null field parsing
|
|
{
|
|
// check notification content fields
|
|
{
|
|
JsonWriter fieldWriter(writer["content"]);
|
|
const Vector<const char *> integerFields =
|
|
{
|
|
"transactionPartNumber",
|
|
"transactionPartCount",
|
|
};
|
|
for (auto field : integerFields)
|
|
{
|
|
checkField<NotificationInstancesUpdate, int32>(field, writer, fieldWriter);
|
|
}
|
|
}
|
|
// check notification instances fields
|
|
{
|
|
JsonWriter fieldWriter(writer["content"]["instances"].getJson().getItems().at(0));
|
|
|
|
// string fields
|
|
const Vector<const char *> stringFields =
|
|
{
|
|
"instanceId",
|
|
"itemId",
|
|
"lastModified",
|
|
"expirationDate",
|
|
"action"
|
|
};
|
|
for (auto field : stringFields)
|
|
{
|
|
checkFieldBestEffort<NotificationInstancesUpdate, String>(field, writer, fieldWriter);
|
|
}
|
|
|
|
// object fields
|
|
const Vector<const char *> objFields =
|
|
{
|
|
"attributes",
|
|
"obj"
|
|
};
|
|
for (auto field : objFields)
|
|
{
|
|
checkFieldBestEffort<NotificationInstancesUpdate, Json>(field, writer, fieldWriter);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_SDK_FULL)
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedParsing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent()));
|
|
|
|
EXPECT_EQ(SeasonId(TestBattlepass_BF::TIER_BANKED_SEASON_ID), notification.m_seasonId);
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_TIER_COUNT, notification.m_tiers.size());
|
|
|
|
uint8 i = 0; //counter
|
|
for (auto &tier : notification.m_tiers)
|
|
{
|
|
EXPECT_EQ(TestBattlepass_BF::TIER_BANKED_TIERS_VALUES[i], tier.m_tier);
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_REWARDS_COUNT, tier.m_rewards.size());
|
|
uint8 j = 0; //counter
|
|
for (auto &rewards : tier.m_rewards)
|
|
{
|
|
EXPECT_EQ(TestBattlepass_BF::TIER_BANKED_REWARDS_ITEMIDS[j], rewards.m_itemId);
|
|
EXPECT_EQ(TestBattlepass_BF::TIER_BANKED_REWARDS_QUANTITY[j], rewards.m_quantity);
|
|
EXPECT_EQ(TestBattlepass_BF::TIER_BANKED_REWARDS_TRACKS[j], rewards.m_trackType);
|
|
EXPECT_EQ(TestBattlepass_BF::TIER_BANKED_REWARDS_TRACKS_TEXT[j], rewards.m_trackTypeText);
|
|
++j;
|
|
}
|
|
++i;
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedSeasonIdMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"].RemoveMember("seasonId");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_FALSE(notification.parseContent(testJson.renderContent()));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedSeasonIdWrongFormat)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["seasonId"].SetString("seasonId");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_FALSE(notification.parseContent(testJson.renderContent()));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedTiersMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"].RemoveMember("tiers");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_FALSE(notification.parseContent(testJson.renderContent()));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedOneTierMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0].RemoveMember("tier");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_TIER_COUNT-1, notification.m_tiers.size()); //TIERS_TIER_COUNT-1 because one of the tier is invalid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedRewardsMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0].RemoveMember("rewards");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_TIER_COUNT - 1, notification.m_tiers.size()); //TIERS_TIER_COUNT-1 because one of the tier is invalid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedAllRewardsMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0].RemoveMember("rewards");
|
|
document["content"]["tiers"][1].RemoveMember("rewards");
|
|
document["content"]["tiers"][2].RemoveMember("rewards");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(0, notification.m_tiers.size()); //0 because none of the tier is valid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedRewardsItemIdMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0]["rewards"][0].RemoveMember("itemId");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_REWARDS_COUNT - 1, notification.m_tiers[0].m_rewards.size()); //TIERS_REWARDS_COUNT-1 because one of the reward is invalid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedRewardsQuantityMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0]["rewards"][0].RemoveMember("quantity");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_REWARDS_COUNT - 1, notification.m_tiers[0].m_rewards.size()); //TIERS_REWARDS_COUNT-1 because one of the reward is invalid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedRewardsTrackMissing)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0]["rewards"][0].RemoveMember("track");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(TestBattlepass_BF::TIERS_REWARDS_COUNT - 1, notification.m_tiers[0].m_rewards.size()); //TIERS_REWARDS_COUNT-1 because one of the reward is invalid
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationTiersBankedRewardsTrackWrongValue)
|
|
{
|
|
const Json jsonData = TestBattlepass_BF::getMockNotificationTiersBanked();
|
|
|
|
// Create RapidJson Document to manipulate Json
|
|
// Ex: Change value, remove field, set field to null, ...
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(jsonData.renderContent().getUtf8());
|
|
document["content"]["tiers"][0]["rewards"][0]["track"].SetString("track");
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
const Json testJson(TestJsonHelper::getJson(document));
|
|
|
|
NotificationTiersBanked notification;
|
|
EXPECT_TRUE(notification.parseContent(testJson.renderContent())); // BEST EFFORT
|
|
EXPECT_EQ(NotificationRewardTrackType::Unknown, notification.m_tiers[0].m_rewards[0].m_trackType);
|
|
EXPECT_EQ("track", notification.m_tiers[0].m_rewards[0].m_trackTypeText);
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(1u, 1u, testCount);
|
|
}
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationFriendRelationshipUpdateParsingSuccessful)
|
|
{
|
|
//{
|
|
// "notificationType": "FRIENDS_RELATIONSHIP_UPDATE",
|
|
// "sourceApplicationId" : "string",
|
|
// "sourceProfileId" : "string",
|
|
// "spaceId" : "string",
|
|
// "datePosted" : "string"
|
|
// "content" :
|
|
// {
|
|
// "lastModified": string,
|
|
// "fromProfileId": string,
|
|
// "state": { NoRelationship, PendingReceivedInvite, Friends}
|
|
// }
|
|
//}
|
|
JsonWriter writer(TestNotificationFriendRelationshipUpdate_BF::renderNotification());
|
|
|
|
NotificationFriendRelationshipUpdate notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
|
|
// check only the notification content.
|
|
// the notification player common fields (sourceApplicationId, sourceProfileId, spaceId, datePosted)
|
|
// are not parsed because they are not useful to the game.
|
|
TestNotificationFriendRelationshipUpdate_BF::checkNotificationContent(notification);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationFriendRelationshipUpdateNotificationTypeInvalid)
|
|
{
|
|
JsonWriter writer(TestNotificationFriendRelationshipUpdate_BF::renderNotification());
|
|
|
|
// Check invalid or null for "notificationType"
|
|
const char * field = "notificationType";
|
|
checkField<NotificationFriendRelationshipUpdate, String>(field, writer, writer);
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationFriendRelationshipUpdateStringFieldsInvalid)
|
|
{
|
|
JsonWriter writer(TestNotificationFriendRelationshipUpdate_BF::renderNotification());
|
|
|
|
// Check invalid or null for the string content fields
|
|
JsonWriter fieldWriter(writer["content"]);
|
|
const Vector<const char *> stringFields = { "lastModified" , "fromProfileId" };
|
|
for (auto field : stringFields)
|
|
{
|
|
checkField<NotificationFriendRelationshipUpdate, String>(field, writer, fieldWriter);
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_NOTIFICATION, LOCAL_NotificationFriendRelationshipUpdateStateFieldInvalid)
|
|
{
|
|
JsonWriter writer(TestNotificationFriendRelationshipUpdate_BF::renderNotification());
|
|
|
|
// Check invalid or null for "state"
|
|
writer["content"]["state"] = "INVALID";
|
|
NotificationFriendRelationshipUpdate notification;
|
|
EXPECT_TRUE(notification.parseContent(writer.renderContent()));
|
|
EXPECT_EQ(FriendInfoClub::Relationship::Unknown, notification.m_relationshipState);
|
|
|
|
writer["content"]["state"].setToNull();
|
|
EXPECT_FALSE(notification.parseContent(writer.renderContent()));
|
|
}
|
|
#endif //US_SDK_FULL
|
|
#endif
|
|
};
|