-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from PinguApps/47create-email-verification-con…
…firmation create email verification confirmation
- Loading branch information
Showing
9 changed files
with
254 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationConfirmationRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Requests.Validators; | ||
|
||
namespace PinguApps.Appwrite.Shared.Requests; | ||
public class CreateEmailVerificationConfirmationRequest : BaseRequest<CreateEmailVerificationConfirmationRequest, CreateEmailVerificationConfirmationRequestValidator> | ||
{ | ||
/// <summary> | ||
/// User ID. | ||
/// </summary> | ||
[JsonPropertyName("userId")] | ||
public string UserId { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Valid verification token. | ||
/// </summary> | ||
[JsonPropertyName("secret")] | ||
public string Secret { get; set; } = string.Empty; | ||
} |
11 changes: 11 additions & 0 deletions
11
...ppwrite.Shared/Requests/Validators/CreateEmailVerificationConfirmationRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using FluentValidation; | ||
|
||
namespace PinguApps.Appwrite.Shared.Requests.Validators; | ||
public class CreateEmailVerificationConfirmationRequestValidator : AbstractValidator<CreateEmailVerificationConfirmationRequest> | ||
{ | ||
public CreateEmailVerificationConfirmationRequestValidator() | ||
{ | ||
RuleFor(x => x.UserId).NotEmpty().Matches("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"); | ||
RuleFor(x => x.Secret).NotEmpty(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...te.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerificationConfirmation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Account; | ||
public partial class AccountClientTests | ||
{ | ||
[Fact] | ||
public async Task CreateEmailVerificationConfirmation_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest() | ||
{ | ||
UserId = "123456", | ||
Secret = "654321" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Put, $"{Constants.Endpoint}/account/verification") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(Constants.AppJson, Constants.TokenResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.CreateEmailVerificationConfirmation(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateEmailVerificationConfirmation_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest() | ||
{ | ||
UserId = "123456", | ||
Secret = "654321" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Put, $"{Constants.Endpoint}/account/verification") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.CreateEmailVerificationConfirmation(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateEmailVerificationConfirmation_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest() | ||
{ | ||
UserId = "123456", | ||
Secret = "654321" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Put, $"{Constants.Endpoint}/account/verification") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.CreateEmailVerificationConfirmation(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...nguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestConfirmationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using FluentValidation; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
|
||
namespace PinguApps.Appwrite.Shared.Tests.Requests; | ||
public class CreateEmailVerificationRequestConfirmationTests | ||
{ | ||
[Fact] | ||
public void Constructor_InitializesWithExpectedValues() | ||
{ | ||
// Arrange & Act | ||
var request = new CreateEmailVerificationConfirmationRequest(); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, request.UserId); | ||
Assert.Equal(string.Empty, request.Secret); | ||
} | ||
|
||
[Fact] | ||
public void Properties_CanBeSet() | ||
{ | ||
var userId = "123456"; | ||
var secret = "[email protected]"; | ||
|
||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest(); | ||
|
||
// Act | ||
request.UserId = userId; | ||
request.Secret = secret; | ||
|
||
// Assert | ||
Assert.Equal(userId, request.UserId); | ||
Assert.Equal(secret, request.Secret); | ||
} | ||
|
||
[Fact] | ||
public void IsValid_WithValidData_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest | ||
{ | ||
UserId = "123456", | ||
Secret = "654321" | ||
}; | ||
|
||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.True(isValid); | ||
} | ||
|
||
[Theory] | ||
[InlineData("badChar^", "654321")] | ||
[InlineData(".bad", "654321")] | ||
[InlineData("_bad", "654321")] | ||
[InlineData("-bad", "654321")] | ||
[InlineData("", "654321")] | ||
[InlineData("1234567890123456789012345678901234567", "654321")] | ||
[InlineData("123456", "")] | ||
public void IsValid_WithInvalidData_ReturnsFalse(string userId, string secret) | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest | ||
{ | ||
UserId = userId, | ||
Secret = secret | ||
}; | ||
|
||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.False(isValid); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest | ||
{ | ||
UserId = ".badChar^", | ||
Secret = "" | ||
}; | ||
|
||
// Assert | ||
Assert.Throws<ValidationException>(() => request.Validate(true)); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() | ||
{ | ||
// Arrange | ||
var request = new CreateEmailVerificationConfirmationRequest | ||
{ | ||
UserId = ".badChar^", | ||
Secret = "" | ||
}; | ||
|
||
// Act | ||
var result = request.Validate(false); | ||
|
||
// Assert | ||
Assert.False(result.IsValid); | ||
} | ||
} |