Fixes based on feedback

This commit is contained in:
rockstardev
2020-07-31 00:20:17 -05:00
parent 6c7d3ae0bf
commit 9e70bb448a
2 changed files with 12 additions and 10 deletions

View File

@@ -3128,13 +3128,10 @@ namespace BTCPayServer.Tests
var settings = tester.PayTester.GetService<SettingsRepository>();
await settings.UpdateSetting<PoliciesSettings>(new PoliciesSettings() { CheckForNewVersions = true });
var envMock = tester.PayTester.GetService<BTCPayServerEnvironment>();
// modifying environment to simulate production
envMock.Environment.EnvironmentName = "Production";
var mockEnv = tester.PayTester.GetService<BTCPayServerEnvironment>();
var mockSender = tester.PayTester.GetService<Services.Notifications.NotificationSender>();
var notificationSender = tester.PayTester.GetService<Services.Notifications.NotificationSender>();
var svc = new NewVersionCheckerHostedService(settings, envMock, notificationSender, new MockVersionFetcher());
var svc = new NewVersionCheckerHostedService(settings, mockEnv, mockSender, new MockVersionFetcher());
await svc.ProcessVersionCheck();
// since last version present in database was null, it should've been updated with version mock returned

View File

@@ -39,7 +39,7 @@ namespace BTCPayServer.HostedServices
public async Task ProcessVersionCheck()
{
var policies = await _settingsRepository.GetSettingAsync<PoliciesSettings>() ?? new PoliciesSettings();
if (policies.CheckForNewVersions && !_env.IsDeveloping)
if (policies.CheckForNewVersions)
{
var tag = await _versionFetcher.Fetch(Cancellation);
if (tag != null && tag != _env.Version)
@@ -67,16 +67,21 @@ namespace BTCPayServer.HostedServices
Task<string> Fetch(CancellationToken cancellation);
}
public class GithubVersionFetcher : IVersionFetcher
public class GithubVersionFetcher : IVersionFetcher, IDisposable
{
private readonly HttpClient _httpClient;
public GithubVersionFetcher()
public GithubVersionFetcher(IHttpClientFactory httpClientFactory)
{
_httpClient = new HttpClient();
_httpClient = httpClientFactory.CreateClient(nameof(GithubVersionFetcher));
_httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
_httpClient.DefaultRequestHeaders.Add("User-Agent", "BTCPayServer/NewVersionChecker");
}
public void Dispose()
{
_httpClient.Dispose();
}
public async Task<string> Fetch(CancellationToken cancellation)
{
const string url = "https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest";