-
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 #169 from PinguApps/83-delete-identity
Implemented delete identity
- Loading branch information
Showing
10 changed files
with
267 additions
and
10 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
16 changes: 16 additions & 0 deletions
16
src/PinguApps.Appwrite.Shared/Requests/DeleteIdentityRequest.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,16 @@ | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Requests.Validators; | ||
|
||
namespace PinguApps.Appwrite.Shared.Requests; | ||
|
||
/// <summary> | ||
/// The request for deleting an identity | ||
/// </summary> | ||
public class DeleteIdentityRequest : BaseRequest<DeleteIdentityRequest, DeleteIdentityRequestValidator> | ||
{ | ||
/// <summary> | ||
/// Identity ID | ||
/// </summary> | ||
[JsonPropertyName("identityId")] | ||
public string IdentityId { get; set; } = string.Empty; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteIdentityRequestValidator.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 DeleteIdentityRequestValidator : AbstractValidator<DeleteIdentityRequest> | ||
{ | ||
public DeleteIdentityRequestValidator() | ||
{ | ||
RuleFor(request => request.IdentityId) | ||
.NotEmpty().WithMessage("Identity ID must not be empty."); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteIdentity.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,106 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Client.Clients; | ||
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 DeleteIdentity_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest { IdentityId = "validIdentityId" }; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{Constants.Endpoint}/account/identities/{request.IdentityId}") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeleteIdentity(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIdentity_ShouldHitDifferentEndpoint_WhenNewIdentityIdIsUsed() | ||
{ | ||
// Arrange | ||
var identityId = "myIdentityId"; | ||
var request = new DeleteIdentityRequest { IdentityId = identityId }; | ||
var requestUri = $"{Constants.Endpoint}/account/identities/{identityId}"; | ||
var mockRequest = _mockHttp.Expect(HttpMethod.Delete, requestUri) | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeleteIdentity(request); | ||
|
||
// Assert | ||
_mockHttp.VerifyNoOutstandingExpectation(); | ||
var matches = _mockHttp.GetMatchCount(mockRequest); | ||
Assert.Equal(1, matches); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIdentity_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest { IdentityId = "validIdentityId" }; | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeleteIdentity(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIdentity_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest { IdentityId = "validIdentityId" }; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{Constants.Endpoint}/account/identities/{request.IdentityId}") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeleteIdentity(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIdentity_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest { IdentityId = "validIdentityId" }; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{Constants.Endpoint}/account/identities/{request.IdentityId}") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeleteIdentity(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteIdentityRequestTests.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,93 @@ | ||
using FluentValidation; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
|
||
namespace PinguApps.Appwrite.Shared.Tests.Requests; | ||
public class DeleteIdentityRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_InitializesWithExpectedValues() | ||
{ | ||
// Arrange & Act | ||
var request = new DeleteIdentityRequest(); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, request.IdentityId); | ||
} | ||
|
||
[Theory] | ||
[InlineData("A string")] | ||
public void Properties_CanBeSet(string identityId) | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest(); | ||
|
||
// Act | ||
request.IdentityId = identityId; | ||
|
||
// Assert | ||
Assert.Equal(identityId, request.IdentityId); | ||
} | ||
|
||
[Fact] | ||
public void IsValid_WithValidInputs_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest | ||
{ | ||
IdentityId = "validIdentityId" | ||
}; | ||
|
||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.True(isValid); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(null)] | ||
public void IsValid_WithInvalidInputs_ReturnsFalse(string? identityId) | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest | ||
{ | ||
IdentityId = identityId! | ||
}; | ||
|
||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.False(isValid); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest | ||
{ | ||
IdentityId = "" | ||
}; | ||
|
||
// Assert | ||
Assert.Throws<ValidationException>(() => request.Validate(true)); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() | ||
{ | ||
// Arrange | ||
var request = new DeleteIdentityRequest | ||
{ | ||
IdentityId = "" | ||
}; | ||
|
||
// Act | ||
var result = request.Validate(false); | ||
|
||
// Assert | ||
Assert.False(result.IsValid); | ||
} | ||
} |