Skip to content

Commit

Permalink
Added tests for client Create Account
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 4, 2024
1 parent 478b024 commit eff2394
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/PinguApps.Appwrite.Client.Tests/AccountTests.cs
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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eff2394

Please sign in to comment.