|
7 | 7 | using Refresh.Database.Models.Playlists; |
8 | 8 | using Refresh.Database.Models.Levels; |
9 | 9 | using Refresh.Common.Constants; |
| 10 | +using Refresh.Common.Extensions; |
| 11 | +using Refresh.Database.Models.Assets; |
10 | 12 |
|
11 | 13 | namespace RefreshTests.GameServer.Tests.ApiV3; |
12 | 14 |
|
13 | 15 | public class PlaylistApiTests : GameServerTest |
14 | 16 | { |
| 17 | + private const string TEST_IMAGE_HASH = "0ec63b140374ba704a58fa0c743cb357683313dd"; |
| 18 | + |
15 | 19 | [Test] |
16 | 20 | public void CreateAndUpdatePlaylist() |
17 | 21 | { |
@@ -172,6 +176,51 @@ public void CantCreatePlaylistInsideOthersPlaylist() |
172 | 176 | Assert.That(context.Database.GetTotalPlaylistsInPlaylist(parent), Is.Zero); |
173 | 177 | } |
174 | 178 |
|
| 179 | + [Test] |
| 180 | + [TestCase("", true, false)] |
| 181 | + [TestCase("0", true, false)] |
| 182 | + [TestCase("lul", false, false)] |
| 183 | + [TestCase(TEST_IMAGE_HASH, true, true)] |
| 184 | + [TestCase("gg", false, false)] |
| 185 | + [TestCase("g67", false, false)] |
| 186 | + [TestCase("g1000035", true, false)] |
| 187 | + public void TestPlaylistIcons(string icon, bool success, bool isRemoteAsset) |
| 188 | + { |
| 189 | + using TestContext context = this.GetServer(); |
| 190 | + GameUser user = context.CreateUser(); |
| 191 | + using HttpClient client = context.GetAuthenticatedClient(TokenType.Api, user); |
| 192 | + |
| 193 | + if (isRemoteAsset) |
| 194 | + { |
| 195 | + context.Database.AddAssetToDatabase(new() |
| 196 | + { |
| 197 | + AssetHash = icon, |
| 198 | + AssetType = GameAssetType.Png, |
| 199 | + }); |
| 200 | + } |
| 201 | + |
| 202 | + // Create |
| 203 | + ApiPlaylistCreationRequest request = new() |
| 204 | + { |
| 205 | + Icon = icon |
| 206 | + }; |
| 207 | + ApiResponse<ApiGamePlaylistResponse>? response = client.PostData<ApiGamePlaylistResponse>($"/api/v3/playlists", request, success, !success); |
| 208 | + Assert.That(response, Is.Not.Null); |
| 209 | + if (success) |
| 210 | + { |
| 211 | + Assert.That(response!.Data, Is.Not.Null); |
| 212 | + Assert.That(response.Data!.IconHash, Is.EqualTo(icon.IsBlankHash() ? "0" : icon)); |
| 213 | + } |
| 214 | + |
| 215 | + GamePlaylist playlist = context.CreatePlaylist(user); |
| 216 | + response = client.PatchData<ApiGamePlaylistResponse>($"/api/v3/playlists/id/{playlist.PlaylistId}", request, success, !success); |
| 217 | + if (success) |
| 218 | + { |
| 219 | + Assert.That(response!.Data, Is.Not.Null); |
| 220 | + Assert.That(response.Data!.IconHash, Is.EqualTo(icon.IsBlankHash() ? "0" : icon)); |
| 221 | + } |
| 222 | + } |
| 223 | + |
175 | 224 | [Test] |
176 | 225 | public async Task GetAndDeletePlaylist() |
177 | 226 | { |
|
0 commit comments