From a1bef6227781e33b0a7428ca2d71c44e1baa45fb Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Sat, 12 Oct 2024 01:44:33 +0100 Subject: [PATCH 1/3] implemented update email verification --- src/PinguApps.Appwrite.Playground/App.cs | 7 ++++--- .../Clients/IUsersClient.cs | 8 +++++++- .../Clients/UsersClient.cs | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/PinguApps.Appwrite.Playground/App.cs b/src/PinguApps.Appwrite.Playground/App.cs index 72b0a082..73555236 100644 --- a/src/PinguApps.Appwrite.Playground/App.cs +++ b/src/PinguApps.Appwrite.Playground/App.cs @@ -17,12 +17,13 @@ public App(Client.IAppwriteClient client, Server.Clients.IAppwriteClient server, public async Task Run(string[] args) { - var request = new CreateTokenRequest() + var request = new UpdateEmailVerificationRequest() { - UserId = "664aac1a00113f82e620" + UserId = "664aac1a00113f82e620", + EmailVerification = true }; - var response = await _server.Users.CreateToken(request); + var response = await _server.Users.UpdateEmailVerification(request); Console.WriteLine(response.Result.Match( result => result.ToString(), diff --git a/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs index d9ab29ee..f23ffef9 100644 --- a/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs @@ -334,7 +334,13 @@ public interface IUsersClient /// The request content /// The token Task> CreateToken(CreateTokenRequest request); - [Obsolete("This method hasn't yet been implemented.", true)] + + /// + /// Update the user email verification status by its unique ID + /// Appwrite Docs + /// + /// The request content + /// The user Task> UpdateEmailVerification(UpdateEmailVerificationRequest request); [Obsolete("This method hasn't yet been implemented.", true)] Task> UpdatePhoneVerification(UpdatePhoneVerificationRequest request); diff --git a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs index 7f5a90b2..cfbea96c 100644 --- a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs +++ b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs @@ -701,9 +701,22 @@ public async Task> CreateToken(CreateTokenRequest request) } } - [ExcludeFromCodeCoverage] /// - public Task> UpdateEmailVerification(UpdateEmailVerificationRequest request) => throw new NotImplementedException(); + public async Task> UpdateEmailVerification(UpdateEmailVerificationRequest request) + { + try + { + request.Validate(true); + + var result = await _usersApi.UpdateEmailVerification(request.UserId, request); + + return result.GetApiResponse(); + } + catch (Exception e) + { + return e.GetExceptionResponse(); + } + } [ExcludeFromCodeCoverage] /// From dc0857192f00baf842b69ce8491fdb5d10cf7748 Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Sat, 12 Oct 2024 01:46:08 +0100 Subject: [PATCH 2/3] added tests for update email verification --- ...sersClientTests.UpdateEmailVerification.cs | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateEmailVerification.cs diff --git a/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateEmailVerification.cs b/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateEmailVerification.cs new file mode 100644 index 00000000..e1881634 --- /dev/null +++ b/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateEmailVerification.cs @@ -0,0 +1,78 @@ +using System.Net; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Tests; +using PinguApps.Appwrite.Shared.Utils; +using RichardSzalay.MockHttp; + +namespace PinguApps.Appwrite.Server.Tests.Clients.Users; +public partial class UsersClientTests +{ + [Fact] + public async Task UpdateEmailVerification_ShouldReturnSuccess_WhenApiCallSucceeds() + { + // Arrange + var request = new UpdateEmailVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + // Add other properties as needed + }; + + _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/verification") + .ExpectedHeaders() + .WithJsonContent(request) + .Respond(Constants.AppJson, Constants.UserResponse); + + // Act + var result = await _appwriteClient.Users.UpdateEmailVerification(request); + + // Assert + Assert.True(result.Success); + } + + [Fact] + public async Task UpdateEmailVerification_ShouldHandleException_WhenApiCallFails() + { + // Arrange + var request = new UpdateEmailVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + // Add other properties as needed + }; + + _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/verification") + .ExpectedHeaders() + .WithJsonContent(request) + .Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); + + // Act + var result = await _appwriteClient.Users.UpdateEmailVerification(request); + + // Assert + Assert.True(result.IsError); + Assert.True(result.IsAppwriteError); + } + + [Fact] + public async Task UpdateEmailVerification_ShouldReturnErrorResponse_WhenExceptionOccurs() + { + // Arrange + var request = new UpdateEmailVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + // Add other properties as needed + }; + + _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/verification") + .ExpectedHeaders() + .WithJsonContent(request) + .Throw(new HttpRequestException("An error occurred")); + + // Act + var result = await _appwriteClient.Users.UpdateEmailVerification(request); + + // Assert + Assert.False(result.Success); + Assert.True(result.IsInternalError); + Assert.Equal("An error occurred", result.Result.AsT2.Message); + } +} From dba26ce76997ac45c7bd9da05492701d9241ba80 Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Sat, 12 Oct 2024 01:46:30 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f8c40bc0..6351291e 100644 --- a/README.md +++ b/README.md @@ -141,9 +141,9 @@ string emailAddressOrErrorMessage = userResponse.Result.Match( ## ⌛ Progress -![Server & Client - 95 / 292](https://img.shields.io/badge/Server_&_Client-95%20%2F%20292-red?style=for-the-badge) +![Server & Client - 96 / 292](https://img.shields.io/badge/Server_&_Client-96%20%2F%20292-red?style=for-the-badge) -![Server - 51 / 202](https://img.shields.io/badge/Server-51%20%2F%20202-red?style=for-the-badge) +![Server - 52 / 202](https://img.shields.io/badge/Server-52%20%2F%20202-red?style=for-the-badge) ![Client - 44 / 90](https://img.shields.io/badge/Client-44%20%2F%2090-gold?style=for-the-badge) @@ -208,7 +208,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match( | [Create Phone Verification (Confirmation)](https://appwrite.io/docs/references/1.6.x/client-rest/account#updatePhoneVerification) | ✅ | ❌ | | ### Users -![Account - 40 / 42](https://img.shields.io/badge/Users-40%20%2F%2042-forestgreen?style=for-the-badge) +![Account - 41 / 42](https://img.shields.io/badge/Users-40%20%2F%2042-forestgreen?style=for-the-badge) | Endpoint | Client | Server | |:-:|:-:|:-:| @@ -252,7 +252,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match( | [Update User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateTarget) | ❌ | ✅ | | [Delete User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#deleteTarget) | ❌ | ✅ | | [Create Token](https://appwrite.io/docs/references/1.6.x/server-rest/users#createToken) | ❌ | ✅ | -| [Update Email Verification](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateEmailVerification) | ❌ | ⬛ | +| [Update Email Verification](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateEmailVerification) | ❌ | ✅ | | [Update Phone Verification](https://appwrite.io/docs/references/1.6.x/server-rest/users#updatePhoneVerification) | ❌ | ⬛ | ### Teams