-
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 #334 from PinguApps/312-delete-team-membership
Implemented Get team membership
- Loading branch information
Showing
13 changed files
with
286 additions
and
25 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,22 +19,23 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var request = new DeleteTeamMembershipRequest() | ||
var request = new CreateTeamMembershipRequest() | ||
{ | ||
TeamId = "67142b78001c379958cb", | ||
MembershipId = "671448a87af3cd4babc7" | ||
Email = "[email protected]", | ||
Name = "Pingu" | ||
}; | ||
|
||
//var clientResponse = await _client.Teams.CreateTeamMembership(request); | ||
var clientResponse = await _client.Teams.CreateTeamMembership(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.DeleteTeamMembership(request); | ||
var serverResponse = await _server.Teams.CreateTeamMembership(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
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,7 @@ | ||
namespace PinguApps.Appwrite.Shared.Enums; | ||
public enum ValidationContext | ||
{ | ||
None, | ||
Client, | ||
Server | ||
} |
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 |
---|---|---|
|
@@ -16,7 +16,8 @@ public async Task CreateTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | |
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
Roles = ["role1", "role2"], | ||
Url = "https://localhost:1234" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
|
@@ -41,7 +42,8 @@ public async Task CreateTeamMembership_ShouldReturnError_WhenSessionIsNull() | |
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
Roles = ["role1", "role2"], | ||
Url = "https://localhost:1234" | ||
}; | ||
|
||
// Act | ||
|
@@ -61,7 +63,8 @@ public async Task CreateTeamMembership_ShouldHandleException_WhenApiCallFails() | |
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
Roles = ["role1", "role2"], | ||
Url = "https://localhost:1234" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
|
@@ -87,7 +90,8 @@ public async Task CreateTeamMembership_ShouldReturnErrorResponse_WhenExceptionOc | |
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
Roles = ["role1", "role2"], | ||
Url = "https://localhost:1234" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
|
101 changes: 101 additions & 0 deletions
101
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.GetTeamMembership.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 GetTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new GetTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{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.GetTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamMembership_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new GetTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new GetTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{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.GetTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new GetTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
MembershipId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{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.GetTeamMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
Oops, something went wrong.