Учу Ноду,
Вот ТЗ: Please download attachments for this homework
here
For this section's assessment, you will fill out the functions defined in interface.js. These functions will query a collection of movies - the data in the movies collection will look like what you see in the movies.json file.
In order to complete this section's assessment, you will have to make the tests in test.js pass. To run the tests, run npm install and then npm test. You will notice the tests fail. In keeping with this section's emphasis on automation, we recommend you use npm run watch to re-run your tests every time you change the interface.js file. Once the tests succeed, npm run watch will terminate and print a "secret code" consisting of a short phrase. Copy this code into the assessment page in your browser to complete this assessment.
Как уже понятно работа в связке Node+Mongo+npm
так вот, пишу этот файл:
/*
* Inserts "doc" into the collection "movies".
*/
exports.insert = function(db, doc, callback) {
db.collection('movies').insert(doc);
callback(null);
};
/*
* Finds all documents in the "movies" collection
* whose "director" field equals the given director,
* ordered by the movie's "title" field. See
* [url]http://mongodb.github.io/node-mongodb-native/2.0/api/Cursor.html#sort[/url]
*/
exports.byDirector = function(db, director, callback) {
db.collection('movies').find({ director }).toArray(function(error, docs) {
console.log(docs);
});
callback(null, []);
};
ошибку при запуске тестов выкидывает следущее
:~/Documents/home_work$ npm test
> @ test /home/ask/Documents/home_work
> gulp test
[13:23:21] Using gulpfile ~/Documents/home_work/gulpfile.js
[13:23:21] Starting 'test'...
[13:23:21] Finished 'test' after 11 ms
dbInterface
✓ can insert a movie
1) can query data by director
[ { _id: 5942601906cddd10228df69c,
title: 'The Empire Strikes Back',
year: 1980,
director: 'Irvin Kershner' } ]
2) returns multiple results ordered by title
[ { _id: 5942601906cddd10228df69b,
title: 'Star Wars',
year: 1977,
director: 'George Lucas' },
{ _id: 5942601906cddd10228df69e,
title: 'The Phantom Menace',
year: 1999,
director: 'George Lucas' },
{ _id: 5942601906cddd10228df69f,
title: 'Attack of the Clones',
year: 2002,
director: 'George Lucas' },
{ _id: 5942601906cddd10228df6a0,
title: 'Revenge of the Sith',
year: 2005,
director: 'George Lucas' } ]
1 passing (292ms)
2 failing
1) dbInterface can query data by director:
AssertionError: 0 == 1
+ expected - actual
+1
-0
at test.js:41:14
at Object.exports.byDirector (interface.js:19:3)
at Context.<anonymous> (test.js:38:17)
2) dbInterface returns multiple results ordered by title:
AssertionError: 0 == 4
+ expected - actual
+4
-0
at test.js:57:14
at Object.exports.byDirector (interface.js:19:3)
at Context.<anonymous> (test.js:54:17)
Tests failed!
Объясните пожалуйста, что я делаю не так, в поиске фильмов по JSON