176 lines
No EOL
6.4 KiB
C++
176 lines
No EOL
6.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "testsIntegration/storeHelper.h"
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#include <ubiservices/core/types/dateTimeHelper.h>
|
|
#include <ubiservices/core/types/string.h>
|
|
|
|
namespace US_NS {;
|
|
|
|
namespace StoreHelper
|
|
{
|
|
String renderJsonNoObjectResult()
|
|
{
|
|
//it has & instead of {, so it is not a valid json object
|
|
return "& items:[] &";
|
|
}
|
|
|
|
String renderEmptyArrayResult(const String& label)
|
|
{
|
|
JsonWriter arrayResult;
|
|
arrayResult[label] = JsonWriter(JsonWriterType::Array).getJson();
|
|
return arrayResult.renderContent();
|
|
}
|
|
|
|
String renderPrimaryStoreMapping()
|
|
{
|
|
JsonWriter mapping;
|
|
|
|
JsonWriter mappingElements(JsonWriterType::Array);
|
|
JsonWriter mappingDlc;
|
|
#if defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
|
|
mappingDlc["primaryStoreItemId"] = "UBISERVICESDLC01";
|
|
#elif defined(US_TARGET_XONE)
|
|
mappingDlc["primaryStoreItemId"] = "6df724cf-af33-4767-842f-dcd7cf86b5ac"; //DLC-Skin
|
|
#elif defined(US_TARGET_MANJARO)
|
|
mappingDlc["primaryStoreItemId"] = ""; //todo
|
|
#elif defined(US_TARGET_GGP)
|
|
mappingDlc["primaryStoreItemId"] = "ZEBRA-WEAPON-SKIN";
|
|
#else
|
|
mappingDlc["primaryStoreItemId"] = String(UPLAYPC_DUMMY_DLCID);
|
|
#endif
|
|
mappingDlc["platformType"].setToNull();
|
|
mappingDlc["items"] = JsonWriter(JsonWriterType::Array).getJson();
|
|
|
|
mappingElements.addItemToArray(mappingDlc.getJson());
|
|
|
|
JsonWriter mappingConsumable;
|
|
|
|
#if defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
|
|
mappingConsumable["primaryStoreItemId"] = "CONSU3";
|
|
#elif defined(US_TARGET_XONE)
|
|
mappingConsumable["primaryStoreItemId"] = "96287574-7512-465f-92e3-0003a9e078f8"; // Consumable 3
|
|
#elif defined(US_TARGET_MANJARO)
|
|
mappingConsumable["primaryStoreItemId"] = ""; //todo
|
|
#elif defined(US_TARGET_GGP)
|
|
mappingConsumable["primaryStoreItemId"] = "CURRENCY-1000-CREDITS";
|
|
#else
|
|
mappingConsumable["primaryStoreItemId"] = String(UPLAYPC_DUMMY_CONSUMABLEID);
|
|
#endif
|
|
mappingConsumable["platformType"].setToNull();
|
|
mappingConsumable["items"] = JsonWriter(JsonWriterType::Array).getJson();
|
|
|
|
mappingElements.addItemToArray(mappingConsumable.getJson());
|
|
|
|
mapping["mappings"] = mappingElements.getJson();
|
|
|
|
return mapping.renderContent();
|
|
}
|
|
|
|
void fillPrimaryStoreInventoryWithMappedItems(Vector<PrimaryStoreInventoryItem>& primaryStoreInventory)
|
|
{
|
|
{
|
|
PrimaryStoreInventoryItem product;
|
|
#if defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
|
|
product.m_id = "UBISERVICESDLC01";
|
|
#elif defined(US_TARGET_XONE)
|
|
product.m_id = "6df724cf-af33-4767-842f-dcd7cf86b5ac"; //DLC-Skin
|
|
#elif defined(US_TARGET_MANJARO)
|
|
product.m_id = ""; //todo
|
|
#else
|
|
product.m_id = String(UPLAYPC_DUMMY_DLCID);
|
|
#endif
|
|
product.m_type = PrimaryStoreItemType::Durable;
|
|
product.m_state = PrimaryStoreInventoryItem::InventoryItemState::ReadyToUse;
|
|
|
|
primaryStoreInventory.push_back(product);
|
|
}
|
|
|
|
{
|
|
PrimaryStoreInventoryItem product;
|
|
#if defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
|
|
product.m_id = "CONSU3";
|
|
#elif defined(US_TARGET_XONE)
|
|
product.m_id = "96287574-7512-465f-92e3-0003a9e078f8"; // Consumable 3
|
|
#elif defined(US_TARGET_MANJARO)
|
|
product.m_id = ""; //todo
|
|
#else
|
|
product.m_id = String(UPLAYPC_DUMMY_CONSUMABLEID);
|
|
#endif
|
|
product.m_type = PrimaryStoreItemType::Consumable;
|
|
product.m_balance = 1000;
|
|
product.m_state = PrimaryStoreInventoryItem::InventoryItemState::ReadyToUse;
|
|
|
|
primaryStoreInventory.push_back(product);
|
|
}
|
|
}
|
|
|
|
String renderPrimaryStoreUpdateResult(bool hasResults, bool hasErrors, bool hasAdditionalDetails)
|
|
{
|
|
JsonWriter updateResult;
|
|
|
|
///mock results
|
|
if (hasResults)
|
|
{
|
|
JsonWriter inventoryItem;
|
|
inventoryItem["itemId"] = "11111111-2222-3333-4444-555566667777";
|
|
inventoryItem["quantity"] = 42;
|
|
inventoryItem["quantityBefore"] = 42;
|
|
inventoryItem["lastModified"] = DateTimeHelper::formatDateISO8601(DateTime(2015, 01, 10, 14, 03, 58));
|
|
inventoryItem["expirationDate"] = DateTimeHelper::formatDateISO8601(DateTime(2016, 02, 10, 14, 03, 58));
|
|
inventoryItem["expirationDetails"].setToNull();
|
|
|
|
|
|
JsonWriter transactionWriter;
|
|
transactionWriter["transactionId"] = STORE_TRANSACTION_ID_FICTIVE;
|
|
transactionWriter["items"].addItemToArray(inventoryItem.getJson());
|
|
transactionWriter["primaryStoreItemId"] = "MOCKEDID";
|
|
transactionWriter["primaryStoreItemQuantity"] = 1;
|
|
transactionWriter["primaryStoreItemIsConsumable"] = false;
|
|
|
|
updateResult["results"].addItemToArray(transactionWriter.getJson());
|
|
}
|
|
else
|
|
{
|
|
updateResult["results"] = JsonWriter(JsonWriterType::Array).getJson();
|
|
}
|
|
|
|
///mock errors
|
|
if (hasErrors)
|
|
{
|
|
JsonWriter errorWriter;
|
|
errorWriter["errorMessage"] = "MOCKEDERROR";
|
|
errorWriter["primaryStoreItemId"] = "MOCKEDID";
|
|
errorWriter["code"] = 5000;
|
|
errorWriter["firstPartyErrorCode"] = "5555";
|
|
errorWriter["firstPartyErrorDescription"] = "MOCKEDFIRSTPARTYDESCRIPTION";
|
|
|
|
updateResult["errors"].addItemToArray(errorWriter.getJson());
|
|
}
|
|
else
|
|
{
|
|
updateResult["errors"] = JsonWriter(JsonWriterType::Array).getJson();
|
|
}
|
|
|
|
///additionalDetails
|
|
if (hasAdditionalDetails)
|
|
{
|
|
|
|
JsonWriter additionalDetailsItem;
|
|
additionalDetailsItem["primaryStoreItemId"] = "11111111-2222-3333-4444-555566664444";
|
|
additionalDetailsItem["code"] = 0;
|
|
additionalDetailsItem["description"] = "Test.";
|
|
|
|
updateResult["additionalDetails"].addItemToArray(additionalDetailsItem.getJson());
|
|
}
|
|
else
|
|
{
|
|
updateResult["additionalDetails"] = JsonWriter(JsonWriterType::Array).getJson();
|
|
}
|
|
|
|
return updateResult.renderContent();
|
|
}
|
|
}
|
|
|
|
}; |