Ticket "Text and Subfield Search": Test passed, UI-Status fails

I implemented the search functionality as specified, at least I hope so :wink:

After running the test (see below) everything seems to be fine but the output in the Status-UI states the following:

Text and Subfield Search: Did not receive the proper response when searching by genre

I would have expected test and UI should report the same, do you have a hint for me?

It is not due to a caching issue because I let another test fail which was immediately reflected by the test AND the UI.

--------------------- 8< ------------------

npm test text-subfield

server@1.0.0 test /Users/Oliver/Dev/mongodb-university/m220/mflix-js
jest --passWithNoTests “text-subfield”

Determining test suites to run…Setup Mongo Connection
PASS test/text-subfield.test.js
Text and Subfield Search
✓ Can perform a text search (124ms)
✓ Can perform a genre search with one genre (100ms)
✓ Can perform a genre search with multiple genres (72ms)
✓ Can perform a cast search with one cast member (218ms)
✓ Can perform a cast search with multiple cast members (122ms)
✓ Can perform a search and return a non-default number of movies per page (127ms)

Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 1.82s, estimated 2s
Ran all test suites matching /text-subfield/i.
Teardown Mongo Connection

Hmm Strange :thinking:. Try restarting the server and check again in the incognito tab. Also try manually searching by genre and see if its working fine.

2 Likes

Thanks for the hint, when I manually searched an error was shown at the command line.

In the end the problem was a combination of a programming-error from my side and a gap in the test-case.

Gap-Description: The test-case passes an array when testing only ONE genre opposed to the UI which passes a string.

1 Like

I am glad you’ve figured it out. BTW they’ve provided code to change a string to an array in the genreSearchQuery() function.

Got the same issue, checked the error and fix it. Thanks for the hints

Amm whats the real issue? I started in incognito and still facing the same issue

Hi @iamodane,

Please let us know if you are still facing the issue.

Kanika

No I fixed the issue

Just a note in case someone else misses it: there is a searchGenre variable to be used to avoid the issue Dharma mentioned. Without it, your tests will pass but the status UI will fail.

Jeremy

I have same issue, test is ok, but GUI gives error. I couldn’t find a solution from the discussion area and I don’t want ruin code with my modifications. Can somebody give a tip how to solve this?

Test is OK


UI Test is NOT OK
Error01
Server side
Error02

Error04
I use Array to fetch data in filter.

Hello,

So I assume you fixed it, but if anyone else runs into this problem.

If when on the Status page and click the Text and Subfield search, and you get an error after passing the test script and you see this in your terminal output from npm start.

Unable to convert cursor to array or problem counting documents, MongoError: $in needs an array

It means you have used for the query, the genre parameter that was passed into the function genreSearchQuery, instead you need to use searchGenre, which is the array the query needs to be using :+1:

NOTE - Some extra logging I added within genreSearchQuery, to confirm what I thought I had done.

> GET /api/v1/movies/search?text=shawshank 304 3.703 ms - -
> 1. genre is:string isArray:false
> 2. searchGenre:object isArray:true
> GET /api/v1/movies/search?genre=Talk-Show 304 75.220 ms - -

When run using npm test -t text-subfield you would have seen this:-

  console.log src/dao/moviesDAO.js:131
    1. genre is:object isArray:true

  console.log src/dao/moviesDAO.js:132
    2. searchGenre:object isArray:true

  console.log src/dao/moviesDAO.js:131
    1. genre is:object isArray:true

  console.log src/dao/moviesDAO.js:132
    2. searchGenre:object isArray:true

Anyway, all good.