Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Nov 1, 2024
1 parent e74e62c commit e69273c
Showing 1 changed file with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public async Task Put_Returns_200OK_When_Creating_New_OptionsList()

var newOptionsList = new List<Option>
{
new Option
new ()
{
Label = "label1",
Value = "value1",
},
new Option
new ()
{
Label = "label2",
Value = "value2",
Expand Down Expand Up @@ -66,6 +66,45 @@ public async Task Put_Returns_200OK_When_Creating_New_OptionsList()
Assert.Equal(newOptionsList[i].HelpText, responseList[i].HelpText);
}
}

[Fact]
public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Double()
{
string repo = "app-with-options";
string optionsListId = "test-options";
// Arrange
string targetRepository = TestDataHelper.GenerateTestRepoName();
await CopyRepositoryForTest(Org, repo, Developer, targetRepository);

string apiUrl = $"/designer/api/{Org}/{targetRepository}/options/{optionsListId}";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Put, apiUrl);

var stringBoolDoubleOptionsList = new List<Option>
{
new ()
{
Label = "StringValue",
Value = "value1",
},
new ()
{
Label = "BoolValue",
Value = true,
},
new ()
{
Label = "DoubleValue",
Value = 3.1415,
}
};
httpRequestMessage.Content = JsonContent.Create(stringBoolDoubleOptionsList);

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

// Assert
Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode);
}

[Fact]
public async Task Put_Returns_200OK_And_Overwrites_Existing_OptionsList()
Expand All @@ -79,12 +118,12 @@ public async Task Put_Returns_200OK_And_Overwrites_Existing_OptionsList()

var newOptionsList = new List<Option>
{
new Option
new ()
{
Label = "aNewLabelThatDidNotExistBefore",
Value = "aNewValueThatDidNotExistBefore",
},
new Option
new ()
{
Label = "label2",
Value = "value2",
Expand Down Expand Up @@ -129,12 +168,12 @@ public async Task Put_Returns_400BadRequest_When_OptionsList_Format_Is_Invalid(s
{
var invalidOptionsList = new List<Option>
{
new Option
new ()
{
// Missing Label
Value = "value1",
},
new Option
new ()
{
Label = "label2",
Value = "value2",
Expand All @@ -153,4 +192,33 @@ public async Task Put_Returns_400BadRequest_When_OptionsList_Format_Is_Invalid(s
// Assert
Assert.Equal(StatusCodes.Status400BadRequest, (int)response.StatusCode);
}

[Fact]
public async Task Put_Returns_400BadRequest_When_Option_Value_Is_Invalid()
{
string repo = "app-with-options";
string optionsListId = "test-options";
// Arrange
string targetRepository = TestDataHelper.GenerateTestRepoName();
await CopyRepositoryForTest(Org, repo, Developer, targetRepository);

string apiUrl = $"/designer/api/{Org}/{targetRepository}/options/{optionsListId}";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Put, apiUrl);

var invalidOptionsList = new List<Option>
{
new ()
{
Label = "StringValue",
Value = { },
},
};
httpRequestMessage.Content = JsonContent.Create(invalidOptionsList);

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

// Assert
Assert.Equal(StatusCodes.Status400BadRequest, (int)response.StatusCode);
}
}

0 comments on commit e69273c

Please sign in to comment.