JD2022-TU1/main/extern/UbiServices/custom/testsIntegration/testUserGeneratedContentsClient.cpp

919 lines
42 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour Group //
////////////////////////////////////////////////////////////////////////////////
#include "tests/common/helpers.h"
#include "tests/config.h"
#include "tests/fixture/authenticationFixture.h"
#include "tests/fixture/loginMockFixture.h"
#include "tests/mock/mockResultHelper.h"
#include "tests/mock/parametersMockHelper.h"
#include <ubiservices/core/types/dateTimeHelper.h>
#include <ubiservices/facade.h>
#include <ubiservices/services/http/request/httpGet.h>
#include <ubiservices/services/userGeneratedContents/ugcConfigs.h>
#include <ubiservices/services/userGeneratedContents/ugcContentId.h>
#include <ubiservices/services/userGeneratedContents/ugcFavorites.h>
#include "ubiservices/services/userGeneratedContents/ugcSortingBy.h"
#include <ubiservices/services/userGeneratedContents/ugcTypeId.h>
#include <ubiservices/services/userGeneratedContents/userGeneratedContentsClient.h>
#include <regex>
namespace US_NS {;
US_DEFINE_TEST(TestUserGeneratedContentsClient);
#if !defined(US_DLL)
#if defined(US_TARGET_WINDOWS)
/// Tests that are profileId related and not mocked use specifically ussdk001, on Windows, to avoid replicating the ugc setup on all test accounts.
template<uint32 facadesCount = 1, bool executeLogin = false>
class AuthenticationFixtureUgcLoginAsUssdk001 : public AuthenticationFixture < facadesCount, executeLogin >
{
public:
AuthenticationFixtureUgcLoginAsUssdk001()
: AuthenticationFixture<facadesCount, executeLogin>()
{
}
private:
virtual void SetUp() override
{
AuthenticationFixture<facadesCount, executeLogin>::SetUp();
const String commonTestUserEmail = "ussdk001@ubisoft.com"; // ussdk001 is used to avoid replicating the ugc setup on new PC test accounts.
const String commonTestUserPassword = "a1234567";
const PlayerCredentials credentials(commonTestUserEmail, commonTestUserPassword);
ASSERT_TRUE(AsyncHelper::waitSuccess(getFacade().createSession(credentials, {}, {})));
}
};
#endif
using UGC = AuthenticationFixture<1>;
using UGC_NOLOGIN = AuthenticationFixture<1, false>;
using UGC_MOCK = LoginMockFixture<true>;
#if defined(US_TARGET_WINDOWS)
#if defined(US_SDK_TEST_CHINA)
using UGC_USSDK001 = AuthenticationFixture<1>;
#else
using UGC_USSDK001 = AuthenticationFixtureUgcLoginAsUssdk001<>;
#endif // US_SDK_TEST_CHINA
#endif // US_TARGET_WINDOWS
namespace TestUserGeneratedContentsClientUnit_BF
{
Json getExternalVideos();
void validateExternalVideo(const UgcExternalVideo& externalVideo);
Json getUgcConfigs();
void validateUgcConfigs(const Map<UgcTypeId, Map<UgcCategoryId, UgcMainCategory>>& config);
Json getRatings();
void validateRatings(const Map<UgcContentId, UgcRatingValue>& ratings);
Json getFavorites();
void validateFavorites(const Vector<UgcContentId>& favorites);
extern const char* CONFIG_CATEGORY_ID_ONE;
extern const char* CONFIG_CATEGORY_DISPLAY_NAME_ONE;
extern const char* CONFIG_SUBCATEGORY_ID_ONE_ONE;
extern const char* CONFIG_SUBCATEGORY_DISPLAY_NAME_ONE_ONE;
}
namespace TestUserGeneratedContentsClient_BF
{
const uint16 SEARCH_FILTER_TITLE_MIN_LENGTH = 3;
const uint16 MAX_GUIDS_IN_URL = 50;
const char* DUMMY_GUID = "11111111-2222-3333-4444-555566667777";
const char* CONTENT_ID_EXTERNAL_VIDEO = "09ec0d99-627f-4120-80f7-583d4fed1d0c";
const char* CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING = "e9024fd4-8689-4195-94e9-13e9be304745";
const char* CONTENT_ID_EXTERNAL_VIDEO_MOST_FAVORITES = "c040458c-2ae1-4897-a7be-df6a9a8d76d4";
const char* CONTENT_ID_EXTERNAL_VIDEO_SPECIFIC_PROVIDER = "a4bba8cb-f3d4-48f7-84da-09e0f3f4b150";
}
/////// searchExternalVideos
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test Checks a simple search for external videos, real call to service
/// @note This test presumes at least one external video exists in the account used for testing.
TEST_F(UGC_USSDK001, US_MINRUN_UgcSearchExternalVideos)
{
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos();
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#if !defined(US_SDK_TEST_CHINA)
ASSERT_GT(result.getResult().size(), 0u);
#endif
}
TEST_F(UGC_USSDK001, US_UgcSearchExternalVideosHighestRating)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_order = UgcSortingBy::HighestRating;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
Vector<UgcExternalVideo> externalVideos = result.getResult();
ASSERT_GT(externalVideos.size(), 0u);
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING, externalVideos.front().m_contentId);
}
TEST_F(UGC_USSDK001, US_UgcSearchExternalVideosMostFavorites)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_order = UgcSortingBy::MostFavorites;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
Vector<UgcExternalVideo> externalVideos = result.getResult();
ASSERT_GT(externalVideos.size(), 0u);
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO_MOST_FAVORITES, externalVideos.front().m_contentId);
}
// note: sorting by MostRecent and MostViews are not tested as it's difficult to set up a test environment for those.
TEST_F(UGC_USSDK001, US_UgcSearchExternalVideosSpecificProvider)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_providers = { "specificprovider" };
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
Vector<UgcExternalVideo> externalVideos = result.getResult();
ASSERT_EQ(1, externalVideos.size());
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO_SPECIFIC_PROVIDER, externalVideos.front().m_contentId);
}
#endif
/// @test Checks a simple search for external videos
TEST_F(UGC_MOCK, USNOT_UgcSearchExternalVideosValidJsonResponse)
{
setupDebugLogging();
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
std::cout << "getExternalVideos: " << getExternalVideos().renderContent() << std::endl;
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
}
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos();
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
Vector<UgcExternalVideo> externalVideos = result.getResult();
EXPECT_EQ(1, externalVideos.size());
validateExternalVideo(externalVideos.front());
}
/// @test Checks behavior when receiving invalid json
TEST_F(UGC_MOCK, USNOT_UgcSearchExternalVideosInvalidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const String invalidJsonResponse = getExternalVideos().renderContent() + "}";
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(invalidJsonResponse);
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
}
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::CORE_INVALID_JSON_FORMAT));
}
/// @test Checks the behavior when title search filter is too short.
TEST_F(UGC_MOCK, USNOT_UgcSearchExternalVideosTitleTooShort)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
const String titleLongEnough = "aaa";
const String titleTooShort = "aa";
ASSERT_GE(titleLongEnough.getLength(), SEARCH_FILTER_TITLE_MIN_LENGTH);
ASSERT_LT(titleTooShort.getLength(), SEARCH_FILTER_TITLE_MIN_LENGTH);
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_title = titleLongEnough;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_title = titleTooShort;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TITLE_SEARCH_FILTER_TOO_SHORT));
}
}
/// @test Checks behavior when too many guids are used in searchFilter
TEST_F(UGC_MOCK, USNOT_UgcSearchExternalVideosTooManyGuids)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{ // 50 contentIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_contentIds.resize(MAX_GUIDS_IN_URL);
std::fill(searchFilter.m_contentIds.begin(), searchFilter.m_contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 51 contentIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_contentIds.resize(MAX_GUIDS_IN_URL + 1);
std::fill(searchFilter.m_contentIds.begin(), searchFilter.m_contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
{ // 50 profileIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_profilesIds.resize(MAX_GUIDS_IN_URL);
std::fill(searchFilter.m_profilesIds.begin(), searchFilter.m_profilesIds.end(), ProfileId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 51 profileIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_profilesIds.resize(MAX_GUIDS_IN_URL + 1);
std::fill(searchFilter.m_profilesIds.begin(), searchFilter.m_profilesIds.end(), ProfileId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
const uint16 HALF_MAX_GUIDS_IN_URL = MAX_GUIDS_IN_URL / 2;
ASSERT_EQ(MAX_GUIDS_IN_URL, HALF_MAX_GUIDS_IN_URL * 2); // supposing MAX_GUIDS_IN_URL will probably always be even.
{ // 25 contentIds + 25 profileIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_contentIds.resize(HALF_MAX_GUIDS_IN_URL);
std::fill(searchFilter.m_contentIds.begin(), searchFilter.m_contentIds.end(), UgcContentId(DUMMY_GUID));
searchFilter.m_profilesIds.resize(HALF_MAX_GUIDS_IN_URL);
std::fill(searchFilter.m_profilesIds.begin(), searchFilter.m_profilesIds.end(), ProfileId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 25 contentIds + 26 profileIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_contentIds.resize(HALF_MAX_GUIDS_IN_URL);
std::fill(searchFilter.m_contentIds.begin(), searchFilter.m_contentIds.end(), UgcContentId(DUMMY_GUID));
searchFilter.m_profilesIds.resize(HALF_MAX_GUIDS_IN_URL + 1);
std::fill(searchFilter.m_profilesIds.begin(), searchFilter.m_profilesIds.end(), ProfileId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
}
/// @test Checks behavior when limit is set too high in searchFilter
TEST_F(UGC_MOCK, USNOT_UgcSearchExternalVideosLimitTooHigh)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
const uint16 MAX_LIMIT = 50;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_resultRange.m_limit = MAX_LIMIT;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
UgcSearchFilterExternalVideos searchFilter;
searchFilter.m_resultRange.m_limit = MAX_LIMIT + 1;
AsyncResult<Vector<UgcExternalVideo>> result = client.searchExternalVideos(searchFilter);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_INVALID_PARAM));
}
}
/////// requestExternalVideos
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test simple content request
TEST_F(UGC_USSDK001, US_MINRUN_UgcRequestExternalVideos)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<Vector<UgcExternalVideo>> result = client.requestExternalVideos({ UgcContentId(CONTENT_ID_EXTERNAL_VIDEO) });
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#if !defined(US_SDK_TEST_CHINA)
const Vector<UgcExternalVideo>& contents = result.getResult();
EXPECT_EQ(1, contents.size());
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO, contents.front().m_contentId);
#endif
}
#endif
/// @test checks behavior when too many contentIds are passed in parameter
TEST_F(UGC_MOCK, US_UgcRequestExternalVideosTooManyGuids)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{ // 50 contentIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getExternalVideos().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos", mockResult);
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.requestExternalVideos(contentIds);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 51 contentIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/ugc/mock-externalvideos");
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL + 1);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcExternalVideo>> result = client.requestExternalVideos(contentIds);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
}
/////// requestConfigs
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test get configs without parameter, real call
TEST_F(UGC_USSDK001, US_MINRUN_UgcGetConfigsDefaultParam)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<UgcConfigs> result = client.requestConfigs();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
#if !defined(US_SDK_TEST_CHINA)
const UgcConfigs& configs = result.getResult();
auto typeIter = configs.find(UgcTypeId::ExternalVideo);
ASSERT_TRUE(typeIter != configs.end());
auto categoryIter = typeIter->second.find("travelsId");
EXPECT_TRUE(categoryIter != typeIter->second.end());
#endif
}
# endif // if defined(US_TARGET_WINDOWS)
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test get configs specifying externalvideo type, real call
TEST_F(UGC_USSDK001, US_UgcGetConfigsParamTypeExternalVideos)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<UgcConfigs> result = client.requestConfigs({ UgcTypeId::ExternalVideo });
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const UgcConfigs& configs = result.getResult();
EXPECT_TRUE(configs.size() == 1);
EXPECT_TRUE(configs.find(UgcTypeId::ExternalVideo) != configs.end());
}
# endif // if defined(US_TARGET_WINDOWS)
/// @test checks simple call and parsing
TEST_F(UGC_MOCK, US_UgcGetConfigsValidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getUgcConfigs().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/spaces/" + getFacade().getWorkingSpaceId() + "/mock-configs/ugc", mockResult);
}
AsyncResult<UgcConfigs> result = client.requestConfigs();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
validateUgcConfigs(result.getResult());
}
/// @test Checks behavior when receiving invalid json
TEST_F(UGC_MOCK, US_UgcGetConfigsInvalidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const String invalidJsonResponse = getUgcConfigs().renderContent() + "}";
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(invalidJsonResponse);
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/spaces/" + getFacade().getWorkingSpaceId() + "/mock-configs/ugc", mockResult);
}
AsyncResult<UgcConfigs> result = client.requestConfigs();
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::CORE_INVALID_JSON_FORMAT));
}
/// @test Checks the helper method to retrieve displayNames based on category and subCategory ids
TEST_F(UGC_MOCK, US_UgcGetCategoriesDisplayNames)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getUgcConfigs().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/spaces/" + getFacade().getWorkingSpaceId() + "/mock-configs/ugc", mockResult);
}
AsyncResult<UgcConfigs> result = client.requestConfigs();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const UgcConfigs& configs = result.getResult();
UgcCategoryIds categoryIds;
categoryIds.m_mainCategoryId = CONFIG_CATEGORY_ID_ONE;
categoryIds.m_subCategoryId = CONFIG_SUBCATEGORY_ID_ONE_ONE;
UgcCategoryDisplayNames displaynames = client.getCategoryDisplayNames(UgcTypeId::ExternalVideo, categoryIds, configs);
EXPECT_EQ(CONFIG_CATEGORY_DISPLAY_NAME_ONE, displaynames.m_mainCategoryDisplayName);
EXPECT_EQ(CONFIG_SUBCATEGORY_DISPLAY_NAME_ONE_ONE, displaynames.m_subCategoryDisplayName);
}
/////// requestRatings
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks that the request succeeds with default params
TEST_F(UGC_USSDK001, US_MINRUN_UgcRequestRatingsDefaultParams)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
#if !defined(US_SDK_TEST_CHINA)
const Map<UgcContentId, UgcRatingValue>& ratings = result.getResult();
EXPECT_GT(ratings.size(), 0);
const auto& iterRatings = ratings.find(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING));
EXPECT_TRUE(iterRatings != ratings.end());
EXPECT_EQ(UgcRatingValue::Like, iterRatings->second);
#endif
}
# endif // if defined(US_TARGET_WINDOWS)
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks that the request succeeds when requesting rating for a specific UgcContentId
TEST_F(UGC_USSDK001, US_UgcRequestRatingsForSpecificUgcContentId)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings({UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING)});
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Map<UgcContentId, UgcRatingValue>& ratings = result.getResult();
EXPECT_EQ(1, ratings.size());
const auto& iterRatings = ratings.find(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING));
EXPECT_TRUE(iterRatings != ratings.end());
EXPECT_EQ(UgcRatingValue::Like, iterRatings->second);
}
# endif // if defined(US_TARGET_WINDOWS)
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks that the request succeeds when giving a specific ProfileId
TEST_F(UGC_USSDK001, US_UgcRequestRatingsForSpecificProfileId)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings({}, profileId);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Map<UgcContentId, UgcRatingValue>& ratings = result.getResult();
EXPECT_GT(ratings.size(), 0);
const auto& iterRatings = ratings.find(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_HIGHEST_RATING));
EXPECT_TRUE(iterRatings != ratings.end());
EXPECT_EQ(UgcRatingValue::Like, iterRatings->second);
}
# endif // if defined(US_TARGET_WINDOWS)
/// @test Checks the parsing for a valid json response
TEST_F(UGC_MOCK, US_UgcRequestRatingsValidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getRatings().renderContent());
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-ratings", mockResult);
}
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Map<UgcContentId, UgcRatingValue>& ratings = result.getResult();
validateRatings(ratings);
}
/// @test Checks the parsing for an invalid json response
TEST_F(UGC_MOCK, US_UgcRequestRatingsInvalidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult invalidMockResult = MockResultHelper::createSuccessResult(getRatings().renderContent() + "}");
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-ratings", invalidMockResult);
}
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings();
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::CORE_INVALID_JSON_FORMAT));
}
/// @test checks behavior when too many contentIds are passed in parameter
TEST_F(UGC_MOCK, US_UgcRequestRatingsTooManyGuids)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
{ // 50 contentIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getRatings().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-ratings", mockResult);
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings(contentIds);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 51 contentIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-ratings");
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL + 1);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Map<UgcContentId, UgcRatingValue>> result = client.requestRatings(contentIds);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
}
/////// updateRating
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks that the update succeeds with each value
TEST_F(UGC_USSDK001, US_UgcUpdateRating)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const UgcContentId contentId(CONTENT_ID_EXTERNAL_VIDEO);
{
const UgcRatingValue ratingValue = UgcRatingValue::NoRating;
AsyncResult<Empty> resultUpdateRating = client.updateRating(contentId, ratingValue);
EXPECT_TRUE(AsyncHelper::waitSuccess(resultUpdateRating));
AsyncResult<Map<UgcContentId, UgcRatingValue>> resultRequestRatings = client.requestRatings({contentId});
EXPECT_TRUE(AsyncHelper::waitSuccess(resultRequestRatings));
const Map<UgcContentId, UgcRatingValue>& ratings = resultRequestRatings.getResult();
EXPECT_TRUE(ratings.empty());
}
{
const UgcRatingValue ratingValue = UgcRatingValue::Dislike;
AsyncResult<Empty> resultUpdateRating = client.updateRating(contentId, ratingValue);
EXPECT_TRUE(AsyncHelper::waitSuccess(resultUpdateRating));
AsyncResult<Map<UgcContentId, UgcRatingValue>> resultRequestRatings = client.requestRatings({ contentId });
EXPECT_TRUE(AsyncHelper::waitSuccess(resultRequestRatings));
const Map<UgcContentId, UgcRatingValue>& ratings = resultRequestRatings.getResult();
const auto iterContentId = ratings.find(contentId);
EXPECT_TRUE(iterContentId != ratings.end());
EXPECT_TRUE(iterContentId->second == ratingValue);
}
{
const UgcRatingValue ratingValue = UgcRatingValue::Like;
AsyncResult<Empty> resultUpdateRating = client.updateRating(contentId, ratingValue);
EXPECT_TRUE(AsyncHelper::waitSuccess(resultUpdateRating));
AsyncResult<Map<UgcContentId, UgcRatingValue>> resultRequestRatings = client.requestRatings({ contentId });
EXPECT_TRUE(AsyncHelper::waitSuccess(resultRequestRatings));
const Map<UgcContentId, UgcRatingValue>& ratings = resultRequestRatings.getResult();
const auto iterContentId = ratings.find(contentId);
EXPECT_TRUE(iterContentId != ratings.end());
EXPECT_TRUE(iterContentId->second == ratingValue);
}
{
const UgcRatingValue ratingValue = UgcRatingValue::NoRating;
AsyncResult<Empty> resultUpdateRating = client.updateRating(contentId, ratingValue);
EXPECT_TRUE(AsyncHelper::waitSuccess(resultUpdateRating));
AsyncResult<Map<UgcContentId, UgcRatingValue>> resultRequestRatings = client.requestRatings({ contentId });
EXPECT_TRUE(AsyncHelper::waitSuccess(resultRequestRatings));
const Map<UgcContentId, UgcRatingValue>& ratings = resultRequestRatings.getResult();
EXPECT_TRUE(ratings.empty());
}
}
# endif // if defined(US_TARGET_WINDOWS)
/////// requestFavorites
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks a simple request without params
TEST_F(UGC_USSDK001, US_MINRUN_UgcRequestFavoritesDefaultParams)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const AsyncResult<Vector<UgcContentId>> result = client.requestFavorites();
AsyncHelper::waitSuccess(result);
#if !defined(US_SDK_TEST_CHINA)
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_GT(favorites.size(), 0);
const UgcContentId contentIdMostFavorites = UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_MOST_FAVORITES);
EXPECT_TRUE(std::any_of(favorites.begin(), favorites.end(), [&contentIdMostFavorites](const UgcContentId& contentId) {return contentId == contentIdMostFavorites; }));
#endif
}
# endif // if defined(US_TARGET_WINDOWS)
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks success when specifying a contentId
TEST_F(UGC_USSDK001, US_UgcRequestFavoritesSpecificUgcContentId)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const UgcContentId contentIdMostFavorites = UgcContentId(CONTENT_ID_EXTERNAL_VIDEO_MOST_FAVORITES);
const AsyncResult<Vector<UgcContentId>> result = client.requestFavorites({ contentIdMostFavorites });
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_EQ(1, favorites.size());
EXPECT_EQ(contentIdMostFavorites, favorites.front());
}
# endif // if defined(US_TARGET_WINDOWS)
/// @test Checks the parsing for a valid json response
TEST_F(UGC_MOCK, US_UgcRequestFavoritesValidJsonResponse)
{
setupDebugLogging();
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getFavorites().renderContent());
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-favorites", mockResult);
}
AsyncResult<Vector<UgcContentId>> result = client.requestFavorites();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_EQ(1, favorites.size());
validateFavorites(favorites);
}
/// @test Checks the behavior when receiving an invalid json response
TEST_F(UGC_MOCK, US_UgcRequestFavoritesInvalidJsonResponse)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
String invalidJson = getFavorites().renderContent() + "}";
{
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(invalidJson);
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-favorites", mockResult);
}
AsyncResult<Vector<UgcContentId>> result = client.requestFavorites();
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::CORE_INVALID_JSON_FORMAT));
}
/// @test checks behavior when too many contentIds are passed in parameter
TEST_F(UGC_MOCK, US_UgcRequestFavoritesTooManyGuids)
{
using namespace TestUserGeneratedContentsClient_BF;
using namespace TestUserGeneratedContentsClientUnit_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
const ProfileId& profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
{ // 50 contentIds
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(getFavorites().renderContent());
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-favorites", mockResult);
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcContentId>> result = client.requestFavorites(contentIds);
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // 51 contentIds
US_EXPECT_NO_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "/profiles/" + profileId + "/ugc/mock-favorites");
Vector<UgcContentId> contentIds(MAX_GUIDS_IN_URL + 1);
std::fill(contentIds.begin(), contentIds.end(), UgcContentId(DUMMY_GUID));
AsyncResult<Vector<UgcContentId>> result = client.requestFavorites(contentIds);
EXPECT_TRUE(AsyncHelper::waitFailure(result, Errors::UGC_TOO_MANY_IDS));
}
}
/////// updateFavoriteStatus
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks behavior when specifying a contentId
TEST_F(UGC_USSDK001, US_UgcUpdateFavoriteStatusAllValues)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{
const AsyncResult<Empty> result = client.updateFavoriteStatus(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), UgcFavoriteStatus::Favorite);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{
const AsyncResult<Empty> result = client.updateFavoriteStatus(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), UgcFavoriteStatus::NotFavorite);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{
const AsyncResult<Empty> result = client.updateFavoriteStatus(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), UgcFavoriteStatus::NotFavorite);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
}
# endif // if defined(US_TARGET_WINDOWS)
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks correct behavior with several cases of updateFavorites
TEST_F(UGC_USSDK001, US_UgcRequestAndUpdateFavorites)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
{ // Setting an external video as favorite
const AsyncResult<Empty> result = client.updateFavoriteStatus(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), UgcFavoriteStatus::Favorite);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // requesting favorites specifying the previous contentId, the result should contain just this content.
const AsyncResult<Vector<UgcContentId>> result = client.requestFavorites({ UgcContentId(CONTENT_ID_EXTERNAL_VIDEO) });
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_EQ(1, favorites.size());
EXPECT_EQ(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), favorites[0]);
}
{ // requesting favorites specifying a dummy contentId, the result shouldn't contain the external video that has just been added to favorites.
const AsyncResult<Vector<UgcContentId>> result = client.requestFavorites({ UgcContentId(DUMMY_GUID) });
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_TRUE(favorites.empty());
}
{ // Setting the external video back to NotFavorite
const AsyncResult<Empty> result = client.updateFavoriteStatus(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO), UgcFavoriteStatus::NotFavorite);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{ // requesting favorites specifying the first contentId, the result shouldn't contain anything as the content has been removed from favorites.
const AsyncResult<Vector<UgcContentId>> result = client.requestFavorites({ UgcContentId(CONTENT_ID_EXTERNAL_VIDEO) });
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcContentId>& favorites = result.getResult();
EXPECT_TRUE(favorites.empty());
}
}
# endif // if defined(US_TARGET_WINDOWS)
/////// incrementViews
# if defined(US_TARGET_WINDOWS) // tests that are profileId related are run only on Windows, to be able to use the setup of one unique PC user.
/// @test checks the incrementation of a content views counter
/// @note There is a throttling on the views count incrementation, server-side. Therefore this test succeeds only if 15 minutes have passed since the last test.
// TODO: when the sdk will support the creation of a content, the test should be changed to create a content, increment, check incrementation, then destroy the content.
TEST_F(UGC_USSDK001, DISABLED_MANUAL_US_UgcIncrementViewsCheckIncrementation)
{
using namespace TestUserGeneratedContentsClient_BF;
UserGeneratedContentsClient& client = getFacade().getUserGeneratedContentsClient();
uint32 viewsCount;
{
const AsyncResult<Vector<UgcExternalVideo>> result = client.requestExternalVideos({ UgcContentId(CONTENT_ID_EXTERNAL_VIDEO) });
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcExternalVideo>& contents = result.getResult();
EXPECT_EQ(1, contents.size());
const UgcExternalVideo& externalVideo = contents.front();
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO, externalVideo.m_contentId);
viewsCount = externalVideo.m_viewsCount;
}
{
const AsyncResult<Empty> result = client.incrementViews(UgcContentId(CONTENT_ID_EXTERNAL_VIDEO));
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
}
{
const AsyncResult<Vector<UgcExternalVideo>> result = client.requestExternalVideos({ UgcContentId(CONTENT_ID_EXTERNAL_VIDEO) });
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<UgcExternalVideo>& contents = result.getResult();
EXPECT_EQ(1, contents.size());
const UgcExternalVideo& externalVideo = contents.front();
EXPECT_EQ(CONTENT_ID_EXTERNAL_VIDEO, externalVideo.m_contentId);
EXPECT_EQ(viewsCount + 1, externalVideo.m_viewsCount);
}
}
# endif // if defined(US_TARGET_WINDOWS)
# endif //US_DLL
}; // namespace US_NS