Fixing CheckNoDeadLink test now that btse blocks our call from circleci

This commit is contained in:
Kukks
2020-03-31 10:47:13 +02:00
parent 79f12a7058
commit e009c1a25a
4 changed files with 30 additions and 4 deletions

View File

@@ -12,5 +12,12 @@ namespace BTCPayServer.Client
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/stores"), token);
return await HandleResponse<IEnumerable<StoreData>>(response);
}
public virtual async Task<StoreData> GetStore(string storeId, CancellationToken token = default)
{
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}"), token);
return await HandleResponse<StoreData>(response);
}
}
}

View File

@@ -96,7 +96,7 @@ namespace BTCPayServer.Client
foreach (KeyValuePair<string, object> keyValuePair in payload)
{
UriBuilder uriBuilder = uri;
if (keyValuePair.Value.GetType().GetInterfaces().Contains((typeof(IEnumerable))))
if (!(keyValuePair.Value is string) && keyValuePair.Value.GetType().GetInterfaces().Contains((typeof(IEnumerable))))
{
foreach (var item in (IEnumerable)keyValuePair.Value)
{

View File

@@ -168,10 +168,17 @@ namespace BTCPayServer.Tests
user.GrantAccess();
await user.MakeAdmin();
var client = await user.CreateClient(Policies.Unrestricted);
//list stores
var stores = await client.GetStores();
Assert.NotNull(stores);
Assert.Single(stores);
Assert.Equal(user.StoreId,stores.First().Id);
//get store
var store = await client.GetStore(user.StoreId);
Assert.Equal(user.StoreId,store.Id);
Assert.Equal(store.Name,stores.First().Name);
}
}

View File

@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using BTCPayServer.Client;
using BTCPayServer.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using BTCPayServer.Client;
namespace BTCPayServer.Controllers.RestApi
namespace BTCPayServer.Controllers.GreenField
{
[ApiController]
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
@@ -15,10 +15,22 @@ namespace BTCPayServer.Controllers.RestApi
[HttpGet("~/api/v1/stores")]
public ActionResult<IEnumerable<Client.Models.StoreData>> GetStores()
{
var stores = this.HttpContext.GetStoresData();
var stores = HttpContext.GetStoresData();
return Ok(stores.Select(FromModel));
}
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/stores/{storeId}")]
public ActionResult<Client.Models.StoreData> GetStore(string storeId)
{
var store = HttpContext.GetStoreData();
if (store == null)
{
return NotFound();
}
return Ok(FromModel(store));
}
private static Client.Models.StoreData FromModel(Data.StoreData data)
{
return new Client.Models.StoreData()