-
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 #294 from PinguApps/290-delete-push-target
Implemented delete push target
- Loading branch information
Showing
9 changed files
with
259 additions
and
8 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
14 changes: 14 additions & 0 deletions
14
src/PinguApps.Appwrite.Shared/Requests/Account/DeletePushTargetRequest.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,14 @@ | ||
using System.Text.Json.Serialization; | ||
using PinguApps.Appwrite.Shared.Attributes; | ||
using PinguApps.Appwrite.Shared.Requests.Account.Validators; | ||
|
||
namespace PinguApps.Appwrite.Shared.Requests.Account; | ||
public class DeletePushTargetRequest : BaseRequest<DeletePushTargetRequest, DeletePushTargetRequestValidator> | ||
{ | ||
/// <summary> | ||
/// Target ID. | ||
/// </summary> | ||
[JsonPropertyName("targetId")] | ||
[SdkExclude] | ||
public string TargetId { get; set; } = string.Empty; | ||
} |
11 changes: 11 additions & 0 deletions
11
...PinguApps.Appwrite.Shared/Requests/Account/Validators/DeletePushTargetRequestValidator.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.Account.Validators; | ||
public class DeletePushTargetRequestValidator : AbstractValidator<DeletePushTargetRequest> | ||
{ | ||
public DeletePushTargetRequestValidator() | ||
{ | ||
RuleFor(x => x.TargetId) | ||
.NotEmpty().WithMessage("TargetId is required."); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeletePushTarget.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,97 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Client.Clients; | ||
using PinguApps.Appwrite.Shared.Requests.Account; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Account; | ||
public partial class AccountClientTests | ||
{ | ||
[Fact] | ||
public async Task DeletePushTarget_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/account/targets/{request.TargetId}/push") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeletePushTarget(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task DeletePushTarget_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeletePushTarget(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task DeletePushTarget_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/account/targets/{request.TargetId}/push") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeletePushTarget(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task DeletePushTarget_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/account/targets/{request.TargetId}/push") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.DeletePushTarget(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeletePushTargetRequestTests.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,103 @@ | ||
using FluentValidation; | ||
using PinguApps.Appwrite.Shared.Requests.Account; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
|
||
namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; | ||
public class DeletePushTargetRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_InitializesWithExpectedValues() | ||
{ | ||
// Arrange & Act | ||
var request = new DeletePushTargetRequest(); | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, request.TargetId); | ||
} | ||
|
||
[Fact] | ||
public void Properties_CanBeSet() | ||
{ | ||
var targetId = IdUtils.GenerateUniqueId(); | ||
|
||
// Arrange | ||
var request = new DeletePushTargetRequest(); | ||
|
||
// Act | ||
request.TargetId = targetId; | ||
|
||
// Assert | ||
Assert.Equal(targetId, request.TargetId); | ||
} | ||
|
||
public static TheoryData<DeletePushTargetRequest> ValidRequestsData = | ||
[ | ||
new DeletePushTargetRequest | ||
{ | ||
TargetId = IdUtils.GenerateUniqueId() | ||
} | ||
]; | ||
|
||
[Theory] | ||
[MemberData(nameof(ValidRequestsData))] | ||
public void IsValid_WithValidData_ReturnsTrue(DeletePushTargetRequest request) | ||
{ | ||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.True(isValid); | ||
} | ||
|
||
public static TheoryData<DeletePushTargetRequest> InvalidRequestsData = | ||
[ | ||
new DeletePushTargetRequest | ||
{ | ||
TargetId = "" | ||
}, | ||
new DeletePushTargetRequest | ||
{ | ||
TargetId = null! | ||
} | ||
]; | ||
|
||
[Theory] | ||
[MemberData(nameof(InvalidRequestsData))] | ||
public void IsValid_WithInvalidData_ReturnsFalse(DeletePushTargetRequest request) | ||
{ | ||
// Act | ||
var isValid = request.IsValid(); | ||
|
||
// Assert | ||
Assert.False(isValid); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = "" | ||
}; | ||
|
||
// Assert | ||
Assert.Throws<ValidationException>(() => request.Validate(true)); | ||
} | ||
|
||
[Fact] | ||
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() | ||
{ | ||
// Arrange | ||
var request = new DeletePushTargetRequest | ||
{ | ||
TargetId = "" | ||
}; | ||
|
||
// Act | ||
var result = request.Validate(false); | ||
|
||
// Assert | ||
Assert.False(result.IsValid); | ||
} | ||
} |