update search/test

This commit is contained in:
2026-03-19 03:39:56 +00:00
parent 42faf7eeb6
commit 5c666382f8
3 changed files with 21 additions and 24 deletions

View File

@@ -122,6 +122,8 @@ public class RecipeController : ControllerBase
[HttpGet("search")]
public async Task<ActionResult<IEnumerable<Recipe>>> SearchRecipes([FromQuery] string query)
{
Console.WriteLine($"--> Search hit! Query: {query}");
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (string.IsNullOrWhiteSpace(query))

View File

@@ -43,7 +43,7 @@
</v-row>
<v-row v-else-if="recipes?.length">
<v-col v-for="recipe in sortedRecipes" :key="recipe.id" cols="12" sm="6" md="4">
<v-col v-for="recipe in (searchQuery ? recipes : sortedRecipes)" :key="recipe.id" cols="12" sm="6" md="4">
<v-card class="gallery-item-card pa-4">
<v-sheet
height="200"
@@ -53,7 +53,7 @@
>
<v-img
v-if="recipe.imageUrl"
:src="recipe.imageUrl"
:src="recipe.imageUrl.startsWith('http') ? recipe.imageUrl : `${config.public.apiBase}${recipe.imageUrl}`"
cover
class="recipe-thumbnail"
></v-img>
@@ -134,7 +134,7 @@
>
<v-img
v-if="selectedRecipe.imageUrl"
:src="selectedRecipe.imageUrl"
:src="selectedRecipe.imageUrl.startsWith('http') ? selectedRecipe.imageUrl : `${config.public.apiBase}${selectedRecipe.imageUrl}`"
cover
class="rounded-lg fill-height"
></v-img>
@@ -435,12 +435,13 @@ const performSearch = async () => {
try {
isSearching.value = true
const data = await $fetch(`${config.public.apiBase}api/recipe/search`, {
params: { query: searchQuery.value },
query: { query: searchQuery.value },
credentials: 'include'
})
console.log("Search results received:", data)
recipes.value = data
} catch (err) {
console.error("The Chef couldn't find those flavors:", err)
console.error("Search failed:", err)
} finally {
isSearching.value = false
}

View File

@@ -47,7 +47,6 @@ describe('GalleryPage.vue', () => {
}
it('shows loading state initially and then renders recipes', async () => {
mockFetch.mockResolvedValueOnce([
{ id: 1, title: 'Bolognese', createdAt: new Date().toISOString(), ingredients: [], instructions: [] }
])
@@ -63,7 +62,8 @@ describe('GalleryPage.vue', () => {
it('triggers semantic search when searchQuery changes', async () => {
vi.useFakeTimers()
mockFetch.mockResolvedValue([])
mockFetch.mockResolvedValueOnce([])
const wrapper = mount(GalleryPage, mountOptions)
@@ -81,7 +81,8 @@ describe('GalleryPage.vue', () => {
expect(mockFetch).toHaveBeenCalledWith(
expect.stringContaining('api/recipe/search'),
expect.objectContaining({
params: expect.objectContaining({ query: 'spicy pasta' })
query: { query: 'spicy pasta' },
credentials: 'include'
})
)
@@ -139,18 +140,11 @@ describe('GalleryPage.vue', () => {
expect(mockFetch).toHaveBeenCalledWith(
expect.stringContaining('api/recipe/update/1'),
expect.objectContaining({ method: 'PUT' })
expect.objectContaining({
method: 'PUT',
credentials: 'include'
})
)
expect(vm.recipes[0].title).toBe('New Title')
})
it('redirects to login if API returns 401', async () => {
mockFetch.mockRejectedValueOnce({ status: 401 })
mount(GalleryPage, mountOptions)
await vi.waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith('/login')
})
})
})