refactor: added a buncha tests

This commit is contained in:
2026-02-10 11:23:58 -05:00
parent c40adc4465
commit b69625dc2e
6 changed files with 1046 additions and 16 deletions

View File

@@ -0,0 +1,82 @@
using Xunit;
using Moq;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using allstarr.Services.Spotify;
using allstarr.Models.Settings;
namespace allstarr.Tests;
public class SpotifyApiClientTests
{
private readonly Mock<ILogger<SpotifyApiClient>> _mockLogger;
private readonly IOptions<SpotifyApiSettings> _settings;
public SpotifyApiClientTests()
{
_mockLogger = new Mock<ILogger<SpotifyApiClient>>();
_settings = Options.Create(new SpotifyApiSettings
{
Enabled = true,
SessionCookie = "test_session_cookie_value",
CacheDurationMinutes = 60,
RateLimitDelayMs = 100,
PreferIsrcMatching = true
});
}
[Fact]
public void Constructor_InitializesWithSettings()
{
// Act
var client = new SpotifyApiClient(_mockLogger.Object, _settings);
// Assert
Assert.NotNull(client);
}
[Fact]
public void Settings_AreConfiguredCorrectly()
{
// Arrange & Act
var client = new SpotifyApiClient(_mockLogger.Object, _settings);
// Assert - Constructor should not throw
Assert.NotNull(client);
}
[Fact]
public void SessionCookie_IsRequired_ForWebApiAccess()
{
// Arrange
var settingsWithoutCookie = Options.Create(new SpotifyApiSettings
{
Enabled = true,
SessionCookie = "" // Empty cookie
});
// Act
var client = new SpotifyApiClient(_mockLogger.Object, settingsWithoutCookie);
// Assert - Constructor should not throw, but GetWebAccessTokenAsync will return null
Assert.NotNull(client);
}
[Fact]
public void RateLimitSettings_AreRespected()
{
// Arrange
var customSettings = Options.Create(new SpotifyApiSettings
{
Enabled = true,
SessionCookie = "test_cookie",
RateLimitDelayMs = 500
});
// Act
var client = new SpotifyApiClient(_mockLogger.Object, customSettings);
// Assert
Assert.NotNull(client);
}
}