I receive the following error from running my mocha test spec:
1) Song API "before all" hook:
TypeError: Undefined type `undefined` at `paths._id`
Did you try nesting Schemas? You can only nest using refs or arrays.
at Function.Schema.interpretAsType (node_modules/mongoose/lib/schema.js:599:11)
at Schema.path (node_modules/mongoose/lib/schema.js:507:29)
at Schema.add (node_modules/mongoose/lib/schema.js:391:12)
at Schema.add (node_modules/mongoose/lib/schema.js:386:14)
at new Schema (node_modules/mongoose/lib/schema.js:94:10)
at Object.<anonymous> (src/server/models/songModel.js:29:18)
at module.exports (src/server/models.js:12:26)
at Context.<anonymous> (src/server/router.spec.js:16:31)
2) Song API "after all" hook:
TypeError: Cannot read property 'close' of undefined
at Context.<anonymous> (src/server/router.spec.js:27:9)
My theory is that I cannot nest arrays within arrays as I've done in my schema. Is this correct? To me the docs say it's ok...for reference, my router.spec.js:
var assert = require('assert'),
express = require('express'),
superagent = require('superagent'),
wagner = require('wagner-core');
var URL_ROOT = 'http://localhost:3000';
describe('Song API', function() {
var server,
Song;
before(function() {
var app = express();
//bootstrap server
models = require('./models')(wagner);
app.use(require('./router')(wagner));
server = app.listen(3000);
//make Song model available for tests
Song = models.Song;
});
after(function() {
//shut the server down when we're done
server.close();
});
beforeEach(function(done) {
//Make sure songs are empty before wach test
Song.remove({}, function(error) {
assert.ifError(error);
done();
});
});
it('can load all songs', function(done) {
//Create a single song
Song.create({ _id: 'Test_Song'}, function(error, doc) {
assert.ifError(error);
var url = URL_ROOT + '/songs';
//make an http request to the url
superagent.get(url, function(error, res) {
assert.ifError(error);
var result;
//Make sure we received a song called "test song" back
assert.doesNotThrow(function() {
result = JSON.parse(res.text);
});
assert.ok(result.song);
assert.equal(result.song._id, 'Test_Song');
done();
});
});
});
and my schema:
var songSchema = new mongoose.Schema({
_id: {type: String},
createdBy: String,
modifiedBy: String,
instruments: [{
id: Number,
member: String,
type: String
}],
sections: [{
name: String,
bpm: Number,
timeSig: Number,
measures: [{
id: Number,
rows: [{
chord: String,
blocks: [{
id: Number,
isChecked: Boolean
}]
}]
}]
}]
});
module.exports = new mongoose.Schema(songSchema);
module.exports.songSchema = songSchema;
Aucun commentaire:
Enregistrer un commentaire