-
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 #31 from PinguApps/26-add-client-createaccount-end…
…point 26 add client CreateAccount endpoint
- Loading branch information
Showing
6 changed files
with
90 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using PinguApps.Appwrite.Shared; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
using PinguApps.Appwrite.Shared.Responses; | ||
|
||
namespace PinguApps.Appwrite.Client; | ||
public interface IAccountClient | ||
{ | ||
Task<AppwriteResult<User>> Create(CreateAccountRequest request); | ||
Task<AppwriteResult<User>> Get(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using PinguApps.Appwrite.Client; | ||
using PinguApps.Appwrite.Server.Servers; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
|
||
namespace PinguApps.Appwrite.Playground; | ||
internal class App | ||
|
@@ -20,21 +21,27 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var result = await _client.Account.Get(); | ||
//var result = await _client.Account.Get(); | ||
|
||
//result.Result.Switch( | ||
// account => Console.WriteLine(account.Email), | ||
// appwriteError => Console.WriteLine(appwriteError.Message), | ||
// internalError => Console.WriteLine(internalError.Message) | ||
//); | ||
|
||
var request = new CreateAccountRequest | ||
{ | ||
Email = "[email protected]", | ||
Password = "ThisIsMyPassword", | ||
Name = "Two Names" | ||
}; | ||
|
||
var result = await _client.Account.Create(request); | ||
|
||
result.Result.Switch( | ||
account => Console.WriteLine(account.Email), | ||
appwriteError => Console.WriteLine(appwriteError.Message), | ||
internalError => Console.WriteLine(internalError.Message) | ||
); | ||
|
||
//var request = new CreateAccountRequest | ||
//{ | ||
// Email = "[email protected]", | ||
// Password = "ThisIsMyPassword", | ||
// Name = "Two Names" | ||
//}; | ||
|
||
//var result = await _server.Account.Create(request); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System.Net; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PinguApps.Appwrite.Shared.Requests; | ||
using PinguApps.Appwrite.Tests.Shared; | ||
using Refit; | ||
using RichardSzalay.MockHttp; | ||
|
@@ -59,6 +60,53 @@ public async Task Get_ShouldHandleException_WhenApiCallFails() | |
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateAccountRequest() | ||
{ | ||
Email = "[email protected]", | ||
Password = "password", | ||
Name = "name" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(Constants.AppJson, Constants.UserResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Create(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateAccountRequest() | ||
{ | ||
Email = "[email protected]", | ||
Password = "password", | ||
Name = "name" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request) | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Account.Create(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
} | ||
|
||
public static class AccountTestsExtensions | ||
|