Skip to content

Commit

Permalink
Added test to confirm that the API key is being passed in with reques…
Browse files Browse the repository at this point in the history
…ts by WaaS's HTTP Client
  • Loading branch information
BellringerQuinn committed Dec 18, 2023
1 parent 31bdfa2 commit 6ce393d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Assets/SequenceSDK/WaaS/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public void AddDefaultHeader(string key, string value)
this._defaultHeaders[key] = value;
}

public async Task<T2> SendRequest<T, T2>(string path, T args, [CanBeNull] Dictionary<string, string> headers = null, string overrideUrl = null)
public (UnityWebRequest, string, string) BuildRequest<T>(string path, T args,
[CanBeNull] Dictionary<string, string> headers = null, string overrideUrl = null)
{
string url = _url + "/" + path;
if (overrideUrl != null)
Expand Down Expand Up @@ -74,7 +75,16 @@ public async Task<T2> SendRequest<T, T2>(string path, T args, [CanBeNull] Dictio
string method = request.method;
string headersString = ExtractHeaders(request);
string curlRequest = $"curl -X {method} '{url}' {headersString} -d '{requestJson}'";
Debug.Log("Equivalent curl command: " + curlRequest);

return (request, curlRequest, url);
}

public async Task<T2> SendRequest<T, T2>(string path, T args, [CanBeNull] Dictionary<string, string> headers = null, string overrideUrl = null)
{
(UnityWebRequest, string, string) newRequest = BuildRequest(path, args, headers, overrideUrl);
UnityWebRequest request = newRequest.Item1;
string curlRequest = newRequest.Item2;
string url = newRequest.Item3;

try
{
Expand Down
19 changes: 19 additions & 0 deletions Assets/SequenceSDK/WaaS/Tests/HttpClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NUnit.Framework;
using Sequence.Config;

namespace Sequence.WaaS.Tests
{
public class HttpClientTests
{
[Test]
public void TestHttpClientIncludesAPIKey()
{
HttpClient client = new HttpClient("https://randomurl.com");
var request = client.BuildRequest<object>("", null);
string header = request.Item1.GetRequestHeader("X-Access-Token");
Assert.IsTrue(header.Length > 0);
Assert.AreEqual(SequenceConfig.GetConfig().BuilderAPIKey_Prod, header);
Assert.IsTrue(request.Item2.Contains(header));
}
}
}
3 changes: 3 additions & 0 deletions Assets/SequenceSDK/WaaS/Tests/HttpClientTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Assets/SequenceSDK/WaaS/Tests/WaaSTests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:72aec190c59574cbabd6cbdd81011e4d"
"GUID:72aec190c59574cbabd6cbdd81011e4d",
"GUID:a35e3a53d4439435f8b36ed2c6158cd8"
],
"includePlatforms": [
"Editor",
Expand Down

0 comments on commit 6ce393d

Please sign in to comment.