Skip to content

Commit

Permalink
add tests for content type
Browse files Browse the repository at this point in the history
  • Loading branch information
gcbeattyAWS committed Dec 12, 2024
1 parent cb60ba2 commit 56af10b
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,83 @@ public void ToHttpResponse_APIGatewayHttpApiV2ProxyResponse_HandlesNonJsonRespon
Assert.Equal("{\"message\":\"Internal Server Error\"}", bodyContent);
Assert.Equal(35, httpResponse.ContentLength);
}

[Fact]
public void ToHttpResponse_APIGatewayProxyResponse_DefaultsToTextPlainContentType()
{
var apiResponse = new APIGatewayProxyResponse
{
StatusCode = 200,
Body = "Hello, World!"
};

var httpResponse = apiResponse.ToHttpResponse();

Assert.Equal("text/plain; charset=utf-8", httpResponse.ContentType);
}

[Fact]
public void ToHttpResponse_APIGatewayProxyResponse_UsesProvidedContentType()
{
var apiResponse = new APIGatewayProxyResponse
{
StatusCode = 200,
Body = "Hello, World!",
Headers = new Dictionary<string, string>
{
{ "Content-Type", "application/json" }
}
};

var httpResponse = apiResponse.ToHttpResponse();

Assert.Equal("application/json", httpResponse.ContentType);
}

[Fact]
public void ToHttpResponse_APIGatewayHttpApiV2ProxyResponse_DefaultsToTextPlainContentType()
{
var apiResponse = new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = 200,
Body = "Hello, World!"
};

var httpResponse = apiResponse.ToHttpResponse();

Assert.Equal("text/plain; charset=utf-8", httpResponse.ContentType);
}

[Fact]
public void ToHttpResponse_APIGatewayHttpApiV2ProxyResponse_UsesProvidedContentType()
{
var apiResponse = new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = 200,
Body = "Hello, World!",
Headers = new Dictionary<string, string>
{
{ "Content-Type", "application/xml" }
}
};

var httpResponse = apiResponse.ToHttpResponse();

Assert.Equal("application/xml", httpResponse.ContentType);
}

[Fact]
public void ToHttpResponse_APIGatewayHttpApiV2ProxyResponse_DefaultsToApplicationJsonForValidJson()
{
var apiResponse = new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = 0,
Body = "{\"message\":\"Hello, World!\"}"
};

var httpResponse = apiResponse.ToHttpResponse();

Assert.Equal("application/json", httpResponse.ContentType);
Assert.Equal(200, httpResponse.StatusCode);
}
}

0 comments on commit 56af10b

Please sign in to comment.