-
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 #331 from PinguApps/308-task-teams-list-team-membe…
…rships Implemented list team memberships
- Loading branch information
Showing
12 changed files
with
356 additions
and
39 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 |
---|---|---|
|
@@ -15,20 +15,3 @@ jobs: | |
contents: read | ||
issues: read | ||
checks: write | ||
|
||
run_code_review: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Code Review GPT | ||
uses: mattzcarey/[email protected] | ||
with: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
MODEL: 'gpt-4o' | ||
GITHUB_TOKEN: ${{ github.token }} |
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
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
130 changes: 130 additions & 0 deletions
130
tests/PinguApps.Appwrite.Client.Tests/Clients/Teams/TeamsClientTests.ListTeamMemberships.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,130 @@ | ||
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 ListTeamMemberships_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new ListTeamMembershipsRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.Respond(TestConstants.AppJson, TestConstants.MembershipsListResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeamMemberships(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeamMemberships_ShouldProvideQueryParams_WhenQueriesAndSearchProvided() | ||
{ | ||
// Arrange | ||
var query = Query.Limit(5); | ||
var search = "SearchString"; | ||
var request = new ListTeamMembershipsRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId(), | ||
Queries = [query], | ||
Search = search | ||
}; | ||
|
||
var expectedQueryParams = new Dictionary<string, string> | ||
{ | ||
{ "queries[]", query.GetQueryString() }, | ||
{ "search", search } | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.WithQueryString($"queries[]={query.GetQueryString()}&search={search}") | ||
.Respond(TestConstants.AppJson, TestConstants.LogsListResponse); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeamMemberships(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeamMemberships_ShouldReturnError_WhenSessionIsNull() | ||
{ | ||
// Arrange | ||
var request = new ListTeamMembershipsRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeamMemberships(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal(ISessionAware.SessionExceptionMessage, result.Result.AsT2.Message); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeamMemberships_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new ListTeamMembershipsRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeamMemberships(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task ListTeamMemberships_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new ListTeamMembershipsRequest | ||
{ | ||
TeamId = IdUtils.GenerateUniqueId() | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/teams/{request.TeamId}/memberships") | ||
.ExpectedHeaders(true) | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
_appwriteClient.SetSession(TestConstants.Session); | ||
|
||
// Act | ||
var result = await _appwriteClient.Teams.ListTeamMemberships(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
Oops, something went wrong.