Version Update Modal Rework + A few bugfixes (#3664)

This commit is contained in:
Joe Milazzo 2025-03-22 15:05:48 -05:00 committed by GitHub
parent 9fb3bdd548
commit 43d0d1277f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
65 changed files with 1963 additions and 805 deletions

View file

@ -65,13 +65,13 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task CheckForUpdate_ShouldReturnNull_WhenGithubApiReturnsNull()
{
// Arrange
_httpTest.RespondWith("null");
// Act
var result = await _service.CheckForUpdate();
// Assert
Assert.Null(result);
}
@ -79,7 +79,7 @@ public class VersionUpdaterServiceTests : IDisposable
//[Fact]
public async Task CheckForUpdate_ShouldReturnUpdateNotification_WhenNewVersionIsAvailable()
{
// Arrange
var githubResponse = new
{
tag_name = "v0.6.0",
@ -91,10 +91,10 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(githubResponse);
// Act
var result = await _service.CheckForUpdate();
// Assert
Assert.NotNull(result);
Assert.Equal("0.6.0", result.UpdateVersion);
Assert.Equal("0.5.0.0", result.CurrentVersion);
@ -121,10 +121,10 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(githubResponse);
// Act
var result = await _service.CheckForUpdate();
// Assert
Assert.NotNull(result);
Assert.True(result.IsReleaseEqual);
Assert.False(result.IsReleaseNewer);
@ -134,7 +134,7 @@ public class VersionUpdaterServiceTests : IDisposable
//[Fact]
public async Task PushUpdate_ShouldSendUpdateEvent_WhenNewerVersionAvailable()
{
// Arrange
var update = new UpdateNotificationDto
{
UpdateVersion = "0.6.0",
@ -145,10 +145,10 @@ public class VersionUpdaterServiceTests : IDisposable
PublishDate = null
};
// Act
await _service.PushUpdate(update);
// Assert
await _eventHub.Received(1).SendMessageAsync(
Arg.Is(MessageFactory.UpdateAvailable),
Arg.Any<SignalRMessage>(),
@ -159,7 +159,7 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task PushUpdate_ShouldNotSendUpdateEvent_WhenVersionIsEqual()
{
// Arrange
var update = new UpdateNotificationDto
{
UpdateVersion = "0.5.0.0",
@ -170,10 +170,10 @@ public class VersionUpdaterServiceTests : IDisposable
PublishDate = null
};
// Act
await _service.PushUpdate(update);
// Assert
await _eventHub.DidNotReceive().SendMessageAsync(
Arg.Any<string>(),
Arg.Any<SignalRMessage>(),
@ -184,7 +184,7 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task GetAllReleases_ShouldReturnReleases_LimitedByCount()
{
// Arrange
var releases = new List<object>
{
new
@ -215,10 +215,10 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(releases);
// Act
var result = await _service.GetAllReleases(2);
// Assert
Assert.Equal(2, result.Count);
Assert.Equal("0.7.0.0", result[0].UpdateVersion);
Assert.Equal("0.6.0", result[1].UpdateVersion);
@ -227,7 +227,7 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task GetAllReleases_ShouldUseCachedData_WhenCacheIsValid()
{
// Arrange
var releases = new List<UpdateNotificationDto>
{
new()
@ -257,10 +257,10 @@ public class VersionUpdaterServiceTests : IDisposable
await File.WriteAllTextAsync(cacheFilePath, System.Text.Json.JsonSerializer.Serialize(releases));
File.SetLastWriteTimeUtc(cacheFilePath, DateTime.UtcNow); // Ensure it's fresh
// Act
var result = await _service.GetAllReleases();
// Assert
Assert.Equal(2, result.Count);
Assert.Empty(_httpTest.CallLog); // No HTTP calls made
}
@ -268,7 +268,7 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task GetAllReleases_ShouldFetchNewData_WhenCacheIsExpired()
{
// Arrange
var releases = new List<UpdateNotificationDto>
{
new()
@ -303,10 +303,10 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(newReleases);
// Act
var result = await _service.GetAllReleases();
// Assert
Assert.Equal(1, result.Count);
Assert.Equal("0.7.0.0", result[0].UpdateVersion);
Assert.NotEmpty(_httpTest.CallLog); // HTTP call was made
@ -314,7 +314,7 @@ public class VersionUpdaterServiceTests : IDisposable
public async Task GetNumberOfReleasesBehind_ShouldReturnCorrectCount()
{
// Arrange
var releases = new List<object>
{
new
@ -345,16 +345,16 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(releases);
// Act
var result = await _service.GetNumberOfReleasesBehind();
// Assert
Assert.Equal(2 + 1, result); // Behind 0.7.0 and 0.6.0 - We have to add 1 because the current release is > 0.7.0
}
public async Task GetNumberOfReleasesBehind_ShouldReturnCorrectCount_WithNightlies()
{
// Arrange
var releases = new List<object>
{
new
@ -377,17 +377,17 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(releases);
// Act
var result = await _service.GetNumberOfReleasesBehind();
// Assert
Assert.Equal(2, result); // We have to add 1 because the current release is > 0.7.0
}
[Fact]
public async Task ParseReleaseBody_ShouldExtractSections()
{
// Arrange
var githubResponse = new
{
tag_name = "v0.6.0",
@ -399,10 +399,10 @@ public class VersionUpdaterServiceTests : IDisposable
_httpTest.RespondWithJson(githubResponse);
// Act
var result = await _service.CheckForUpdate();
// Assert
Assert.NotNull(result);
Assert.Equal(2, result.Added.Count);
Assert.Equal(2, result.Fixed.Count);
@ -414,7 +414,7 @@ public class VersionUpdaterServiceTests : IDisposable
[Fact]
public async Task GetAllReleases_ShouldHandleNightlyBuilds()
{
// Arrange
// Set BuildInfo.Version to a nightly build version
typeof(BuildInfo).GetProperty(nameof(BuildInfo.Version))?.SetValue(null, new Version("0.7.1.0"));
@ -444,10 +444,10 @@ public class VersionUpdaterServiceTests : IDisposable
// Mock commit info for develop branch
_httpTest.RespondWithJson(new List<object>());
// Act
var result = await _service.GetAllReleases();
// Assert
Assert.NotNull(result);
Assert.True(result[0].IsOnNightlyInRelease);
}