-
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 #333 from PinguApps/312-delete-team-membership
Implemented delete team membership
- Loading branch information
Showing
8 changed files
with
228 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,10 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var request = new CreateTeamMembershipRequest() | ||
var request = new DeleteTeamMembershipRequest() | ||
{ | ||
TeamId = "67142b78001c379958cb", | ||
Email = "[email protected]", | ||
Url = "https://localhost:1234/acceptTeamInvite", | ||
Name = "Your Name" | ||
MembershipId = "671448a87af3cd4babc7" | ||
}; | ||
|
||
//var clientResponse = await _client.Teams.CreateTeamMembership(request); | ||
|
@@ -36,7 +34,7 @@ public async Task Run(string[] args) | |
|
||
Console.WriteLine("############################################################################"); | ||
|
||
var serverResponse = await _server.Teams.CreateTeamMembership(request); | ||
var serverResponse = await _server.Teams.DeleteTeamMembership(request); | ||
|
||
Console.WriteLine(serverResponse.Result.Match( | ||
result => result.ToString(), | ||
|
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
101 changes: 101 additions & 0 deletions
101
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.DeleteTeamMembership.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,101 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Client.Clients; | ||
using PinguApps.Appwrite.Shared.Requests.Teams; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.DeleteTeamMembership.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,75 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Requests.Teams; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Clients.Teams; | ||
public partial class TeamsClientTests | ||
{ | ||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteTeamMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new DeleteTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.DeleteTeamMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |