Ticket Projection error

Running the Unit Tests

Hi @Joseph_75231,

PLEASE SHARE THE ERROR

Kanika

Hi Kanika,

Would you like to tell me what’s wrong in this ticket - projection :

Modification in moviesDAO.js :

let cursor

try {‚Äč

// here‚Äôs the find query with query predicate and field projection‚Äč

cursor = await movies.find({ countries: { $in: countries } }).project({ title: 1 })‚Äč

} catch (e) {‚Äč

console.error(Unable to issue find command, ${e})‚Äč

return []‚Äč

}

Command in Mongo Shell:

C:\Users\a7\mflix-js> npm test -t moviesDAO.js

> server@1.0.0 test C:\Users\a7\mflix-js

> jest --passWithNoTests "moviesDAO.js"‚Äč

‚Äč**No tests found‚Äč

In C:\Users\a7\mflix-js‚Äč

51 files checked.‚Äč

testMatch: /tests//.js?(x),**/?(.)+(spec|test).js?(x) - 23 matches‚Äč

testPathIgnorePatterns: \node_modules\ - 51 matches‚Äč

Pattern: moviesDAO.js - 0 matches‚Äč

Setup Mongo Connection‚Äč

Teardown Mongo Connection

‚ÄčIn http://localhost:5000/status/

Projection: The return from the api was incorrect when searching by country

Thank you for your help.

1 Like

For testing the Projection ticket, you need to run the below command:

npm test -t projection

So, if it shows Passed means the unit tests are passing and you can run npm start then.
If it shows Failed, then you will be able to identify whats wrong from the output, if not, please let me know.

Kanika

Hi Kanika,

It works well now. Thank you very much.

1 Like

Hi Kanika,

I edited m√©thodes : getUser, addUser, loginUser, logoutUser, ‚ÄčgetUserSession

And it runs perfectly.

Now I have a problem with Ticket - User Preferences :

The tests passed, but Mflix output wrongly, please help

PS C:\Users\a7\mflix-js> npm test -t user-management

‚Äč

server@1.0.0 test C:\Users\a7\mflix-js‚Äč

jest --passWithNoTests "user-management"‚Äč

‚Äč

Determining test suites to run‚ĶSetup Mongo Connection‚Äč

PASS test/user-management.test.js (5.841s)‚Äč

User Management‚Äč

‚ąö it can add a new user to the database (580ms)‚Äč

‚ąö it returns an error when trying to register duplicate user (272ms)‚Äč

‚ąö it allows a user to login (559ms)‚Äč

‚ąö it allows a user to logout (552ms)‚Äč

‚Äč

Test Suites: 1 passed, 1 total‚Äč

Tests: 4 passed, 4 total‚Äč

Snapshots: 0 total‚Äč

Time: 6.13s‚Äč

Ran all test suites matching /user-management/i.‚Äč

Teardown Mongo Connection‚Äč

PS C:\Users\a7\mflix-js> npm start‚Äč

‚Äč

server@1.0.0 start C:\Users\a7\mflix-js‚Äč

nodemon -L ./index.js‚Äč

‚Äč

[nodemon] 1.17.5‚Äč

[nodemon] to restart at any time, enter rs‚Äč

[nodemon] watching: *.*‚Äč

[nodemon] starting node ./index.js‚Äč

listening on port 5000‚Äč

GET /status/ 304 10.298 ms - -‚Äč

GET /static/css/main.d2c98b4b.chunk.css 304 2.160 ms - -‚Äč

GET /static/js/1.85042e97.chunk.js 304 1.743 ms - -‚Äč

GET /static/js/main.1ddf7b65.chunk.js 304 3.381 ms - -‚Äč

GET /static/media/mongoleaf.0ebc1843.png 304 1.097 ms - -‚Äč

GET /static/media/pixelatedLeaf.6c93bd20.svg 304 0.418 ms - -‚Äč

GET /api/v1/movies/ 304 2115.673 ms - -‚Äč

GET /api/v1/movies/countries?countries=Australia 304 939.529 ms - -‚Äč

GET /api/v1/movies/search?cast=Griffin%20Gluck 304 650.462 ms - -‚Äč

GET /api/v1/movies/search?text=shawshank 304 537.148 ms - -‚Äč

GET /api/v1/movies/search?genre=Reality-TV 304 540.451 ms - -‚Äč

GET /api/v1/movies/search?cast=Morgan%20Freeman&page=0 304 870.646 ms - -‚Äč

GET /api/v1/movies/search?cast=Morgan%20Freeman&page=1 304 570.414 ms - -‚Äč

GET /api/v1/movies/search?genre=Action&page=0 304 1104.271 ms - -‚Äč

GET /api/v1/movies/search?genre=Action&page=5 304 572.686 ms - -‚Äč

GET /api/v1/movies/search?text=Heist&page=0 304 803.958 ms - -‚Äč

GET /api/v1/movies/search?text=Heist&page=7 304 542.879 ms - -‚Äč

GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 304 925.366 ms - -‚Äč

GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 304 984.653 ms - -‚Äč

POST /api/v1/user/register 200 677.159 ms - 308‚Äč

POST /api/v1/user/register 400 646.608 ms - 55‚Äč

POST /api/v1/user/logout 200 276.477 ms - 16‚Äč

POST /api/v1/user/login 200 651.552 ms - 308‚Äč

DELETE /api/v1/user/delete 200 1438.002 ms - 16‚Äč

POST /api/v1/user/register 200 644.340 ms - 308‚Äč

An error occurred while updating this user‚Äôs preferences, MongoError: E11000 duplicate key error collection: 5d0f40f379358e754e38fa34_mflix.users index: email_1 dup key: { : ‚Äú7surknq9j@h98if.z36‚ÄĚ }‚Äč

PUT /api/v1/user/update-preferences 200 561.555 ms - 308‚Äč

POST /api/v1/user/login 200 706.499 ms - 308‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

‚Äč

Hi @Joseph_75231,

For Ticket: User Preferences, you need to run below command to test the unit-tests:

 npm test -t user-preferences

Let me know if you have questions.

Kanika

Thank you for your advise, it works now.
For Final : Question 3, I need more documentation. Can you give some link, please.

Hi @Joseph_75231,

Here is the API link for NodeJS driver :

https://mongodb.github.io/node-mongodb-native/3.2/api/MongoClient.html

Kanika

Hi Kanika,

Please give me the link of documentation : How to use API for NodeJS driver in Mongo Shell, because cours M220JS tell us do not touch API folder.

Hi @Joseph_75231,

In the course, we don’t want anyone to touch this directory: m220js/mflix-js/src/api which contains all the api.

The documentation link is:

https://mongodb.github.io/node-mongodb-native/3.2/api/MongoClient.html

Kanika