diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.CreateDocument.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.CreateDocument.cs index 7fda4022..1f44e84f 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.CreateDocument.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.CreateDocument.cs @@ -29,6 +29,30 @@ public async Task CreateDocument_ShouldReturnSuccess_WhenApiCallSucceeds() Assert.True(result.Success); } + [Fact] + public async Task CreateDocument_ShouldIncludeSessionHeaders_WhenProvided() + { + // Arrange + var request = CreateDocumentRequest.CreateBuilder() + .WithDatabaseId(IdUtils.GenerateUniqueId()) + .WithCollectionId(IdUtils.GenerateUniqueId()) + .AddField("AttributeName", "MyValue") + .Build(); + + _mockHttp.Expect(HttpMethod.Post, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/documents") + .ExpectedHeaders() + .WithJsonContent(request, _jsonSerializerOptions) + .Respond(TestConstants.AppJson, TestConstants.DocumentResponse); + + _appwriteClient.SetSession(TestConstants.Session); + + // Act + var result = await _appwriteClient.Databases.CreateDocument(request); + + // Assert + _mockHttp.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task CreateDocument_ShouldHandleException_WhenApiCallFails() { diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.DeleteDocument.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.DeleteDocument.cs index e713626b..ec2df9df 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.DeleteDocument.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.DeleteDocument.cs @@ -29,6 +29,30 @@ public async Task DeleteDocument_ShouldReturnSuccess_WhenApiCallSucceeds() Assert.True(result.Success); } + [Fact] + public async Task DeleteDocument_ShouldIncludeSessionHeaders_WhenProvided() + { + // Arrange + var request = new DeleteDocumentRequest + { + DatabaseId = IdUtils.GenerateUniqueId(), + CollectionId = IdUtils.GenerateUniqueId(), + DocumentId = IdUtils.GenerateUniqueId() + }; + + _mockHttp.Expect(HttpMethod.Delete, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/documents/{request.DocumentId}") + .ExpectedHeaders() + .Respond(HttpStatusCode.NoContent); + + _appwriteClient.SetSession(TestConstants.Session); + + // Act + var result = await _appwriteClient.Databases.DeleteDocument(request); + + // Assert + _mockHttp.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task DeleteDocument_ShouldHandleException_WhenApiCallFails() { diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.GetDocument.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.GetDocument.cs index 131e41eb..29af6f14 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.GetDocument.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.GetDocument.cs @@ -29,6 +29,30 @@ public async Task GetDocument_ShouldReturnSuccess_WhenApiCallSucceeds() Assert.True(result.Success); } + [Fact] + public async Task GetDocument_ShouldIncludeSessionHeaders_WhenProvided() + { + // Arrange + var request = new GetDocumentRequest + { + DatabaseId = IdUtils.GenerateUniqueId(), + CollectionId = IdUtils.GenerateUniqueId(), + DocumentId = IdUtils.GenerateUniqueId(), + }; + + _mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/documents/{request.DocumentId}") + .ExpectedHeaders() + .Respond(TestConstants.AppJson, TestConstants.DocumentResponse); + + _appwriteClient.SetSession(TestConstants.Session); + + // Act + var result = await _appwriteClient.Databases.GetDocument(request); + + // Assert + _mockHttp.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task GetDocument_ShouldProvideQueryParams_WhenQueriesProvided() { diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.ListDocuments.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.ListDocuments.cs index 9b7aab76..1107abe5 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.ListDocuments.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.ListDocuments.cs @@ -28,6 +28,29 @@ public async Task ListDocuments_ShouldReturnSuccess_WhenApiCallSucceeds() Assert.True(result.Success); } + [Fact] + public async Task ListDocuments_ShouldIncludeSessionHeaders_WhenProvided() + { + // Arrange + var request = new ListDocumentsRequest + { + DatabaseId = IdUtils.GenerateUniqueId(), + CollectionId = IdUtils.GenerateUniqueId() + }; + + _mockHttp.Expect(HttpMethod.Get, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/documents") + .ExpectedHeaders(true) + .Respond(TestConstants.AppJson, TestConstants.DocumentsListResponse); + + _appwriteClient.SetSession(TestConstants.Session); + + // Act + var result = await _appwriteClient.Databases.ListDocuments(request); + + // Assert + _mockHttp.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task ListDocuments_ShouldProvideQueryParams_WhenQueriesProvided() { diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.UpdateDocument.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.UpdateDocument.cs index 7cd92fac..05e95f9a 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.UpdateDocument.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Databases/DatabasesClientTests.UpdateDocument.cs @@ -29,6 +29,30 @@ public async Task UpdateDocument_ShouldReturnSuccess_WhenApiCallSucceeds() Assert.True(result.Success); } + [Fact] + public async Task UpdateDocument_ShouldIncludeSessionHeaders_WhenProvided() + { + // Arrange + var request = UpdateDocumentRequest.CreateBuilder() + .WithDatabaseId(IdUtils.GenerateUniqueId()) + .WithCollectionId(IdUtils.GenerateUniqueId()) + .WithDocumentId(IdUtils.GenerateUniqueId()) + .AddField("test", "test") + .Build(); + + _mockHttp.Expect(HttpMethod.Patch, $"{TestConstants.Endpoint}/databases/{request.DatabaseId}/collections/{request.CollectionId}/documents/{request.DocumentId}") + .ExpectedHeaders(true) + .Respond(TestConstants.AppJson, TestConstants.DocumentResponse); + + _appwriteClient.SetSession(TestConstants.Session); + + // Act + var result = await _appwriteClient.Databases.UpdateDocument(request); + + // Assert + _mockHttp.VerifyNoOutstandingExpectation(); + } + [Fact] public async Task UpdateDocument_ShouldHandleException_WhenApiCallFails() {