Skip to content

Commit

Permalink
Added Create Account tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 9, 2024
1 parent 757a54a commit 468e600
Showing 1 changed file with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PinguApps.Appwrite.Shared.Requests;
using FluentValidation;
using PinguApps.Appwrite.Shared.Requests;

namespace PinguApps.Appwrite.Shared.Tests.Requests;
public class CreateAccountRequestTests
Expand Down Expand Up @@ -35,4 +36,96 @@ public void Properties_CanBeSet(string email, string password, string? name)
Assert.Equal(password, request.Password);
Assert.Equal(name, request.Name);
}

[Theory]
[InlineData(null, "[email protected]", "Password", null)]
[InlineData("321654987", "[email protected]", "12345678", "Pingu")]
[InlineData("a.s-d_f", "[email protected]", "12345678", "Pingu")]
public void IsValid_WithValidData_ReturnsTrue(string? userId, string email, string password, string? name)
{
// Arrange
var request = new CreateAccountRequest
{
Email = email,
Password = password,
Name = name
};

if (userId is not null)
{
request.UserId = userId;
}

// Act
var isValid = request.IsValid();

// Assert
Assert.True(isValid);
}

[Theory]
[InlineData("badChar^", "[email protected]", "Password", "Pingu")]
[InlineData(".bad", "[email protected]", "Password", "Pingu")]
[InlineData("_bad", "[email protected]", "Password", "Pingu")]
[InlineData("-bad", "[email protected]", "Password", "Pingu")]
[InlineData("", "[email protected]", "Password", "Pingu")]
[InlineData("1234567890123456789012345678901234567", "[email protected]", "Password", "Pingu")]
[InlineData(null, "not an email", "Password", "Pingu")]
[InlineData(null, "", "Password", "Pingu")]
[InlineData(null, "[email protected]", "short", "Pingu")]
[InlineData(null, "[email protected]", "", "Pingu")]
public void IsValid_WithInvalidData_ReturnsFalse(string? userId, string email, string password, string? name)
{
// Arrange
var request = new CreateAccountRequest
{
Email = email,
Password = password,
Name = name
};

if (userId is not null)
{
request.UserId = userId;
}

// Act
var isValid = request.IsValid();

// Assert
Assert.False(isValid);
}

[Fact]
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure()
{
// Arrange
var request = new CreateAccountRequest
{
UserId = ".badChar^",
Email = "not an email",
Password = "short"
};

// Assert
Assert.Throws<ValidationException>(() => request.Validate(true));
}

[Fact]
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure()
{
// Arrange
var request = new CreateAccountRequest
{
UserId = ".badChar^",
Email = "not an email",
Password = "short"
};

// Act
var result = request.Validate(false);

// Assert
Assert.False(result.IsValid);
}
}

0 comments on commit 468e600

Please sign in to comment.