Skip to content

Commit 7c487cb

Browse files
committed
Add failing tests
1 parent 8d38b2e commit 7c487cb

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,14 +1840,14 @@ osu file format v14
18401840
}
18411841

18421842
[Fact]
1843-
public async Task TestPatch_BeatmapWithNoChanges_BumpsLastUpdateDate()
1843+
public async Task TestPatch_BeatmapWithNoChanges_BumpsLastUpdateDateAndUpdatesCreatorUsername()
18441844
{
18451845
using var db = await DatabaseAccess.GetConnectionAsync();
18461846
await db.ExecuteAsync(
18471847
"INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
18481848

18491849
await db.ExecuteAsync(
1850-
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'test user', -1, 0, -1, CURRENT_TIMESTAMP)");
1850+
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'old username', -1, 0, -1, CURRENT_TIMESTAMP)");
18511851

18521852
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
18531853
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
@@ -1875,6 +1875,41 @@ await db.ExecuteAsync(
18751875
Assert.True(response.IsSuccessStatusCode);
18761876

18771877
WaitForDatabaseState(@"SELECT COUNT(1) FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526 AND `last_update` > '2020-01-01 00:00:00'", 1, CancellationToken);
1878+
WaitForDatabaseState(@"SELECT `creator` FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526", "test", CancellationToken);
1879+
}
1880+
1881+
[Fact]
1882+
public async Task TestPatchPackage_UpdatesCreatorUsername()
1883+
{
1884+
using var db = await DatabaseAccess.GetConnectionAsync();
1885+
await db.ExecuteAsync(
1886+
"INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
1887+
1888+
await db.ExecuteAsync(
1889+
@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'old username', -1, 0, -1, CURRENT_TIMESTAMP)");
1890+
1891+
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
1892+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
1893+
1894+
using (var dstStream = File.OpenWrite(Path.Combine(beatmapStorage.BaseDirectory, "241526")))
1895+
using (var srcStream = TestResources.GetResource(osz_filename)!)
1896+
await srcStream.CopyToAsync(dstStream);
1897+
await db.ExecuteAsync(@"INSERT INTO `beatmapset_versions` (`beatmapset_id`) VALUES (241526)");
1898+
1899+
var request = new HttpRequestMessage(HttpMethod.Patch, "/beatmapsets/241526");
1900+
1901+
using var content = new MultipartFormDataContent($"{Guid.NewGuid()}----");
1902+
using var osuFileStream = TestResources.GetResource(osu_filename)!;
1903+
content.Add(new StreamContent(osuFileStream), "filesChanged", osu_filename);
1904+
content.Add(new StringContent("Soleily - Renatus (test) [Platter].osu"), "filesDeleted");
1905+
request.Content = content;
1906+
request.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1907+
1908+
var response = await Client.SendAsync(request);
1909+
Assert.True(response.IsSuccessStatusCode);
1910+
1911+
WaitForDatabaseState(@"SELECT COUNT(1) FROM `osu_beatmaps` WHERE `beatmapset_id` = 241526 AND `deleted_at` IS NULL", 12, CancellationToken);
1912+
WaitForDatabaseState(@"SELECT `creator` FROM `osu_beatmapsets` WHERE `beatmapset_id` = 241526", "test", CancellationToken);
18781913
}
18791914

18801915
[Fact]

0 commit comments

Comments
 (0)