Skip to content

Commit

Permalink
style: fix lint errors for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 committed Jun 25, 2023
1 parent c5f3915 commit 98a6a02
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ public class AuthManagerTests
internal const string ACCESS_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9." +
"eyJlbWFpbCI6ImRvbWluaWMubXVycmF5QGltbXV0YWJsZS5jb20iLCJvcmciOiJhNTdiMWYzZC1mYTU3LTRiNzgtODZkYy05ZDEyZDM1YjlhNj" +
"giLCJldGhlcl9rZXkiOiIweGRlMDYzYmViNmNmNDhlNGMxOTcxYzc3N2M0OGY0NTU3MTA1MjU5ZWMiLCJzdGFya19rZXkiOiIweGM1NTYxZGU3" +
"Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG1pbl9rZXkiOiIweGY4MjY4OT" +
"I0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMiLCJpc3MiOiJodHRwczovL2F1dGguaW1tdXRhYmxlLmNvbS8iLCJzdWIiOiJlbWFp" +
"bHw2NDJiN2Q0YWI5N2IzYWMyNDg3NzBlNTEiLCJhdWQiOlsicGxhdGZvcm1fYXBpIiwiaHR0cHM6Ly9wcm9kLmltbXV0YWJsZS5hdXRoMGFwcC" +
"Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG1pbl9rZXkiOiIweGY4MjY4OT" +
"I0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMiLCJpc3MiOiJodHRwczovL2F1dGguaW1tdXRhYmxlLmNvbS8iLCJzdWIiOiJlbWFp" +
"bHw2NDJiN2Q0YWI5N2IzYWMyNDg3NzBlNTEiLCJhdWQiOlsicGxhdGZvcm1fYXBpIiwiaHR0cHM6Ly9wcm9kLmltbXV0YWJsZS5hdXRoMGFwcC" +
"5jb20vdXNlcmluZm8iXSwiaWF0IjoxNjg2ODg5MDgwLCJleHAiOjE2ODY5NzU0ODAsImF6cCI6IlpKTDdKdmV0Y0RGQk5EbGdSczVvSm94dUFV" +
"VWw2dVFqIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCB0cmFuc2FjdCBvZmZsaW5lX2FjY2VzcyJ9.aqFem4Pp0k91YWdYuxBo1wfCr" +
"YAHy1Y1zIqof2GMQXd_mwhGBkHotUlgFAsOIQmvO6lQG5m3cHLR9zlEsFJ_2AJuJg3NTNnF0dEx12H5hx24_aN4qDga8Q9KNDdGc3x4LAxv48P" +
"H-P6OcdMnpWekCUPAI3zZ9qWC1YWU9HaouQuBJNbUV8ujyooFGOP4YzejQf2Uyxz9wmzDiMS-e70BSmY8IPRR2A3QjOEo7oI3enqM_jylfbDo8" +
"BsDRouDbwbZrMeX-rcJ_HBY5iZEdagVpcvOmfZCaad55MI_WJcXHrDMzmLqck1fd15Oklo7fajQtiG0ByINxTmm9_0YnEy02w";
internal const string REFRESH_TOKEN = "v1.NOQCr0kkmy0Cky_Doia8VgJdclSKOOOrkicjZ4NFeabS5J7xNct-oRwO2H65ua0mPOhzWfIf8lhxlM1sIUBqLoc";
internal const string ID_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9.eyJk" +
internal const string ID_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNhYVl5dGR3d2UwMzJzMXIzVElyOSJ9.eyJk" +
"ZXZlbG9wZXJfaHViIjp7ImFjdGl2YXRlZCI6dHJ1ZSwib3Jn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3N2M0OGY0NTU3MTA1MjU5ZWMiLCJzdGFy" +
"a19rZXkiOiIweGM1NTYxZGU3Nzg4NTUxOTY0ZWQxMjI0Yzc2ZjQ5ZDk5ZmVjODkyOGQ1OWVkNTcwZTExZGIwYzk3ZGYwMTFmIiwidXNlcl9hZG" +
"1pbl9rZXkiOiIweGY4MjY4OTI0MWU3NTM1YjYyNTgyMmI4M2I1OWMxZDM3ZWUwOTBiZGMifSwibmlja25hbWUiOiJkb21pbmljLm11cnJheSIs" +
"Im5hbWUiOiJkb21pbmljLm11cnJheUBpbW11dGFibGUuY29tIiwicGljdHVyZSI6Imh0dHBzOi8vcy5ncmF2YXRhci5jb20vYXZhdGFyL2NkOT" +
Expand All @@ -58,25 +58,27 @@ public class AuthManagerTests
#pragma warning disable CS8618
private AuthManager manager;
private MockHttpMessageHandler httpMock;
private MockCredentialsManager credentialsManager;
private MockCredentialsManager credentialsManager;
#pragma warning restore CS8618
[SetUp]

[SetUp]
public void Init()
{
{
httpMock = new MockHttpMessageHandler();
credentialsManager = new MockCredentialsManager();
manager = new AuthManager(httpMock.ToHttpClient(), credentialsManager);
}

private async void PrepareForConfirmCode() {
private async void PrepareForConfirmCode()
{
credentialsManager.hasValidCredentials = false;
credentialsManager.token = null;
AddDeviceCodeResponse();
_ = await manager.Login();
}

private void AddDeviceCodeResponse() {
private void AddDeviceCodeResponse()
{
var deviceCodeResponse = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(@$"{{""{KEY_DEVICE_CODE}"": ""{DEVICE_CODE}"",""user_code"": ""{USER_CODE}""," +
Expand Down Expand Up @@ -134,8 +136,8 @@ public async Task Login_Success_UsingRefreshToken()
Assert.AreEqual(request.Method, HttpMethod.Post);
string stringContent = await request.Content.ReadAsStringAsync();
Assert.True(stringContent.Contains($"{KEY_REFRESH_TOKEN}={REFRESH_TOKEN}"));
}
}

[Test]
public async Task Login_Failed_GetDeviceCode()
{
Expand All @@ -144,9 +146,12 @@ public async Task Login_Failed_GetDeviceCode()
var deviceCodeResponse = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
httpMock.Responses.Add(deviceCodeResponse);
Exception? e = null;
try {
try
{
var result = await manager.Login();
} catch (Exception exception) {
}
catch (Exception exception)
{
e = exception;
}
Assert.NotNull(e);
Expand Down Expand Up @@ -225,9 +230,12 @@ public async Task ConfirmCode_Failed_PendingAndExpired()
Assert.Null(manager.GetUser());

Exception? e = null;
try {
try
{
var result = await manager.ConfirmCode();
} catch (Exception exception) {
}
catch (Exception exception)
{
e = exception;
Debug.Log("Exception: " + e);
}
Expand Down Expand Up @@ -255,9 +263,12 @@ public async Task ConfirmCode_Failed_SlowDownAndAccessDenied()
Assert.Null(manager.GetUser());

Exception? e = null;
try {
try
{
var result = await manager.ConfirmCode();
} catch (Exception exception) {
}
catch (Exception exception)
{
e = exception;
Debug.Log("Exception: " + e);
}
Expand All @@ -279,9 +290,12 @@ public async Task ConfirmCode_Failed_UnexpectedErrorCode()
Assert.Null(manager.GetUser());

Exception? e = null;
try {
try
{
var result = await manager.ConfirmCode();
} catch (Exception exception) {
}
catch (Exception exception)
{
e = exception;
Debug.Log("Exception: " + e);
}
Expand All @@ -302,9 +316,12 @@ public async Task ConfirmCode_Failed_UnexpectedResponse()
Assert.Null(manager.GetUser());

Exception? e = null;
try {
try
{
var result = await manager.ConfirmCode();
} catch (Exception exception) {
}
catch (Exception exception)
{
e = exception;
Debug.Log("Exception: " + e);
}
Expand All @@ -317,7 +334,8 @@ public void HasCredentialsSavedTest()
{
Assert.False(manager.HasCredentialsSaved());

credentialsManager.token = new TokenResponse() {
credentialsManager.token = new TokenResponse()
{
access_token = AuthManagerTests.ACCESS_TOKEN,
refresh_token = AuthManagerTests.REFRESH_TOKEN,
id_token = AuthManagerTests.ID_TOKEN,
Expand All @@ -333,23 +351,28 @@ private string CreateErrorJsonString(string error)
}
}

internal class MockCredentialsManager : ICredentialsManager {
internal class MockCredentialsManager : ICredentialsManager
{
public bool hasValidCredentials = false;
public TokenResponse? token = null;

public void SaveCredentials(TokenResponse tokenResponse) {
public void SaveCredentials(TokenResponse tokenResponse)
{
token = tokenResponse;
}

public TokenResponse? GetCredentials() {
public TokenResponse? GetCredentials()
{
return token;
}

public bool HasValidCredentials() {
public bool HasValidCredentials()
{
return hasValidCredentials;
}

public void ClearCredentials() {
public void ClearCredentials()
{

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class BrowserCommunicationsManagerTests

#pragma warning disable CS8618
private BrowserCommunicationsManager manager;
private MockBrowserClient mockClient;
private MockBrowserClient mockClient;
#pragma warning restore CS8618
[SetUp]

[SetUp]
public void Init()
{
{
mockClient = new MockBrowserClient();
manager = new BrowserCommunicationsManager(mockClient);
}
Expand Down Expand Up @@ -73,9 +73,12 @@ public async Task CallAndResponse_Failed_NoRequestId()
mockClient.setRequestId = false;

Exception? e = null;
try {
try
{
string response = await manager.Call(FUNCTION_NAME);
} catch (PassportException exception) {
}
catch (PassportException exception)
{
e = exception;
}

Expand All @@ -94,12 +97,15 @@ public async Task CallAndResponse_Failed_ClientError_WithType()
};

PassportException? e = null;
try {
try
{
string response = await manager.Call(FUNCTION_NAME);
} catch (PassportException exception) {
}
catch (PassportException exception)
{
e = exception;
}
}

Assert.AreEqual(PassportErrorType.WALLET_CONNECTION_ERROR, e?.Type);
}

Expand All @@ -114,12 +120,15 @@ public async Task CallAndResponse_Failed_ClientError_NoType()
};

PassportException? e = null;
try {
try
{
string response = await manager.Call(FUNCTION_NAME);
} catch (PassportException exception) {
}
catch (PassportException exception)
{
e = exception;
}
}

Assert.Null(e?.Type);
Assert.AreEqual(ERROR, e?.Message);
}
Expand All @@ -128,7 +137,8 @@ public async Task CallAndResponse_Failed_ClientError_NoType()
[Test]
public void CallAndResponse_Success_BrowserReady()
{
Response browserResponse = new() {
Response browserResponse = new()
{
responseFor = BrowserCommunicationsManager.INIT,
requestId = BrowserCommunicationsManager.INIT_REQUEST_ID,
success = true
Expand All @@ -143,7 +153,8 @@ public void CallAndResponse_Success_BrowserReady()
}
}

internal class MockBrowserClient : IWebBrowserClient {
internal class MockBrowserClient : IWebBrowserClient
{
public event OnUnityPostMessageDelegate? OnUnityPostMessage;
public Request? request = null;
public Response? browserResponse = null;
Expand Down
14 changes: 7 additions & 7 deletions src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Immutable.Passport
public class PassportImplTests
{
internal static string DEVICE_CODE = "deviceCode";
internal static string ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikp" +
internal static string ACCESS_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikp" +
"vaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjEyM30.kRqQkJudxgI3koJAp9K4ENp6E2ExFQ5VchogaTWx6Fk";
internal static string ACCESS_TOKEN_KEY = "accessToken";
internal static string REFRESH_TOKEN = "refreshToken";
Expand All @@ -37,9 +37,9 @@ public class PassportImplTests
private PassportImpl passport;
#pragma warning restore CS8618

[SetUp]
[SetUp]
public void Init()
{
{
communicationsManager = new MockBrowserCommsManager();
auth = new MockAuthManager();
passport = new PassportImpl(auth, communicationsManager);
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task Connect_Failed()
{
Assert.Null(await passport.Connect());
}
catch (InvalidOperationException e)
catch (InvalidOperationException e)
{
exception = e;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task ConfirmCode_Failed()
{
await passport.ConfirmCode();
}
catch (PassportException e)
catch (PassportException e)
{
exception = e;
}
Expand Down Expand Up @@ -145,8 +145,8 @@ public async Task GetAddress_Failed()
Assert.True(String.IsNullOrEmpty(communicationsManager.data));
}

[Test]
[Test]

public void Logout_Success()
{
Assert.False(auth.logoutCalled);
Expand Down
Loading

0 comments on commit 98a6a02

Please sign in to comment.