Skip to content

Commit 1f52082

Browse files
Revamp of CI and first tests targeting stage
This is a squashed commit of a too big commit. This commit consists of: 1. Initial workflow that targets stage 2. Added CI specific utils to store created users and games 3. Testing on Guest login 4. Testing on White Label Login 5. Testing on Leaderboard details and rewards 6. Testing on submitting scores to Leaderboards 7. Testing on Leaderboard listing, types, and metadata 8. Testing on Player Info 9. Testing on Pinging LootLocker's server 10. Testing on Player Storage, private, public and update 11. Removed ratelimiting while targeting stage
1 parent 28efa2b commit 1f52082

File tree

47 files changed

+3624
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3624
-85
lines changed

.github/workflows/run-tests-and-package.yml

Lines changed: 121 additions & 66 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,10 @@ sysinfo.txt
5959
crashlytics-build.properties
6060

6161
.DS_Store
62+
63+
#IDE generated files
64+
.idea
65+
.vscode
66+
67+
#Specific meta files to ignore
68+
Tests.meta

Runtime/Client/LootLockerServerApi.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ IEnumerator coroutine()
102102
yield break;
103103
}
104104

105-
LogResponse(request, webRequest.responseCode, webRequest.downloadHandler.text, startTime);
105+
106+
LogResponse(request, webRequest.responseCode, webRequest.downloadHandler.text, startTime, webRequest.error);
106107

107108
if (WebRequestSucceeded(webRequest))
108109
{
@@ -168,8 +169,17 @@ private static bool ShouldRetryRequest(long statusCode, int timesRetried)
168169
return (statusCode == 401 || statusCode == 403) && LootLockerConfig.current.allowTokenRefresh && CurrentPlatform.Get() != Platforms.Steam && timesRetried < MaxRetries;
169170
}
170171

171-
private static void LogResponse(LootLockerServerRequest request, long statusCode, string responseBody, float startTime)
172+
private static void LogResponse(LootLockerServerRequest request, long statusCode, string responseBody, float startTime, string unityWebRequestError)
172173
{
174+
if (statusCode == 0 && string.IsNullOrEmpty(responseBody) && !string.IsNullOrEmpty(unityWebRequestError))
175+
{
176+
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("Unity Web request failed, request to " +
177+
request.endpoint + " completed in " +
178+
(Time.time - startTime).ToString("n4") +
179+
" secs.\nWeb Request Error: " + unityWebRequestError);
180+
return;
181+
}
182+
173183
try
174184
{
175185
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("Server Response: " +
@@ -184,8 +194,7 @@ private static void LogResponse(LootLockerServerRequest request, long statusCode
184194
{
185195
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)(request.httpMethod.ToString());
186196
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)(request.endpoint);
187-
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)(
188-
LootLockerObfuscator.ObfuscateJsonStringForLogging(responseBody));
197+
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Error)(LootLockerObfuscator.ObfuscateJsonStringForLogging(responseBody));
189198
}
190199
}
191200

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ private int MoveCurrentBucket(DateTime now)
414414

415415
public virtual bool AddRequestAndCheckIfRateLimitHit()
416416
{
417+
//Disable local ratelimiter when not targeting production
418+
if (!LootLockerConfig.IsTargetingProductionEnvironment())
419+
{
420+
return false;
421+
}
422+
417423
DateTime now = GetTimeNow();
418424
var currentBucket = MoveCurrentBucket(now);
419425

Runtime/Game/Requests/AssetRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public class LootLockerCommonAsset : LootLockerResponse
113113
{
114114
public int id { get; set; }
115115
public string uuid { get; set; }
116+
public string ulid { get; set; }
116117
public string name { get; set; }
117118
public bool active { get; set; }
118119
public bool purchasable { get; set; }

Runtime/Game/Resources/LootLockerConfig.cs

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UnityEditor.PackageManager.UI;
88
#endif
99
using UnityEngine;
10+
using static LootLocker.LootLockerConfig;
1011

1112
namespace LootLocker
1213
{
@@ -22,10 +23,10 @@ public static LootLockerConfig Get()
2223
{
2324
if (settingsInstance != null)
2425
{
25-
settingsInstance.ConstructUrls();
2626
#if LOOTLOCKER_COMMANDLINE_SETTINGS
2727
settingsInstance.CheckForSettingOverrides();
2828
#endif
29+
settingsInstance.ConstructUrls();
2930
return settingsInstance;
3031
}
3132

@@ -62,37 +63,32 @@ public static LootLockerConfig Get()
6263
throw new ArgumentException("LootLocker config does not exist. To fix this, play once in the Unity Editor before making a build.");
6364
}
6465
#endif
65-
settingsInstance.ConstructUrls();
6666
#if LOOTLOCKER_COMMANDLINE_SETTINGS
6767
settingsInstance.CheckForSettingOverrides();
6868
#endif
69+
settingsInstance.ConstructUrls();
6970
return settingsInstance;
7071
}
7172

7273
private void CheckForSettingOverrides()
7374
{
7475
#if LOOTLOCKER_COMMANDLINE_SETTINGS
7576
string[] args = System.Environment.GetCommandLineArgs();
76-
string _apiKey = null;
77-
string _domainKey = null;
7877
for (int i = 0; i < args.Length; i++)
7978
{
8079
if (args[i] == "-apikey")
8180
{
82-
_apiKey = args[i + 1];
81+
apiKey = args[i + 1];
8382
}
8483
else if (args[i] == "-domainkey")
8584
{
86-
_domainKey = args[i + 1];
85+
domainKey = args[i + 1];
86+
}
87+
else if (args[i] == "-lootlockerurl")
88+
{
89+
UrlCoreOverride = args[i + 1];
8790
}
8891
}
89-
90-
if (string.IsNullOrEmpty(_apiKey) || string.IsNullOrEmpty(_domainKey))
91-
{
92-
return;
93-
}
94-
apiKey = _apiKey;
95-
domainKey = _domainKey;
9692
#endif
9793
}
9894

@@ -184,10 +180,37 @@ public static bool CreateNewSettings(string apiKey, string gameVersion, string d
184180
_current.currentDebugLevel = debugLevel;
185181
_current.allowTokenRefresh = allowTokenRefresh;
186182
_current.domainKey = domainKey;
183+
_current.token = null;
184+
#if UNITY_EDITOR
185+
_current.adminToken = null;
186+
#endif //UNITY_EDITOR
187+
_current.refreshToken = null;
188+
_current.gameID = 0;
189+
_current.deviceID = null;
190+
#if LOOTLOCKER_COMMANDLINE_SETTINGS
191+
_current.CheckForSettingOverrides();
192+
#endif
187193
_current.ConstructUrls();
188194
return true;
189195
}
190196

197+
public static bool ClearSettings()
198+
{
199+
_current.apiKey = null;
200+
_current.game_version = null;
201+
_current.currentDebugLevel = DebugLevel.All;
202+
_current.allowTokenRefresh = true;
203+
_current.domainKey = null;
204+
_current.token = null;
205+
#if UNITY_EDITOR
206+
_current.adminToken = null;
207+
#endif //UNITY_EDITOR
208+
_current.refreshToken = null;
209+
_current.gameID = 0;
210+
_current.deviceID = null;
211+
return true;
212+
}
213+
191214
private void ConstructUrls()
192215
{
193216
string startOfUrl = UrlProtocol;
@@ -222,7 +245,7 @@ public static LootLockerConfig current
222245
public string token;
223246
#if UNITY_EDITOR
224247
[HideInInspector]
225-
public string adminToken;
248+
public string adminToken = null;
226249
#endif
227250
[HideInInspector]
228251
public string refreshToken;
@@ -238,13 +261,19 @@ public static LootLockerConfig current
238261

239262
[HideInInspector] private static readonly string UrlProtocol = "https://";
240263
[HideInInspector] private static readonly string UrlCore = "api.lootlocker.io";
241-
[HideInInspector] private static readonly string UrlCoreOverride =
264+
[HideInInspector] private static string UrlCoreOverride =
242265
#if LOOTLOCKER_TARGET_STAGE_ENV
243266
"api.stage.internal.dev.lootlocker.cloud";
244267
#else
245268
null;
246269
#endif
247270
private static string GetUrlCore() { return string.IsNullOrEmpty(UrlCoreOverride) ? UrlCore : UrlCoreOverride; }
271+
272+
public static bool IsTargetingProductionEnvironment()
273+
{
274+
return string.IsNullOrEmpty(UrlCoreOverride) || UrlCoreOverride.Equals(UrlCore);
275+
276+
}
248277
[HideInInspector] private static readonly string UrlAppendage = "/v1";
249278
[HideInInspector] private static readonly string AdminUrlAppendage = "/admin";
250279
[HideInInspector] private static readonly string PlayerUrlAppendage = "/player";

Tests/LootLockerTestUtils.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using LootLocker;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace LootLockerTestConfigurationUtils
6+
{
7+
public class ApiKey
8+
{
9+
public class CreateApiKeyRequest
10+
{
11+
public string name { get; set; }
12+
public string api_type { get; set; } = "game";
13+
}
14+
15+
public class CreateApiKeyResponse : LootLockerResponse
16+
{
17+
public string api_key { get; set; }
18+
}
19+
20+
public static void CreateKey(string keyName, int gameId, Action<CreateApiKeyResponse> onComplete)
21+
{
22+
if (string.IsNullOrEmpty(LootLockerConfig.current.adminToken))
23+
{
24+
// Not signed in
25+
onComplete?.Invoke(new CreateApiKeyResponse { success = false, errorData = new LootLockerErrorData{message = "Not logged in"}});
26+
return;
27+
}
28+
29+
EndPointClass endPoint = LootLockerTestConfigurationEndpoints.CreateKey;
30+
var formattedEndpoint = string.Format(endPoint.endPoint, gameId);
31+
32+
CreateApiKeyRequest request = new CreateApiKeyRequest { name = keyName };
33+
34+
string json = LootLockerJson.SerializeObject(request);
35+
36+
LootLockerAdminRequest.Send(formattedEndpoint, endPoint.httpMethod, json,
37+
onComplete: (serverResponse) => LootLockerResponse.Deserialize(onComplete, serverResponse), true);
38+
}
39+
}
40+
}

Tests/LootLockerTestUtils/LootLockerTestConfigurationApiKey.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using LootLocker;
2+
using LootLocker.Requests;
3+
using System;
4+
using System.Collections.Generic;
5+
using Debug = UnityEngine.Debug;
6+
7+
namespace LootLockerTestConfigurationUtils
8+
{
9+
10+
public class LootLockerTestAssetResponse : LootLockerResponse
11+
{
12+
public LootLockerCommonAsset asset { get; set; }
13+
}
14+
15+
public class LootLockerRewardResponse : LootLockerResponse
16+
{
17+
public string id { get; set; }
18+
}
19+
20+
public class LootLockerRewardRequest
21+
{
22+
public string entity_id { get; set; }
23+
public string entity_kind { get; set;}
24+
}
25+
26+
public class LootLockerTestContextResponse : LootLockerResponse
27+
{
28+
public LootLockerTestContext[] contexts { get; set; }
29+
}
30+
31+
public class LootLockerTestContext
32+
{
33+
public int id { get; set; }
34+
public string uuid { get; set; }
35+
public string name { get; set; }
36+
}
37+
38+
public class CreateLootLockerTestAsset
39+
{
40+
public int context_id { get; set; }
41+
public string name { get; set; }
42+
}
43+
44+
}

0 commit comments

Comments
 (0)