-
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.
- Loading branch information
Showing
3 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...guApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateAnonymousSession.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,55 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Servers.Account; | ||
public partial class AccountServerTests | ||
{ | ||
[Fact] | ||
public async Task CreateAnonymousSession_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account/sessions/anonymous") | ||
.ExpectedHeaders() | ||
.Respond(Constants.AppJson, Constants.SessionResponse); | ||
|
||
// Act | ||
var result = await _appwriteServer.Account.CreateAnonymousSession(); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAnonymousSession_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account/sessions/anonymous") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteServer.Account.CreateAnonymousSession(); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAnonymousSession_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
_mockHttp.Expect(HttpMethod.Post, $"{Constants.Endpoint}/account/sessions/anonymous") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteServer.Account.CreateAnonymousSession(); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountTestsExtensions.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,19 @@ | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Servers.Account; | ||
|
||
public static class AccountTestsExtensions | ||
{ | ||
public static MockedRequest ExpectedHeaders(this MockedRequest request) | ||
{ | ||
return request | ||
.WithHeaders("x-appwrite-project", Constants.ProjectId) | ||
.WithHeaders("x-appwrite-key", Constants.ApiKey) | ||
.WithHeaders("x-sdk-name", Constants.SdkName) | ||
.WithHeaders("x-sdk-platform", "server") | ||
.WithHeaders("x-sdk-language", Constants.SdkLanguage) | ||
.WithHeaders("x-sdk-version", Constants.SdkVersion) | ||
.WithHeaders("x-appwrite-response-format", Constants.AppwriteResponseFormat); | ||
} | ||
} |