using JobTrackerApi.Services;
using Xunit;

namespace JobTrackerApi.Tests;

public sealed class AvatarStorageTests
{
    [Fact]
    public async Task Store_resolve_delete_round_trip_keeps_image_out_of_database_value()
    {
        var root = Path.Combine(Path.GetTempPath(), "jobtracker-avatar-test-" + Guid.NewGuid().ToString("N"));
        try
        {
            var stored = await AvatarStorage.StoreAsync(root, "user-1", new byte[] { 1, 2, 3 }, "image/png", default);

            Assert.StartsWith("file:", stored);
            Assert.Equal("data:image/png;base64,AQID", AvatarStorage.Resolve(stored));
            AvatarStorage.Delete(stored);
            Assert.Null(AvatarStorage.Resolve(stored));
        }
        finally
        {
            if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
        }
    }
}
