From bac9ef4f930a7507fb51120a1443070299eb578a Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 29 May 2018 17:12:07 +0200 Subject: [PATCH] add some UT and fix error message + bump Nbitpayclient --- BTCPayServer.Tests/UnitTest1.cs | 35 ++++++++++++++++++++++ BTCPayServer/BTCPayServer.csproj | 2 +- BTCPayServer/Controllers/RateController.cs | 4 +-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 1e8a23067..9f7c1a6c0 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -35,6 +35,7 @@ using BTCPayServer.Services.Apps; using BTCPayServer.Services.Stores; using System.Net.Http; using System.Text; +using BTCPayServer.Models; using BTCPayServer.Rating; using BTCPayServer.Validation; using ExchangeSharp; @@ -677,6 +678,40 @@ namespace BTCPayServer.Tests } } + [Fact] + public void CanGetRates() + { + using (var tester = ServerTester.Create()) + { + tester.Start(); + var acc = tester.NewAccount(); + acc.GrantAccess(); + acc.RegisterDerivationScheme("BTC"); + acc.RegisterDerivationScheme("LTC"); + + var rateController = acc.GetController(); + var GetBaseCurrencyRatesResult = JObject.Parse(((JsonResult)rateController.GetBaseCurrencyRates("BTC", acc.StoreId) + .GetAwaiter().GetResult()).ToJson()).ToObject>(); + Assert.NotNull(GetBaseCurrencyRatesResult); + Assert.NotNull(GetBaseCurrencyRatesResult.Data); + Assert.Single(GetBaseCurrencyRatesResult.Data); + Assert.Equal("LTC", GetBaseCurrencyRatesResult.Data.First().Code); + + var GetRatesResult = JObject.Parse(((JsonResult)rateController.GetRates(null, acc.StoreId) + .GetAwaiter().GetResult()).ToJson()).ToObject>(); + Assert.NotNull(GetRatesResult); + Assert.NotNull(GetRatesResult.Data); + Assert.Equal(2, GetRatesResult.Data.Length); + + var GetCurrencyPairRateResult = JObject.Parse(((JsonResult)rateController.GetCurrencyPairRate("BTC", "LTC", acc.StoreId) + .GetAwaiter().GetResult()).ToJson()).ToObject>(); + + Assert.NotNull(GetCurrencyPairRateResult); + Assert.NotNull(GetCurrencyPairRateResult.Data); + Assert.Equal("LTC", GetCurrencyPairRateResult.Data.Code); + } + } + private void AssertSearchInvoice(TestAccount acc, bool expected, string invoiceId, string filter) { var result = (Models.InvoicingModels.InvoicesModel)((ViewResult)acc.GetController().ListInvoices(filter).Result).Model; diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index bf7662173..6d16a1a98 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -41,7 +41,7 @@ - + diff --git a/BTCPayServer/Controllers/RateController.cs b/BTCPayServer/Controllers/RateController.cs index af8befe1b..1df51e8e8 100644 --- a/BTCPayServer/Controllers/RateController.cs +++ b/BTCPayServer/Controllers/RateController.cs @@ -104,7 +104,7 @@ namespace BTCPayServer.Controllers { if (storeId == null) { - var result = Json(new BitpayErrorsModel() { Error = "You need to specify storeId (in your store settings) and currencyPairs (eg. BTC_USD,LTC_CAD)" }); + var result = Json(new BitpayErrorsModel() { Error = "You need to specify storeId (in your store settings)" }); result.StatusCode = 400; return result; } @@ -143,7 +143,7 @@ namespace BTCPayServer.Controllers if (string.IsNullOrEmpty(currencyPairs)) { - var result = Json(new BitpayErrorsModel() { Error = "You need to specify storeId (in your store settings) and currencyPairs (eg. BTC_USD,LTC_CAD)" }); + var result = Json(new BitpayErrorsModel() { Error = "You need to specify currencyPairs (eg. BTC_USD,LTC_CAD)" }); result.StatusCode = 400; return result; }