How do I verify/test that on a mongoose, document update call, my embedded documents are not being duplicated?
I'm using Mongoose, sinon, mocha and chai. I have a document that contains an embedded document, and both are created from external data that is pulled at regular intervals.
Format is similar to:
{
title: testingTitle,
flag: true,
color: orange,
list: [{
name: testName,
status: overdue
},
{
name: otherTestName,
status: due,
}]
}
I have two separate Schemas. Format similar to this:
let embeddedSchema = new mongoose.Schema({
name: {type: String, required: true},
staus: {type: String, required: true}
createdAt: {type: Date, default: moment}
});
let mainSchema = new mongoose.Schema({
title: {type: String, required: true},
flag: {type: String, defualt: null},
color: {type: Object, defualt: null},
list: [embeddedSchema]
})
It seems that this works. When I run my logic (which calls update if the main document already exists) it doesn't appear to duplicate any of the sublist items. Unfortunately the way the system is set up it's difficult to fully verify that truth.
- Is there anything blatantly wrong with this set up? My main concern is that every item in the list could potentially be duplicated, instead of updated on changes, because there is no uniqueID to connect them to the previously stored items.
- How would I go about testing this using sinon?
Aucun commentaire:
Enregistrer un commentaire