-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database indexes #555
Merged
Merged
Database indexes #555
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b44d450
Implemented list indexes
pingu2k4 519b176
added tests for list indexes
pingu2k4 b0320c7
implemented create index
pingu2k4 2a3faa2
added tests for create index
pingu2k4 168c183
implemented delete index
pingu2k4 506f445
added tests for delete index
pingu2k4 e254695
implemented get index
pingu2k4 b77d853
added tests for get index
pingu2k4 2243fe7
Update README.md
pingu2k4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
88 changes: 88 additions & 0 deletions
88
tests/PinguApps.Appwrite.Server.Tests/Clients/Databases/DatabasesClientTests.CreateIndex.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,88 @@ | ||
using System.Net; | ||
using PinguApps.Appwrite.Shared.Enums; | ||
using PinguApps.Appwrite.Shared.Requests.Databases; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Clients.Databases; | ||
public partial class DatabasesClientTests | ||
{ | ||
[Fact] | ||
public async Task CreateIndex_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new CreateIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "myIndex", | ||
IndexType = IndexType.Unique, | ||
Attributes = ["new_int"], | ||
Orders = [SortDirection.Asc] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes") | ||
.ExpectedHeaders() | ||
.Respond(TestConstants.AppJson, TestConstants.IndexResponse); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.CreateIndex(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateIndex_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new CreateIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "myIndex", | ||
IndexType = IndexType.Unique, | ||
Attributes = ["new_int"], | ||
Orders = [SortDirection.Asc] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.CreateIndex(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateIndex_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new CreateIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "myIndex", | ||
IndexType = IndexType.Unique, | ||
Attributes = ["new_int"], | ||
Orders = [SortDirection.Asc] | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.CreateIndex(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/Databases/DatabasesClientTests.DeleteIndex.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.Databases; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
using PinguApps.Appwrite.Shared.Utils; | ||
using RichardSzalay.MockHttp; | ||
|
||
namespace PinguApps.Appwrite.Server.Tests.Clients.Databases; | ||
public partial class DatabasesClientTests | ||
{ | ||
[Fact] | ||
public async Task DeleteIndex_ShouldReturnSuccess_WhenApiCallSucceeds() | ||
{ | ||
// Arrange | ||
var request = new DeleteIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "indexKey" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes/{request.Key}") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.NoContent); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.DeleteIndex(request); | ||
|
||
// Assert | ||
Assert.True(result.Success); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIndex_ShouldHandleException_WhenApiCallFails() | ||
{ | ||
// Arrange | ||
var request = new DeleteIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "indexKey" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes/{request.Key}") | ||
.ExpectedHeaders() | ||
.Respond(HttpStatusCode.BadRequest, TestConstants.AppJson, TestConstants.AppwriteError); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.DeleteIndex(request); | ||
|
||
// Assert | ||
Assert.True(result.IsError); | ||
Assert.True(result.IsAppwriteError); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteIndex_ShouldReturnErrorResponse_WhenExceptionOccurs() | ||
{ | ||
// Arrange | ||
var request = new DeleteIndexRequest | ||
{ | ||
DatabaseId = IdUtils.GenerateUniqueId(), | ||
CollectionId = IdUtils.GenerateUniqueId(), | ||
Key = "indexKey" | ||
}; | ||
|
||
_mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/indexes/{request.Key}") | ||
.ExpectedHeaders() | ||
.Throw(new HttpRequestException("An error occurred")); | ||
|
||
// Act | ||
var result = await _appwriteClient.Databases.DeleteIndex(request); | ||
|
||
// Assert | ||
Assert.False(result.Success); | ||
Assert.True(result.IsInternalError); | ||
Assert.Equal("An error occurred", result.Result.AsT2.Message); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation Error Handling Not Specific
Tell me more
What is the issue?
The validation of requests is marked as required (true), but there's no error handling specific to validation failures, which could mask validation errors as generic exceptions.
Why this matters
When validation fails, it will be caught in the generic catch block, making it difficult to distinguish between validation errors and other types of exceptions. This affects error handling and debugging.