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

Don't update level modification date if the root level has not changed #626

Merged
merged 1 commit into from
Aug 11, 2024
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
7 changes: 6 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseContext.Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ public GameLevel GetStoryLevelById(int id)
// All checks passed, let's start by retaining some information from the old level
newLevel.Publisher = author;
newLevel.PublishDate = oldLevel.PublishDate;
newLevel.UpdateDate = this._time.Now; // Set the last modified date
newLevel.DateTeamPicked = oldLevel.DateTeamPicked;

// If the actual contents of the level haven't changed, extract some extra information
if (oldLevel.RootResource == newLevel.RootResource)
{
newLevel.GameVersion = oldLevel.GameVersion;
newLevel.UpdateDate = oldLevel.UpdateDate;
}
// If we're changing the actual level, update other things
else
{
newLevel.UpdateDate = this._time.Now; // Set the last modified date
}

// Now newLevel is set up to replace oldLevel.
Expand Down
34 changes: 33 additions & 1 deletion RefreshTests.GameServer/Tests/ApiV3/EditApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void CantUpdateMissingLevel()
}

[Test]
public void UpdatingLevelPersistsPublishDate()
public void LevelUpdateChangesUpdateDate()
{
using TestContext context = this.GetServer(false);
GameUser author = context.CreateUser();
Expand All @@ -139,6 +139,8 @@ public void UpdatingLevelPersistsPublishDate()
// Replicate this here.
newLevel.PublishDate = default;

newLevel.RootResource = "g12345";

context.Time.TimestampMilliseconds = 2;
context.Database.UpdateLevel(newLevel, author);
Assert.Multiple(() =>
Expand All @@ -147,4 +149,34 @@ public void UpdatingLevelPersistsPublishDate()
Assert.That(level.UpdateDate.ToUnixTimeMilliseconds(), Is.EqualTo(2));
});
}

[Test]
public void LevelUpdateDoesNotChangeUpdateDateWhenRootUnchanged()
{
using TestContext context = this.GetServer(false);
GameUser author = context.CreateUser();

context.Time.TimestampMilliseconds = 1;
GameLevel level = context.CreateLevel(author);
Assert.Multiple(() =>
{
Assert.That(level.PublishDate.ToUnixTimeMilliseconds(), Is.EqualTo(1));
Assert.That(level.UpdateDate.ToUnixTimeMilliseconds(), Is.EqualTo(1));
});

GameLevel newLevel = (GameLevel)level.Clone();
// When originating from a request, it wouldn't pass down the original PublishDate.
// Replicate this here.
newLevel.PublishDate = default;

newLevel.Description = "description update";

context.Time.TimestampMilliseconds = 2;
context.Database.UpdateLevel(newLevel, author);
Assert.Multiple(() =>
{
Assert.That(level.PublishDate.ToUnixTimeMilliseconds(), Is.EqualTo(1));
Assert.That(level.UpdateDate.ToUnixTimeMilliseconds(), Is.EqualTo(1));
});
}
}
Loading