node.js - Disappearing value in Mongoose model custom function when testing with Jasmine-Node -
I am trying to test my custom method on my monogage model, but the values I set in the test model I disappeared and the test failed. The test should look like this:
get it ('friend id', function) (var conversations = new conversation ({'user': [new object id ('0'), New Object ID ('1')]}); Hopefully (Conversation.GetFreendandID ('0')) Excel (New Object ID ('1');}); My model's announcement includes:
var mongoose = is required ('magos'); Var ObjectID = Mongoose Sema Type.object id; Var Conversation Schema = New Mongoose Sema ({'user': [{'type': object id, 'referee': 'user'}]}); Conversation style.education.filmid = function (user id) // return it [0] === New object ID (user-facing) //? this. Jores [1]: This Joes [0]; }; Module Exports = Mongoise.model ('Conversation', Conversation Schema); When I run the test, I get:
expected [] similar {path: '1', example: 'Object ID' , Validated: [], Sets: [], Gates: [], Options: Undefined, _ Indics: Null}. I set the users in the test, so the return value should be the array of users. (Which will still fail the test in the current situation, but in theory the second return statement should be passed on repeatedly.) Instead the user array is clearly visible.
How do I test the test model in my custom function?
I changed many things to get it to work at the end.
I changed the users to the array because it was a more accurate representation of the data. There are strings for the object to set.
To create a new Object ID, you must have 12 byte string or 24 character hex string. Basically, I tried to do it with a single digit string. I've added a SPC Helper that stores dummy IDs with 24 character hex strings.
mongoose.Schema.Type.ObjectId and mongoose.Types.ObjectId are two different things before I realize that I have to use both Needed, every one tried it. When creating schemas, I need mongoose.Schema.Types.ObjectId . I was trying to return the model to those files, where I define them. Instead, I need to call mongoose.model () to get my model. With these changes, my model definition looks like this now:
requires Var Mongoose = ('Mongoose'); Var ObjectID = Mongoose Sema Type.object id; Var 'Conversation' schema = New Mongoose Sema ({'User': Object, 'Message': [{'Text': String, 'Sender': {'Type': Object ID, 'Ref': 'User'}}}}}); Conversation.education.ools.gofreeindid = function (user id) {for (URI in this U). If (U! == User ID) returns to the new Mongoose. Type. Object ID (U); } Return tap; }; // Other custom methods ... Mongos Model ('Conversation', Conversation Schema); My test looks like this:
Description ('getFriendId ()', function () {var mongoose = require ('mongoose'); Var ObjectId = mongoose.Types.ObjectId; ('../../../Model / Conversation'); var Conversation = Mongoos.Model ('Conversation'); var Assistant = Required ('../fiction ('Friend's id', function () {user = {}; user [helper.ids.user0] = true; user [helper.ids.user1] = true; var chat = new conversation () {'User': User}); Hopefully (Chat.GraphIRIID (Helper.ids.user0)). (New object ID (helper.ids.user1));});});
Comments
Post a Comment