-
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 #61 from PinguApps/39-update-phone-implementation
Update phone implementation
- Loading branch information
Showing
8 changed files
with
174 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
21 changes: 21 additions & 0 deletions
21
src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneRequest.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,21 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PinguApps.Appwrite.Shared.Requests; | ||
|
||
/// <summary> | ||
/// The request for updating a users phone | ||
/// </summary> | ||
public class UpdatePhoneRequest | ||
{ | ||
/// <summary> | ||
/// Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212 | ||
/// </summary> | ||
[JsonPropertyName("phone")] | ||
public string Phone { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// New user password. Must be at least 8 chars | ||
/// </summary> | ||
[JsonPropertyName("password")] | ||
public string Password { get; set; } = string.Empty; | ||
} |
83 changes: 83 additions & 0 deletions
83
tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhone.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,83 @@ | ||
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 UpdatePhone_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new UpdatePhoneRequest() | ||
{ | ||
Password = "Password", | ||
Phone = "+14155552671" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/account/phone") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request) | ||
.Respond(Constants.AppJson, Constants.UserResponse); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.UpdatePhone(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdatePhone_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new UpdatePhoneRequest() | ||
{ | ||
Password = "Password", | ||
Phone = "+14155552671" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/account/phone") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.UpdatePhone(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdatePhone_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new UpdatePhoneRequest() | ||
{ | ||
Password = "Password", | ||
Phone = "+14155552671" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/account/phone") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(Constants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.UpdatePhone(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneRequestTests.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,36 @@ | ||
using PinguApps.Appwrite.Shared.Requests; | ||
|
||
namespace PinguApps.Appwrite.Shared.Tests.Requests; | ||
|
||
public class UpdatePhoneRequestTests | ||
{ | ||
[Fact] | ||
public void Constructor_InitializesWithExpectedValues() | ||
{ | ||
// Arrange & Act | ||
var request = new UpdatePhoneRequest(); | ||
|
||
// Assert | ||
Assert.NotNull(request.Password); | ||
Assert.NotNull(request.Phone); | ||
Assert.Equal(string.Empty, request.Password); | ||
Assert.Equal(string.Empty, request.Phone); | ||
} | ||
|
||
[Theory] | ||
[InlineData("password", "+123456789")] | ||
[InlineData("drowssap", "+987654321")] | ||
public void Properties_CanBeSet(string password, string phone) | ||
{ | ||
// Arrange | ||
var request = new UpdatePhoneRequest(); | ||
|
||
// Act | ||
request.Password = password; | ||
request.Phone = phone; | ||
|
||
// Assert | ||
Assert.Equal(password, request.Password); | ||
Assert.Equal(phone, request.Phone); | ||
} | ||
} |