Skip to content

Commit

Permalink
fix: check for all number cases in writer in optionValueConverter (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren authored Jan 2, 2025
1 parent 1aa8bb1 commit 0c3d521
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOp
case string s:
writer.WriteStringValue(s);
break;
case double d:
writer.WriteNumberValue(d);
case double:
case int:
case long:
case decimal:
writer.WriteNumberValue(Convert.ToDouble(value));
break;
case bool b:
writer.WriteBooleanValue(b);
break;
default:
throw new InvalidOptionsFormatException($"{value} is an unsupported type for Value field. Accepted types are string, double and bool.");
throw new InvalidOptionsFormatException($"{value} is an unsupported type for Value field. Accepted types are string, numbers and bool.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task Put_Returns_200OK_When_Creating_New_OptionsList()
}

[Fact]
public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Double()
public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Numbers()
{
string repo = "app-with-options";
string optionsListId = "test-options";
Expand All @@ -74,12 +74,13 @@ public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Double()
string apiUrl = $"/designer/api/{Org}/{targetRepository}/options/{optionsListId}";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Put, apiUrl);

var stringBoolDoubleOptionsList = @"[
var stringBoolNumbersOptionsList = @"[
{ ""label"": ""StringValue"", ""value"": ""value"" },
{ ""label"": ""BoolValue"", ""value"": true },
{ ""label"": ""NumberValue"", ""value"": 3.1415 },
{ ""label"": ""NumberValue"", ""value"": 1024 },
]";
httpRequestMessage.Content = new StringContent(stringBoolDoubleOptionsList, Encoding.UTF8, "application/json");
httpRequestMessage.Content = new StringContent(stringBoolNumbersOptionsList, Encoding.UTF8, "application/json");

// Act
using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
Expand Down

0 comments on commit 0c3d521

Please sign in to comment.