-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add simple player files test to sanity test that upload works
- Loading branch information
1 parent
d4208ec
commit 7d5d295
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
using LootLocker; | ||
using LootLocker.Requests; | ||
using LootLockerTestConfigurationUtils; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Net; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
|
||
namespace LootLockerTests.PlayMode | ||
{ | ||
public class PlayerFilesTest | ||
{ | ||
private LootLockerTestGame gameUnderTest = null; | ||
private LootLockerConfig configCopy = null; | ||
private static int TestCounter = 0; | ||
private bool SetupFailed = false; | ||
|
||
[UnitySetUp] | ||
public IEnumerator Setup() | ||
{ | ||
TestCounter++; | ||
configCopy = LootLockerConfig.current; | ||
|
||
if (!LootLockerConfig.ClearSettings()) | ||
{ | ||
Debug.LogError("Could not clear LootLocker config"); | ||
} | ||
|
||
// Create game | ||
bool gameCreationCallCompleted = false; | ||
LootLockerTestGame.CreateGame(testName: "GuestSessionTest" + TestCounter + " ", onComplete: (success, errorMessage, game) => | ||
{ | ||
if (!success) | ||
{ | ||
gameCreationCallCompleted = true; | ||
Debug.LogError(errorMessage); | ||
SetupFailed = true; | ||
} | ||
gameUnderTest = game; | ||
gameCreationCallCompleted = true; | ||
}); | ||
yield return new WaitUntil(() => gameCreationCallCompleted); | ||
if (SetupFailed) | ||
{ | ||
yield break; | ||
} | ||
gameUnderTest?.SwitchToStageEnvironment(); | ||
|
||
// Enable guest platform | ||
bool enableGuestLoginCallCompleted = false; | ||
gameUnderTest?.EnableGuestLogin((success, errorMessage) => | ||
{ | ||
if (!success) | ||
{ | ||
Debug.LogError(errorMessage); | ||
SetupFailed = true; | ||
} | ||
enableGuestLoginCallCompleted = true; | ||
}); | ||
yield return new WaitUntil(() => enableGuestLoginCallCompleted); | ||
if (SetupFailed) | ||
{ | ||
yield break; | ||
} | ||
Assert.IsTrue(gameUnderTest?.InitializeLootLockerSDK(), "Successfully created test game and initialized LootLocker"); | ||
|
||
// Sign in client | ||
bool guestLoginCompleted = false; | ||
LootLockerSDKManager.StartGuestSession(Guid.NewGuid().ToString(), response => | ||
{ | ||
SetupFailed |= !response.success; | ||
guestLoginCompleted = true; | ||
}); | ||
yield return new WaitUntil(() => guestLoginCompleted); | ||
|
||
} | ||
|
||
[UnityTearDown] | ||
public IEnumerator TearDown() | ||
{ | ||
if (gameUnderTest != null) | ||
{ | ||
bool gameDeletionCallCompleted = false; | ||
gameUnderTest.DeleteGame(((success, errorMessage) => | ||
{ | ||
if (!success) | ||
{ | ||
Debug.LogError(errorMessage); | ||
} | ||
gameUnderTest = null; | ||
gameDeletionCallCompleted = true; | ||
})); | ||
yield return new WaitUntil(() => gameDeletionCallCompleted); | ||
} | ||
|
||
LootLockerConfig.CreateNewSettings(configCopy.apiKey, configCopy.game_version, configCopy.domainKey, | ||
configCopy.currentDebugLevel, configCopy.allowTokenRefresh); | ||
} | ||
|
||
|
||
[UnityTest] | ||
public IEnumerator PlayerFiles_UploadSimplePublicFile_Succeeds() | ||
{ | ||
Assert.IsFalse(SetupFailed, "Failed to setup game"); | ||
// Given | ||
string path = Application.temporaryCachePath + "/PlayerFileCanBeCreatedWithPathUpdatedAndThenDeleted-creation.txt"; | ||
string content = "First added line"; | ||
TextWriter writer = new StreamWriter(path); | ||
writer.WriteLine(content); | ||
writer.Close(); | ||
|
||
// When | ||
LootLockerPlayerFile actualResponse = new LootLockerPlayerFile(); | ||
bool setToPublic = true; | ||
bool playerFileUploadCompleted = false; | ||
LootLockerSDKManager.UploadPlayerFile(path, "test", setToPublic, fileResponse => | ||
{ | ||
actualResponse = fileResponse; | ||
playerFileUploadCompleted = true; | ||
}); | ||
|
||
// Wait for response | ||
yield return new WaitUntil(() => playerFileUploadCompleted); | ||
|
||
// Then | ||
Assert.IsTrue(actualResponse.success, "File upload failed"); | ||
Assert.Greater(actualResponse.size, 0, "File Size was 0"); | ||
Assert.AreEqual(setToPublic, actualResponse.is_public, "File does not have the same public setting"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.