Skip to content

Commit

Permalink
Prevent duplicate profile pins
Browse files Browse the repository at this point in the history
  • Loading branch information
sudokoko committed Apr 5, 2024
1 parent 931f079 commit 67d0d3d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task<IActionResult> UpdateMyPins()
// Sometimes the update gets called periodically as pin progress updates via playing,
// may not affect equipped profile pins however, so check before setting it.
string currentPins = user.Pins;
string newPins = string.Join(",", pinJson.ProfilePins);
string newPins = string.Join(",", pinJson.ProfilePins.Distinct());

if (string.Equals(currentPins, newPins)) return this.Ok("[{\"StatusCode\":200}]");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,29 @@ public async Task UpdateMyPins_ShouldNotSave_WhenPinsAreEqual()
Assert.Equal(expectedPins, dbMock.Users.First().Pins);
Assert.Equal(expectedResponse, pinsResponse);
}

[Fact]
public async Task UpdateMyPins_ShouldRemove_DuplicatePins()
{
UserEntity entity = MockHelper.GetUnitTestUser();
entity.Pins = "1234";
List<UserEntity> users = new()
{
entity,
};
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase(users);

UserController userController = new(dbMock);
userController.SetupTestController("{\"profile_pins\": [1234, 1234]}");

const string expectedPins = "1234";
const string expectedResponse = "[{\"StatusCode\":200}]";

IActionResult result = await userController.UpdateMyPins();

string pinsResponse = result.CastTo<OkObjectResult, string>();

Assert.Equal(expectedPins, dbMock.Users.First().Pins);
Assert.Equal(expectedResponse, pinsResponse);
}
}

0 comments on commit 67d0d3d

Please sign in to comment.