Skip to content
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

Formatting of Extra Property #218

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

CopperBeardy
Copy link
Collaborator

@CopperBeardy CopperBeardy commented Feb 7, 2024

to address git hub issues
#200
#201

implementation to properly format the Extra Property of the LiveSchema and PrerecordedSchema for the QueryString of request. The implementation in the QueryParameterUtil class, in the URL Encode methods switch statement. the format does NOT change the casing of the keys or value's as the casing may have significance to the user

Summary by CodeRabbit

  • New Features
    • Enhanced the app's ability to handle complex queries by introducing support for dictionary parameters in the query string formatting process.
  • Tests
    • Added unit tests to ensure reliable query string formatting when using dictionary parameters.

to address git hub issues
#200
#201

implementation  to properly format the Extra Property of the LiveSchema and PrerecordedSchema for the QueryString of request.
The implementation in the QueryParameterUtil class, in the URl Encode methods switch statement. the format does Not change the casing of the key's or value's as the casing may have significance to the user
Copy link
Contributor

coderabbitai bot commented Feb 7, 2024

Walkthrough

The recent update introduces a significant enhancement to the handling of dictionary parameters in query strings. Specifically, it focuses on improving the QueryParameterUtil.GetParameters() function to adeptly format query strings when provided with dictionary parameters under the "extra" parameter. This enhancement is validated through the addition of a new unit test, ensuring the functionality behaves as expected when dealing with complex dictionary inputs.

Changes

File Change Summary
.../UtilitiesTests/QueryParameterUtilTests.cs Added a test GetParameters_Should_Return_String_When_Passing_Dictonary_Parameter() to validate handling of dictionary parameters.
Deepgram/Utilities/QueryParameterUtil.cs Enhanced to correctly format query strings with dictionary parameters under the "extra" parameter.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3fb47cb and 8b4f672.
Files selected for processing (2)
  • Deepgram.Tests/UnitTests/UtilitiesTests/QueryParameterUtilTests.cs (1 hunks)
  • Deepgram/Utilities/QueryParameterUtil.cs (2 hunks)

Comment on lines +42 to +53
//specific case for the Extra Parameter dictionary to format the querystring correctly
//no case changing of the key or values as theses are unknowns and the casing may have
//significance to the user
case Dictionary<string, string> dict:
if (name == "extra")
{
foreach (var kvp in dict)
{
sb.Append($"{name}={HttpUtility.UrlEncode($"{kvp.Key}:{kvp.Value}")}&");
}
}
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for handling Dictionary<string, string> in the UrlEncode method correctly preserves the case of keys and values, aligning with the PR objectives. However, consider using Uri.EscapeDataString instead of HttpUtility.UrlEncode for encoding keys and values. Uri.EscapeDataString provides a more RFC 3986 compliant way to encode URI components, which might be more appropriate for query string parameters.

- sb.Append($"{name}={HttpUtility.UrlEncode($"{kvp.Key}:{kvp.Value}")}&");
+ sb.Append($"{name}={Uri.EscapeDataString($"{kvp.Key}:{kvp.Value}")}&");

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
//specific case for the Extra Parameter dictionary to format the querystring correctly
//no case changing of the key or values as theses are unknowns and the casing may have
//significance to the user
case Dictionary<string, string> dict:
if (name == "extra")
{
foreach (var kvp in dict)
{
sb.Append($"{name}={HttpUtility.UrlEncode($"{kvp.Key}:{kvp.Value}")}&");
}
}
break;
//specific case for the Extra Parameter dictionary to format the querystring correctly
//no case changing of the key or values as theses are unknowns and the casing may have
//significance to the user
case Dictionary<string, string> dict:
if (name == "extra")
{
foreach (var kvp in dict)
{
sb.Append($"{name}={Uri.EscapeDataString($"{kvp.Key}:{kvp.Value}")}&");
}
}
break;

Comment on lines +84 to +103
public void GetParameters_Should_Return_String_When_Passing_Dictonary_Parameter()
{
//Arrange
var prerecordedOptions = new PrerecordedSchema()
{
Extra = new Dictionary<string, string>
{
{"KeyOne","ValueOne" },
{"KeyTwo","ValueTwo" }
}
};
var expected = $"extra={HttpUtility.UrlEncode("KeyOne:ValueOne")}&extra={HttpUtility.UrlEncode("KeyTwo:ValueTwo")}";

//Act
var result = QueryParameterUtil.GetParameters(prerecordedOptions);

//Assert
result.Should().NotBeNull();
result.Should().Contain(expected);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test GetParameters_Should_Return_String_When_Passing_Dictonary_Parameter correctly asserts the functionality for handling dictionary parameters. However, the expected string construction does not account for the order in which dictionary entries might be processed, which could lead to flaky tests if the dictionary iteration order is not consistent. Consider using a more flexible assertion that checks for the presence of each key-value pair in the result, regardless of order.

- var expected = $"extra={HttpUtility.UrlEncode("KeyOne:ValueOne")}&extra={HttpUtility.UrlEncode("KeyTwo:ValueTwo")}";
+ // Assert each key-value pair separately to avoid dependency on dictionary iteration order
+ Assert.IsTrue(result.Contains(HttpUtility.UrlEncode("KeyOne:ValueOne")));
+ Assert.IsTrue(result.Contains(HttpUtility.UrlEncode("KeyTwo:ValueTwo")));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public void GetParameters_Should_Return_String_When_Passing_Dictonary_Parameter()
{
//Arrange
var prerecordedOptions = new PrerecordedSchema()
{
Extra = new Dictionary<string, string>
{
{"KeyOne","ValueOne" },
{"KeyTwo","ValueTwo" }
}
};
var expected = $"extra={HttpUtility.UrlEncode("KeyOne:ValueOne")}&extra={HttpUtility.UrlEncode("KeyTwo:ValueTwo")}";
//Act
var result = QueryParameterUtil.GetParameters(prerecordedOptions);
//Assert
result.Should().NotBeNull();
result.Should().Contain(expected);
}
public void GetParameters_Should_Return_String_When_Passing_Dictonary_Parameter()
{
//Arrange
var prerecordedOptions = new PrerecordedSchema()
{
Extra = new Dictionary<string, string>
{
{"KeyOne","ValueOne" },
{"KeyTwo","ValueTwo" }
}
};
// Assert each key-value pair separately to avoid dependency on dictionary iteration order
Assert.IsTrue(result.Contains(HttpUtility.UrlEncode("KeyOne:ValueOne")));
Assert.IsTrue(result.Contains(HttpUtility.UrlEncode("KeyTwo:ValueTwo")));
//Act
var result = QueryParameterUtil.GetParameters(prerecordedOptions);
//Assert
result.Should().NotBeNull();
result.Should().Contain(expected);
}

@davidvonthenen davidvonthenen merged commit bc69b54 into main Feb 7, 2024
4 checks passed
@davidvonthenen davidvonthenen deleted the FormatExtraParameterInQueryString branch February 7, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants