Skip to content

Commit

Permalink
UpdateIsLatest not resetting IsLatest(Stable)SemVer2 on previous late…
Browse files Browse the repository at this point in the history
…st versions (#3909)
  • Loading branch information
xavierdecoster committed May 15, 2017
1 parent ad552e6 commit 895df4b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NuGetGallery/Services/PackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public async Task UpdateIsLatestAsync(PackageRegistration packageRegistration, b

// TODO: improve setting the latest bit; this is horrible. Trigger maybe?
var currentUtcTime = DateTime.UtcNow;
foreach (var pv in packageRegistration.Packages.Where(p => p.IsLatest || p.IsLatestStable))
foreach (var pv in packageRegistration.Packages.Where(p => p.IsLatest || p.IsLatestStable || p.IsLatestSemVer2 || p.IsLatestStableSemVer2))
{
pv.IsLatest = false;
pv.IsLatestStable = false;
Expand Down
44 changes: 44 additions & 0 deletions tests/NuGetGallery.Facts/Services/PackageServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,50 @@ public async Task CommitIfCommitChangesIsTrue()
packageRepository.Verify(r => r.CommitChangesAsync(), Times.Once());
}

[Fact]
public async Task ResetsCurrentLatestPackageVersionsBeforeUpdate()
{
// Arrange
var packageRegistration = new PackageRegistration();

var previousLatestStable = new Package { PackageRegistration = packageRegistration, Version = "1.0.0", IsLatestStable = true };
packageRegistration.Packages.Add(previousLatestStable);
var previousLatest = new Package { PackageRegistration = packageRegistration, Version = "1.0.0-alpha", IsLatest = true, IsPrerelease = true };
packageRegistration.Packages.Add(previousLatest);
var previousLatestStableSemVer2 = new Package { PackageRegistration = packageRegistration, Version = "1.0.1+metadata", IsLatestStableSemVer2 = true, SemVerLevelKey = SemVerLevelKey.SemVer2 };
packageRegistration.Packages.Add(previousLatestStableSemVer2);
var previousLatestSemVer2 = new Package { PackageRegistration = packageRegistration, Version = "1.0.1-alpha.1", IsLatestSemVer2 = true, IsPrerelease = true, SemVerLevelKey = SemVerLevelKey.SemVer2 };
packageRegistration.Packages.Add(previousLatestSemVer2);

// Simulates adding newer versions, to ensure the previous latest are no longer latest at end of test.
var newLatestStable = new Package { PackageRegistration = packageRegistration, Version = "1.0.1", IsLatestStable = true };
packageRegistration.Packages.Add(newLatestStable);
var newLatest = new Package { PackageRegistration = packageRegistration, Version = "1.0.2-alpha", IsLatest = true, IsPrerelease = true };
packageRegistration.Packages.Add(newLatest);
var newLatestStableSemVer2 = new Package { PackageRegistration = packageRegistration, Version = "1.0.2+metadata", IsLatestStableSemVer2 = true, SemVerLevelKey = SemVerLevelKey.SemVer2 };
packageRegistration.Packages.Add(newLatestStableSemVer2);
var newLatestSemVer2 = new Package { PackageRegistration = packageRegistration, Version = "1.0.3-alpha.1", IsLatestSemVer2 = true, IsPrerelease = true, SemVerLevelKey = SemVerLevelKey.SemVer2 };
packageRegistration.Packages.Add(newLatestSemVer2);

var packageRepository = new Mock<IEntityRepository<Package>>();

var service = CreateService(packageRepository: packageRepository);

// Act
await service.UpdateIsLatestAsync(packageRegistration, commitChanges: true);

// Assert
Assert.False(previousLatestStable.IsLatestStable);
Assert.False(previousLatest.IsLatest);
Assert.False(previousLatestSemVer2.IsLatestSemVer2);
Assert.False(previousLatestStableSemVer2.IsLatestStableSemVer2);

Assert.True(newLatestStable.IsLatestStable);
Assert.True(newLatest.IsLatest);
Assert.True(newLatestSemVer2.IsLatestSemVer2);
Assert.True(newLatestStableSemVer2.IsLatestStableSemVer2);
}

[Fact]
public async Task UpdateIsLatestScenarioForPrereleaseAsAbsoluteLatest()
{
Expand Down

0 comments on commit 895df4b

Please sign in to comment.