-
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 #335 from PinguApps/311-task-teams-update-membership
Implemented update membership
- Loading branch information
Showing
8 changed files
with
241 additions
and
20 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,23 +19,23 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var request = new CreateTeamMembershipRequest() | ||
var request = new UpdateMembershipRequest() | ||
{ | ||
TeamId = "67142b78001c379958cb", | ||
Email = "[email protected]", | ||
Name = "Pingu" | ||
MembershipId = "671515e5bf4d9b8849c8", | ||
Roles = ["server"] | ||
}; | ||
|
||
var clientResponse = await _client.Teams.CreateTeamMembership(request); | ||
//var clientResponse = await _client.Teams.UpdateMembership(request); | ||
|
||
Console.WriteLine(clientResponse.Result.Match( | ||
result => result.ToString(), | ||
appwriteError => appwriteError.Message, | ||
internalError => internalError.Message)); | ||
//Console.WriteLine(clientResponse.Result.Match( | ||
// result => result.ToString(), | ||
// appwriteError => appwriteError.Message, | ||
// internalError => internalError.Message)); | ||
|
||
Console.WriteLine("############################################################################"); | ||
|
||
var serverResponse = await _server.Teams.CreateTeamMembership(request); | ||
var serverResponse = await _server.Teams.UpdateMembership(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
105 changes: 105 additions & 0 deletions
105
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.UpdateMembership.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,105 @@ | ||
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 UpdateMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders(true) | ||
.Respond(TestConstants.AppJson, TestConstants.MembershipResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateMembership_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{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.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{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.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.UpdateMembership.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,78 @@ | ||
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 UpdateMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Respond(TestConstants.AppJson, TestConstants.MembershipResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new UpdateMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId(), | ||
// Add other necessary fields for the request | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Patch, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships/{request.MembershipId}") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.UpdateMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |