Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateIsLatest not resetting IsLatest(Stable)SemVer2 on previous latest versions #3909

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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