using Knoks.Api.Client.Invoker;
using Knoks.Test.Integrations.Api.Tools;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;
using static Knoks.Test.Integrations.Api.Tools.ApiMocker;

namespace Knoks.Test.Integrations.Api
{
    public class AccountControllerTest : ApiTestClient
    {
        [Fact(DisplayName = "Unauthorized Account Info")]
        async Task UnauthorizedAccountInfo()
        {
            Assert.Equal(HttpStatusCode.Unauthorized, (await ApiClient.Request("account/useraccounts")).HttpResponse.StatusCode);
        }

        [Fact(DisplayName = "Forbidden Account Info")]
        async Task ForbiddenAccountInfo()
        {
            await ApiClient.AuthorizeApiConsumer();
            Assert.Equal(HttpStatusCode.Forbidden, (await ApiClient.Request("account/useraccounts")).HttpResponse.StatusCode);
        }

        [Fact(DisplayName = "User Accounts")]
        async Task UserAccounts()
        {
            await ApiClient.AuthorizeApiConsumer();

            var createUserArgs = GetCreateUserArgs();
            var user = (await ApiClient.InvokeCreateUser(createUserArgs)).Object;

            await ApiClient.AuthorizeApiUser(createUserArgs.Email, createUserArgs.Password);
            var userAccounts = (await ApiClient.InvokeUserAccounts()).Object;

            Assert.Equal(user.FirstName, userAccounts.User.FirstName);
            Assert.NotEmpty(userAccounts.Accounts);
        }
    }
}
