, text: string): string | undefined {
+ const trimmed = text.trim()
+ return trimmed ? `${field} @=* ${quoteText(trimmed)}` : undefined
+}
diff --git a/frontend/src/routes/(examples)/workshops/index.tsx b/frontend/src/routes/(examples)/workshops/index.tsx
index 874d89292..ddcac7814 100644
--- a/frontend/src/routes/(examples)/workshops/index.tsx
+++ b/frontend/src/routes/(examples)/workshops/index.tsx
@@ -1,10 +1,8 @@
import { createFileRoute } from '@tanstack/react-router'
import * as z from 'zod'
-import {
- getWorkshopListQueryPageNumberSchema,
- getWorkshopListQuerySearchSchema,
-} from '@/api/generated/workshops/zod/get-workshop-list'
+import { workshopForCreationDtoSchema } from '@/api/generated/models/zod/workshop-for-creation-dto'
+import { getWorkshopListQueryPageNumberSchema } from '@/api/generated/workshops/zod/get-workshop-list'
import { QueryError } from '@/components/query-error'
import { SearchBox } from '@/components/search-box'
import { buttonVariants } from '@/components/ui/button-variants'
@@ -19,13 +17,13 @@ import { useIsMobile } from '@/hooks/use-mobile'
import { maxLengthOf } from '@/lib/api-contract'
import { PageHeading } from '@/components/page-heading'
+const searchMaxLength = maxLengthOf(workshopForCreationDtoSchema.shape.title)
+
const listSearchSchema = z.object({
- search: getWorkshopListQuerySearchSchema.catch(undefined),
+ search: z.string().max(searchMaxLength).optional().catch(undefined),
page: getWorkshopListQueryPageNumberSchema.catch(undefined),
})
-const searchMaxLength = maxLengthOf(getWorkshopListQuerySearchSchema.unwrap())
-
export const Route = createFileRoute('/(examples)/workshops/')({
validateSearch: listSearchSchema,
component: WorkshopsPage,
@@ -122,7 +120,7 @@ function WorkshopRows({ list, search, page, onPageChange }: WorkshopRowsProps) {
if (workshops.length === 0) {
return (
- {search ? `No workshop has "${search.trim()}" in its title.` : 'No workshops yet. Add one with New workshop.'}
+ {search.trim() ? `No workshop has "${search.trim()}" in its title.` : 'No workshops yet. Add one with New workshop.'}
)
}
diff --git a/frontend/tests/features/examples/workshops/workshops.spec.ts b/frontend/tests/features/examples/workshops/workshops.spec.ts
index 2fc4d6530..33d3a4c97 100644
--- a/frontend/tests/features/examples/workshops/workshops.spec.ts
+++ b/frontend/tests/features/examples/workshops/workshops.spec.ts
@@ -201,7 +201,7 @@ test.describe('the workshops', () => {
await workshops.searchFor('Kubb')
await expect(page).toHaveURL('/workshops?search=Kubb')
- expect(api.last('get', workshopPaths.list)?.query.get('search')).toBe('Kubb')
+ expect(api.last('get', workshopPaths.list)?.query.get('filters')).toBe('title @=* "Kubb"')
expect(api.last('get', workshopPaths.list)?.query.get('pageNumber')).toBe('1')
await expect(workshops.at.row('Kubb basics')).toBeVisible()
})
diff --git a/tests/FullstackTemplate.FunctionalTests/FunctionalTests/TextValues/NulInReadInputTests.cs b/tests/FullstackTemplate.FunctionalTests/FunctionalTests/TextValues/NulInReadInputTests.cs
index f19890aad..dc0262255 100644
--- a/tests/FullstackTemplate.FunctionalTests/FunctionalTests/TextValues/NulInReadInputTests.cs
+++ b/tests/FullstackTemplate.FunctionalTests/FunctionalTests/TextValues/NulInReadInputTests.cs
@@ -33,10 +33,8 @@ public class NulInReadInputTests : TestBase
// example:start
(ApiRoutes.Workshops.GetList, "filters"),
(ApiRoutes.Workshops.GetList, "sortOrder"),
- (ApiRoutes.Workshops.GetList, "search"),
(ApiRoutes.Venues.GetList, "filters"),
(ApiRoutes.Venues.GetList, "sortOrder"),
- (ApiRoutes.Venues.GetList, "search"),
// example:end
];
diff --git a/tests/FullstackTemplate.IntegrationTests/Examples/Lists/ExampleListFilterSweepTests.cs b/tests/FullstackTemplate.IntegrationTests/Examples/Lists/ExampleListFilterSweepTests.cs
index fd36e7e2d..dc8b831ab 100644
--- a/tests/FullstackTemplate.IntegrationTests/Examples/Lists/ExampleListFilterSweepTests.cs
+++ b/tests/FullstackTemplate.IntegrationTests/Examples/Lists/ExampleListFilterSweepTests.cs
@@ -19,7 +19,7 @@ public async Task each_operator_on_each_field_of_the_workshops_runs_or_gives_a_q
// Act
var faults = await ListFilterSweep.FaultsAsync(typeof(WorkshopDto), (filters, sort) =>
- testingServiceScope.SendAsync(new GetWorkshopList.Query(WorkshopParametersDto.From(null, null, filters, sort, null))));
+ testingServiceScope.SendAsync(new GetWorkshopList.Query(WorkshopParametersDto.From(null, null, filters, sort))));
// Assert
faults.ShouldBeEmpty();
@@ -33,7 +33,7 @@ public async Task each_operator_on_each_field_of_the_venues_runs_or_gives_a_quer
// Act
var faults = await ListFilterSweep.FaultsAsync(typeof(VenueDto), (filters, sort) =>
- testingServiceScope.SendAsync(new GetVenueList.Query(VenueParametersDto.From(null, null, filters, sort, null))));
+ testingServiceScope.SendAsync(new GetVenueList.Query(VenueParametersDto.From(null, null, filters, sort))));
// Assert
faults.ShouldBeEmpty();
@@ -56,7 +56,7 @@ public async Task a_part_of_a_field_gives_a_query_input_error(string? filters, s
// Act
var act = () => testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(null, null, filters, sortOrder, null)));
+ WorkshopParametersDto.From(null, null, filters, sortOrder)));
// Assert
(await act.ShouldThrowAsync()).Parameter.ShouldBe(filters is null ? "sortOrder" : "filters");
diff --git a/tests/FullstackTemplate.IntegrationTests/Examples/Venues/VenueListQueryTests.cs b/tests/FullstackTemplate.IntegrationTests/Examples/Venues/VenueListQueryTests.cs
index a55249c84..bc6c751ce 100644
--- a/tests/FullstackTemplate.IntegrationTests/Examples/Venues/VenueListQueryTests.cs
+++ b/tests/FullstackTemplate.IntegrationTests/Examples/Venues/VenueListQueryTests.cs
@@ -2,15 +2,15 @@ namespace FullstackTemplate.IntegrationTests.Examples.Venues;
using FullstackTemplate.Server.Examples.Venues.Dtos;
using FullstackTemplate.Server.Examples.Venues.Features;
-using FullstackTemplate.Server.Exceptions;
using FullstackTemplate.SharedTestHelpers.EntityGraphs;
using FullstackTemplate.SharedTestHelpers.Examples.EntityGraphs;
+using FullstackTemplate.SharedTestHelpers.Utilities;
using Shouldly;
public class VenueListQueryTests : TestBase
{
[Test]
- public async Task a_search_finds_the_names_that_contain_the_text_with_no_regard_to_case_and_a_percent_as_plain_text()
+ public async Task a_name_filter_finds_the_names_that_contain_the_text_with_no_regard_to_case_and_a_percent_as_plain_text()
{
// Arrange
var testingServiceScope = new TestingServiceScope();
@@ -24,28 +24,18 @@ await testingServiceScope.StartGraph(out _)
.BuildAsync();
// Act
- var found = await testingServiceScope.SendAsync(new GetVenueList.Query(
- VenueParametersDto.From(null, null, null, null, $" hall {marker.ToUpperInvariant()} ")));
- var percent = await testingServiceScope.SendAsync(new GetVenueList.Query(
- VenueParametersDto.From(null, null, null, null, $"{marker} 50%")));
+ var found = await NamesContainingAsync(testingServiceScope, $"hall {marker.ToUpperInvariant()}");
+ var percent = await NamesContainingAsync(testingServiceScope, $"{marker} 50%");
// Assert
- found.Select(v => v.Name).ShouldBe([$"North Hall {marker}", $"South Hall {marker}"]);
- percent.Select(v => v.Name).ShouldBe([$"{marker} 50% full"]);
+ found.ShouldBe([$"North Hall {marker}", $"South Hall {marker}"]);
+ percent.ShouldBe([$"{marker} 50% full"]);
}
- [Test]
- public async Task a_search_longer_than_its_maximum_gives_a_query_input_error()
+ private static async Task> NamesContainingAsync(TestingServiceScope scope, string text)
{
- // Arrange
- var testingServiceScope = new TestingServiceScope();
- var search = new string('a', VenueParametersDto.SearchMaxLength + 1);
-
- // Act
- var act = () => testingServiceScope.SendAsync(new GetVenueList.Query(
- VenueParametersDto.From(null, null, null, null, search)));
-
- // Assert
- (await act.ShouldThrowAsync()).Parameter.ShouldBe("search");
+ var page = await scope.SendAsync(new GetVenueList.Query(
+ VenueParametersDto.From(null, null, $"name @=* {QueryKitText.Quote(text)}", null)));
+ return page.Select(v => v.Name).ToList();
}
}
diff --git a/tests/FullstackTemplate.IntegrationTests/Examples/Workshops/WorkshopListQueryTests.cs b/tests/FullstackTemplate.IntegrationTests/Examples/Workshops/WorkshopListQueryTests.cs
index 70dab569c..7187faccf 100644
--- a/tests/FullstackTemplate.IntegrationTests/Examples/Workshops/WorkshopListQueryTests.cs
+++ b/tests/FullstackTemplate.IntegrationTests/Examples/Workshops/WorkshopListQueryTests.cs
@@ -5,6 +5,7 @@ namespace FullstackTemplate.IntegrationTests.Examples.Workshops;
using FullstackTemplate.Server.Exceptions;
using FullstackTemplate.SharedTestHelpers.EntityGraphs;
using FullstackTemplate.SharedTestHelpers.Examples.EntityGraphs;
+using FullstackTemplate.SharedTestHelpers.Utilities;
using Shouldly;
public class WorkshopListQueryTests : TestBase
@@ -17,16 +18,16 @@ public class WorkshopListQueryTests : TestBase
[Arguments("50%", "Yard 50% full")]
[Arguments("a_b", "a_b")]
[Arguments(@"c\d", @"c\d")]
- [Arguments(" A_B ", "a_b")]
- public async Task a_search_matches_a_percent_an_underscore_or_a_backslash_as_plain_text(string search, string match)
+ [Arguments("A_B", "a_b")]
+ public async Task a_title_filter_matches_a_percent_an_underscore_or_a_backslash_as_plain_text(string text, string match)
{
// Arrange
var testingServiceScope = new TestingServiceScope();
var venueId = await AddWorkshopsAsync(testingServiceScope);
// Act
- var found = await testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(null, null, $"venueId == \"{venueId}\"", null, search)));
+ var found = await testingServiceScope.SendAsync(new GetWorkshopList.Query(WorkshopParametersDto.From(
+ null, null, $"venueId == \"{venueId}\" && title @=* {QueryKitText.Quote(text)}", null)));
// Assert
found.Select(w => w.Title).ShouldBe([match]);
@@ -41,7 +42,7 @@ public async Task the_list_sorts_by_the_start_and_gives_each_row_its_actions()
// Act
var page = await testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(1, 4, $"venueId == \"{venueId}\"", null, null)));
+ WorkshopParametersDto.From(1, 4, $"venueId == \"{venueId}\"", null)));
// Assert
page.TotalCount.ShouldBe(Titles.Length);
@@ -52,32 +53,17 @@ public async Task the_list_sorts_by_the_start_and_gives_each_row_its_actions()
[Test]
[Arguments("a\0b")]
[Arguments("\uD800")]
- public async Task a_search_with_a_character_that_postgres_cannot_store_gives_a_query_input_error(string search)
- {
- // Arrange
- var testingServiceScope = new TestingServiceScope();
-
- // Act
- var act = () => testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(null, null, null, null, search)));
-
- // Assert
- (await act.ShouldThrowAsync()).Parameter.ShouldBe("search");
- }
-
- [Test]
- public async Task a_search_longer_than_its_maximum_gives_a_query_input_error()
+ public async Task a_title_filter_with_a_character_that_postgres_cannot_store_gives_a_query_input_error(string text)
{
// Arrange
var testingServiceScope = new TestingServiceScope();
- var search = new string('a', WorkshopParametersDto.SearchMaxLength + 1);
// Act
var act = () => testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(null, null, null, null, search)));
+ WorkshopParametersDto.From(null, null, $"title @=* {QueryKitText.Quote(text)}", null)));
// Assert
- (await act.ShouldThrowAsync()).Parameter.ShouldBe("search");
+ (await act.ShouldThrowAsync()).Parameter.ShouldBe("filters");
}
public static IEnumerable<(string, string[])> FiltersThatTheFilterBuilderWrites =>
@@ -110,7 +96,7 @@ public async Task a_filter_that_the_filter_builder_writes_finds_its_text(string
// Act
var found = await testingServiceScope.SendAsync(new GetWorkshopList.Query(
- WorkshopParametersDto.From(null, null, $"venueId == \"{venueId}\" && {filter}", null, null)));
+ WorkshopParametersDto.From(null, null, $"venueId == \"{venueId}\" && {filter}", null)));
// Assert
found.Select(w => w.Title).ShouldBe(matches, ignoreOrder: true);