-
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 #337 from PinguApps/314-task-teams-get-team-prefer…
…ences Implemented get team preferences
- Loading branch information
Showing
8 changed files
with
226 additions
and
32 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,34 +19,21 @@ public async Task Run(string[] args) | |
{ | ||
_client.SetSession(_session); | ||
|
||
var request = new UpdateTeamMembershipStatusRequest() | ||
var request = new GetTeamPreferencesRequest() | ||
{ | ||
TeamId = "67142b78001c379958cb", | ||
MembershipId = "671531b0251d3541ae46", | ||
UserId = "67143ec991a30b2a73cb", | ||
Secret = "43c2c5f0d3b2aa4f9a519be67f2b866ae8a44f132acd6dba32401cf7c7f1185e9389c8fce3bfa1e8675915bf06a2ccaedc4a756e10fac27f10103111d32a05046301fd689598bb6d25275832be90b4be682b9217ef648d1f01e97be8e10b0a8b4b424fa092e6d987e18fd65a431ed493edad846b2d3709a379e44d1df0870701" | ||
TeamId = "67142b78001c379958cb" | ||
}; | ||
|
||
//var clientResponse = await _client.Teams.UpdateTeamMembershipStatus(request); | ||
var clientResponse = await _client.Teams.GetTeamPreferences(request); | ||
|
||
//var request = new CreateTeamMembershipRequest() | ||
//{ | ||
// TeamId = "67142b78001c379958cb", | ||
// Email = "[email protected]", | ||
// Name = "TEST", | ||
// Url = "https://localhost:1234/abc" | ||
//}; | ||
|
||
//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.UpdateTeamMembershipStatus(request); | ||
var serverResponse = await _server.Teams.GetTeamPreferences(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
97 changes: 97 additions & 0 deletions
97
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.GetTeamPreferences.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,97 @@ | ||
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 GetTeamPreferences_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders(true) | ||
.Respond(TestConstants.AppJson, TestConstants.PreferencesResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamPreferences_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamPreferences_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamPreferences_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/PinguApps.Appwrite.Server.Tests/Clients/Teams/TeamsClientTests.GetTeamPreferences.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,72 @@ | ||
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 GetTeamPreferences_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders() | ||
.Respond(TestConstants.AppJson, TestConstants.PreferencesResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamPreferences_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task GetTeamPreferences_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new GetTeamPreferencesRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/prefs") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.GetTeamPreferences(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |