From 5c666382f8579227d6687bf4e54fa1c05dddf00c Mon Sep 17 00:00:00 2001 From: chloe Date: Thu, 19 Mar 2026 03:39:56 +0000 Subject: [PATCH] update search/test --- .../Controllers/RecipeController.cs | 2 ++ Seasoned.Frontend/app/pages/gallery.vue | 11 ++++--- Seasoned.Frontend/test/GalleryPage.spec.ts | 32 ++++++++----------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Seasoned.Backend/Controllers/RecipeController.cs b/Seasoned.Backend/Controllers/RecipeController.cs index c38319a..d2917cc 100644 --- a/Seasoned.Backend/Controllers/RecipeController.cs +++ b/Seasoned.Backend/Controllers/RecipeController.cs @@ -122,6 +122,8 @@ public class RecipeController : ControllerBase [HttpGet("search")] public async Task>> SearchRecipes([FromQuery] string query) { + Console.WriteLine($"--> Search hit! Query: {query}"); + var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (string.IsNullOrWhiteSpace(query)) diff --git a/Seasoned.Frontend/app/pages/gallery.vue b/Seasoned.Frontend/app/pages/gallery.vue index 6c65b23..96250e0 100644 --- a/Seasoned.Frontend/app/pages/gallery.vue +++ b/Seasoned.Frontend/app/pages/gallery.vue @@ -43,7 +43,7 @@ - + @@ -134,7 +134,7 @@ > @@ -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 } diff --git a/Seasoned.Frontend/test/GalleryPage.spec.ts b/Seasoned.Frontend/test/GalleryPage.spec.ts index 967ea56..b7186ad 100644 --- a/Seasoned.Frontend/test/GalleryPage.spec.ts +++ b/Seasoned.Frontend/test/GalleryPage.spec.ts @@ -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) @@ -79,14 +79,15 @@ describe('GalleryPage.vue', () => { await flushPromises() expect(mockFetch).toHaveBeenCalledWith( - expect.stringContaining('api/recipe/search'), - expect.objectContaining({ - params: expect.objectContaining({ query: 'spicy pasta' }) - }) + expect.stringContaining('api/recipe/search'), + expect.objectContaining({ + query: { query: 'spicy pasta' }, + credentials: 'include' + }) ) vi.useRealTimers() - }) + }) it('redirects to login if API returns 401', async () => { mockFetch.mockReset() @@ -99,7 +100,7 @@ describe('GalleryPage.vue', () => { await vi.waitFor(() => { expect(mockNavigate).toHaveBeenCalledWith('/login') }, { timeout: 1000 }) - }) + }) it('enters editing mode and formats arrays into strings', async () => { mockFetch.mockResolvedValueOnce([ @@ -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') - }) - }) }) \ No newline at end of file