//-----------------------------------------------------------------------
// <copyright file="FilesizeTests.cs" company="lanedirt">
// Copyright (c) lanedirt. All rights reserved.
// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
// </copyright>
//-----------------------------------------------------------------------

namespace AliasVault.UnitTests.Vault;

using AliasVault.Api.Helpers;

/// <summary>
/// Tests for the Vault FileSize calculation.
/// </summary>
public class FilesizeTests
{
    /// <summary>
    /// Test the FileSize calculation for small strings.
    /// </summary>
    [Test]
    public void FileSizeSmallTest()
    {
        var smallString = "dGVzdA==";
        Assert.That(FileHelper.Base64StringToKilobytes(smallString), Is.EqualTo(1));
    }

    /// <summary>
    /// Test the FileSize calculation for medium strings.
    /// </summary>
    [Test]
    public void FileSizeMediumTest()
    {
        var mediumString = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gRG9uZWMgZXUgY29udmFsbGlzIGxvcmVtLCB2ZWwgdGluY2lkdW50IG5pYmguIERvbmVjIGN1cnN1cywgZXJvcyBzZWQgZmVybWVudHVtIGhlbmRyZXJpdCwgZXggbnVsbGEgY3Vyc3VzIGxhY3VzLCBldSBjb21tb2RvIGVyYXQgbGVvIGF0IGV4LiBJbnRlZ2VyIHV0IGR1aSBwaGFyZXRyYSwgc3VzY2lwaXQgbGVjdHVzIHF1aXMsIG1vbGVzdGllIGFyY3UuIFByYWVzZW50IG5pc2wgZW5pbSwgc29kYWxlcyB2ZWwgbHVjdHVzIGluLCBlZ2VzdGFzIGV1IG1hc3NhLiBDcmFzIHZlaGljdWxhIGNvbW1vZG8gZnJpbmdpbGxhLiBTdXNwZW5kaXNzZSBwcmV0aXVtIGZpbmlidXMgcHVydXMgZXUgc2VtcGVyLiBRdWlzcXVlIGFsaXF1YW0gbGVjdHVzIGFyY3UsIGFjIHBvcnRhIG5pYmggY29udmFsbGlzIGRpZ25pc3NpbS4gSW50ZWdlciByaXN1cyBhcmN1LCBtYXR0aXMgZWdld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B1dCByaXN1cyB0ZW1wb3IgdWx0cmljZXMuIE5hbSBhdCB0dXJwaXMgdml0YWUgbnVsbGEgaWFjdWxpcyBlZ2VzdGFzLiBOdW5jIGZldWdpYXQgc29kYWxlcyBuaXNpLg==";
        Assert.That(FileHelper.Base64StringToKilobytes(mediumString), Is.EqualTo(3));
    }

    /// <summary>
    /// Test the FileSize calculation for large strings.
    /// </summary>
    [Test]
    public void FileSizeLargeTest()
    {
        var largeString = "[encoded data, 42836 characters]";
        Assert.That(FileHelper.Base64StringToKilobytes(largeString), Is.EqualTo(32));
    }
}
