Skip to content

Commit

Permalink
Merge pull request #1797 from qdraw/feature/202411_suggest_error_400
Browse files Browse the repository at this point in the history
add test for suggest 400 && fix issue
  • Loading branch information
qdraw authored Nov 1, 2024
2 parents 357f4db + 9d8f625 commit 2f09f55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion starsky/starsky/Controllers/SearchSuggestController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -29,9 +30,10 @@ public SearchSuggestController(ISearchSuggest suggest)
// ^ ^ ^ ^ = = = = = = = = = = = = = = = = = =
public async Task<IActionResult> Suggest(string t)
{
if ( string.IsNullOrEmpty(t) )
if ( string.IsNullOrWhiteSpace(t) )
{
CacheControlOverwrite.SetExpiresResponseHeaders(Request); // 4 weeks
return Json(new List<string>());
}

if ( !ModelState.IsValid )
Expand Down
11 changes: 9 additions & 2 deletions starsky/starskytest/Controllers/SearchSuggestControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ public async Task Suggestion_IsMoreThan10()
}

[TestMethod]
public async Task Suggestion_Nothing()
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public async Task Suggestion_Nothing(string t)
{
var controller = new SearchSuggestController(_searchSuggest)
{
ControllerContext = { HttpContext = new DefaultHttpContext() }
};
var result = await controller.Suggest(string.Empty) as JsonResult;

// this will hit ModelState.IsValid
controller.ModelState.AddModelError("Key", "ErrorMessage");

var result = await controller.Suggest(t) as JsonResult;
var list = result!.Value as List<string>;

Assert.IsFalse(list!.Count != 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using starsky.foundation.platform.Models;
using starskytest.FakeCreateAn.CreateFakeStarskyExe;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace starskytest.starsky.foundation.native.OpenApplicationNative.Helpers;

Expand Down Expand Up @@ -53,7 +54,7 @@ private static void CleanSetup()
}

[TestMethod]
public void WindowsSetFileAssociations_EnsureAssociationsSet()
public async Task WindowsSetFileAssociations_EnsureAssociationsSet()
{
if ( !new AppSettings().IsWindows )
{
Expand All @@ -72,7 +73,13 @@ public void WindowsSetFileAssociations_EnsureAssociationsSet()
});

var valueKey = GetRegistryValue();
valueKey ??= GetRegistryValue();

if ( valueKey == null )
{
Console.WriteLine("Registry key not found, waiting for registry to update");
await Task.Delay(1000); // Wait for the registry to update
valueKey = GetRegistryValue();
}

Assert.IsNotNull(valueKey);
var match = GetFilePathFromRegistryRegex().Match(valueKey);
Expand Down

0 comments on commit 2f09f55

Please sign in to comment.