-
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 #332 from PinguApps/309-create-team-membership
Implemented create team membership
- Loading branch information
Showing
12 changed files
with
280 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/PinguApps.Appwrite.Playground/* |
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,21 +19,24 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var request = new ListTeamMembershipsRequest() | ||
var request = new CreateTeamMembershipRequest() | ||
{ | ||
TeamId = "67142b78001c379958cb" | ||
TeamId = "67142b78001c379958cb", | ||
Email = "[email protected]", | ||
Url = "https://localhost:1234/acceptTeamInvite", | ||
Name = "Your Name" | ||
}; | ||
|
||
var clientResponse = await _client.Teams.ListTeamMemberships(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.ListTeamMemberships(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
108 changes: 108 additions & 0 deletions
108
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.CreateTeamMembership.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,108 @@ | ||
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 CreateTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Respond(TestConstants.AppJson, TestConstants.MembershipResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTeamMembership_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTeamMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTeamMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.CreateTeamMembership.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,81 @@ | ||
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 CreateTeamMembership_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Respond(TestConstants.AppJson, TestConstants.MembershipResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTeamMembership_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateTeamMembership_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new CreateTeamMembershipRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Email = "[email protected]", | ||
Roles = ["role1", "role2"] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders() | ||
.WithJsonContent(request, _jsonSerializerOptions) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.CreateTeamMembership(request); | ||
|
||
// 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
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 |
---|---|---|
|
@@ -329,6 +329,26 @@ public static class TestConstants | |
} | ||
"""; | ||
|
||
public const string MembershipResponse = """ | ||
{ | ||
"$id": "5e5ea5c16897e", | ||
"$createdAt": "2020-10-15T06:38:00.000+00:00", | ||
"$updatedAt": "2020-10-15T06:38:00.000+00:00", | ||
"userId": "5e5ea5c16897e", | ||
"userName": "John Doe", | ||
"userEmail": "[email protected]", | ||
"teamId": "5e5ea5c16897e", | ||
"teamName": "VIP", | ||
"invited": "2020-10-15T06:38:00.000+00:00", | ||
"joined": "2020-10-15T06:38:00.000+00:00", | ||
"confirm": false, | ||
"mfa": false, | ||
"roles": [ | ||
"owner" | ||
] | ||
} | ||
"""; | ||
|
||
public const string TargetListResponse = """ | ||
{ | ||
"total": 5, | ||
|