From 854e4642abdb56af91484111ea0f36398f5e37c1 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:33:09 -0600 Subject: [PATCH] =?UTF-8?q?tests:=20add=20integration=20tests=20for=20rema?= =?UTF-8?q?ining=20=F0=9F=A5=B2=20and=20=F0=9F=98=80=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Integration/AnthropicApiClientTests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs index ca97570..ba2a6a2 100644 --- a/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs +++ b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs @@ -1032,4 +1032,70 @@ public class AnthropicApiClientTests : IntegrationTest result.Value.CancelInitiatedAt.Should().Be(DateTimeOffset.Parse("2024-08-20T18:37:24.100435Z")); result.Value.ResultsUrl.Should().Be("https://api.anthropic.com/v1/messages/batches/msgbatch_013Zva2CMHLNnXjNJJKqJ2EF/results"); } + + [Fact] + public async Task CreateMessageBatchAsync_WhenCalledAndErrorReturned_ItShouldHandleError() + { + _mockHttpMessageHandler + .WhenCreateMessageBatchRequest() + .Respond( + HttpStatusCode.BadRequest, + "application/json", + @"{ + ""type"": ""error"", + ""error"": { + ""type"": ""invalid_request_error"", + ""message"": ""messages: roles must alternate between user and assistant, but found multiple user roles in a row"" + } + }" + ); + + var request = new MessageBatchRequest([new("custom_id", new())]); + + var result = await Client.CreateMessageBatchAsync(request); + + result.IsSuccess.Should().BeFalse(); + result.Error.Should().BeOfType(); + result.Error.Error.Should().BeOfType(); + } + + [Fact] + public async Task CreateMessageBatchAsync_WhenCalledRequestFailsAndErrorCanNotBeDeserialized_ItShouldReturnUnknownError() + { + _mockHttpMessageHandler + .WhenCreateMessageBatchRequest() + .Respond( + HttpStatusCode.BadRequest, + "application/json", + @"{}" + ); + + var request = new MessageBatchRequest([new("custom_id", new())]); + + var result = await Client.CreateMessageBatchAsync(request); + + result.IsSuccess.Should().BeFalse(); + result.Error.Should().BeOfType(); + result.Error.Error.Should().BeOfType(); + } + + [Fact] + public async Task CreateMessageBatchAsync_WhenCalledRequestSucceedsAndCanNotDeserializeResponse_ItShouldReturnEmptyResponse() + { + _mockHttpMessageHandler + .WhenCreateMessageBatchRequest() + .Respond( + HttpStatusCode.OK, + "application/json", + @"{}" + ); + + var request = new MessageBatchRequest([new("custom_id", new())]); + + var result = await Client.CreateMessageBatchAsync(request); + + result.IsSuccess.Should().BeTrue(); + result.Value.Should().BeOfType(); + result.Value.Should().BeEquivalentTo(new MessageBatchResponse()); + } } \ No newline at end of file