mongoose-slug-updater
Advanced tools
Comparing version 2.2.0 to 2.3.0
'use strict'; | ||
// const _ = require('deepdash')(require('lodash')); | ||
const _ = require('lodash'); | ||
const _ = require('deepdash')(require('lodash')); | ||
const fs = require('fs'); | ||
@@ -37,3 +37,5 @@ var getSlug = require('speakingurl'), | ||
schemaType.caster.schema, | ||
basePath + schemaPath + (schemaType.constructor.schemaName == 'DocumentArray'?'.*':''), | ||
basePath + | ||
schemaPath + | ||
(schemaType.constructor.schemaName == 'DocumentArray' ? '.*' : ''), | ||
cb | ||
@@ -154,23 +156,23 @@ ); | ||
// console.log("doc",docs[0]); | ||
let updFields = Object.keys(docs[0]); | ||
if (!updFields.filter(value => -1 !== watcher.indexOf(value)).length) { | ||
// console.log('no slug update needed', updFields, watcher); | ||
let unwoundSlugs = unwindSlugs( | ||
docs[0], | ||
_.filter(slugs, `on.${operation}`), | ||
_.get, | ||
updIsModified | ||
); | ||
// console.log(_.filter(unwoundSlugs,['path','children.0.subChildren'])); | ||
if (!unwoundSlugs.length) { | ||
// console.log('no slugs affected', watcher); | ||
return; | ||
} | ||
let affectedSlugs = slugs.filter( | ||
slug => | ||
slug.on[operation] && | ||
(slug.fields.filter(slugValue => updFields.indexOf(slugValue) !== -1) | ||
.length || | ||
(slug.uniqueGroup && | ||
slug.uniqueGroup.filter( | ||
slugValue => updFields.indexOf(slugValue) !== -1 | ||
).length)) | ||
); | ||
if (!affectedSlugs.length) return; | ||
// console.log("affectedSlugs",affectedSlugs); | ||
let missingFields = affectedSlugs | ||
let updFields = _.keysDeep(docs[0]); | ||
let updPaths= _.map(updFields,(f)=>f.replace(/\[(.+?)\]/g,'.$1')); | ||
// console.log(updFields); | ||
// console.log(updPaths); | ||
// console.log("unwoundSlugs",unwoundSlugs); | ||
let missingFields = unwoundSlugs | ||
.reduce((acc, slug) => acc.concat(slug.fields).concat([slug.path]), []) | ||
.filter(val => updFields.indexOf(val) == -1); | ||
.filter(val => updPaths.indexOf(val) == -1); | ||
// console.log("missingFields",missingFields); | ||
@@ -186,12 +188,14 @@ if (missingFields.length) { | ||
// } | ||
if (!Array.isArray(missingValuesDocs)) | ||
missingValuesDocs = [missingValuesDocs]; | ||
missingValuesDocs.forEach((missingValuesDoc, i) => { | ||
if (i) docs[i] = { ...docs[0] }; | ||
missingFields.forEach(function(f) { | ||
if (missingValuesDoc) docs[i][f] = missingValuesDoc[f]; | ||
if (missingValuesDocs) { | ||
if (!Array.isArray(missingValuesDocs)) | ||
missingValuesDocs = [missingValuesDocs]; | ||
missingValuesDocs.forEach((missingValuesDoc, i) => { | ||
if (i) docs[i] = { ...docs[0] }; | ||
missingFields.forEach(function(f) { | ||
_.set(docs[i], f, _.get(missingValuesDoc, f)); | ||
}); | ||
if (missingValuesDoc && missingValuesDoc._id) | ||
docs[i]._id = missingValuesDoc._id; | ||
}); | ||
if (missingValuesDoc && missingValuesDoc._id) | ||
docs[i]._id = missingValuesDoc._id; | ||
}); | ||
} | ||
} else { | ||
@@ -204,8 +208,10 @@ let query = me.getQuery(); | ||
](me.getQuery(), '_id'); | ||
if (!Array.isArray(missingValuesDocs)) | ||
missingValuesDocs = [missingValuesDocs]; | ||
missingValuesDocs.forEach((missingValuesDoc, i) => { | ||
if (i) docs[i] = { ...docs[0] }; | ||
if (missingValuesDoc._id) docs[i]._id = missingValuesDoc._id; | ||
}); | ||
if (missingValuesDocs) { | ||
if (!Array.isArray(missingValuesDocs)) | ||
missingValuesDocs = [missingValuesDocs]; | ||
missingValuesDocs.forEach((missingValuesDoc, i) => { | ||
if (i) docs[i] = { ...docs[0] }; | ||
if (missingValuesDoc._id) docs[i]._id = missingValuesDoc._id; | ||
}); | ||
} | ||
} | ||
@@ -220,10 +226,14 @@ } | ||
for (let i = 0; i < docs.length; i++) { | ||
await setSlugs(docs[i], affectedSlugs, options, _.get, _.set, findOne); | ||
await setSlugs(docs[i], unwoundSlugs, options, _.get, _.set, findOne); | ||
// console.log("after setSlugs",docs[i]); | ||
slugsUpd[i] = {}; | ||
affectedSlugs.forEach(slug => { | ||
if (docs[i][slug.path]) slugsUpd[i][slug.path] = docs[i][slug.path]; | ||
slugsUpd[i] = _.cloneDeep(upd.$set || upd); | ||
unwoundSlugs.forEach(slug => { | ||
let slugVal = _.get(docs[i], slug.path); | ||
// if(slugVal==="0-am-i-wrong-fallin-in-love-with-you") | ||
// console.log("000 ",slug); | ||
if (slugVal != undefined) _.set(slugsUpd[i], slug.path, slugVal); | ||
}); | ||
if (upd.$set) slugsUpd[i] = { $set: slugsUpd[i] }; | ||
// console.log('upd',slugsUpd[i]); | ||
if (docs.length == 1) me[operation]({}, slugsUpd[i]); | ||
@@ -252,52 +262,9 @@ else { | ||
let unwoundSlugs = []; | ||
slugs.forEach(slug => { | ||
if (!slug.on.save) return; | ||
let slugPaths = unwindPath(doc, slug.path); | ||
let basePath = slug.basePath; | ||
// console.log(slug.path,'vs',slug.path); | ||
if (_.endsWith(basePath, '.*')) basePath += '.'; | ||
slugPaths.forEach(slugPath => { | ||
let unwoundBasePath = slugPath.replace(/\.[^\.]+$/, ''); | ||
if (unwoundBasePath == slugPath) unwoundBasePath = ''; | ||
// console.log("unwoundBasePath",unwoundBasePath); | ||
function unwindFieldPath(fieldPath) { | ||
let slugValueBasePath = unwoundBasePath; | ||
while (_.startsWith(fieldPath, ':')) { | ||
// console.log("relative path ",slugValueBasePath,fieldPath); | ||
let prevValueBasePath = slugValueBasePath; | ||
if (slugValueBasePath.match(/\.\d+$/)) { | ||
slugValueBasePath = slugValueBasePath.replace(/\.\d+$/, ''); | ||
prevValueBasePath = slugValueBasePath; | ||
} | ||
slugValueBasePath = slugValueBasePath.replace(/\.[^\.]+$/, ''); | ||
if (slugValueBasePath == prevValueBasePath) slugValueBasePath = ''; | ||
fieldPath = fieldPath.substr(1); | ||
// console.log("unwind relative path ",slugValueBasePath,fieldPath); | ||
} | ||
if (!_.startsWith(fieldPath, '/')) | ||
fieldPath = | ||
((slugValueBasePath && slugValueBasePath + '.') || '') + | ||
fieldPath; | ||
else fieldPath = fieldPath.substr(1); | ||
return fieldPath; | ||
} | ||
let unwoundFields = slug.fields.map(unwindFieldPath); | ||
let unwoundGroupPaths = (slug.uniqueGroup || []).map(unwindFieldPath); | ||
if ( | ||
_.some(unwoundFields.concat(unwoundGroupPaths), path => { | ||
return doc.isModified(path); | ||
}) | ||
) { | ||
let s = _.cloneDeep(slug); | ||
s.path = slugPath; | ||
s.basePath = unwoundBasePath; | ||
s.fields = unwoundFields; | ||
s.uniqueGroup = unwoundGroupPaths; | ||
unwoundSlugs.push(s); | ||
} else { | ||
// console.log('fields not changed', unwoundFields); | ||
} | ||
}); | ||
}); | ||
let unwoundSlugs = unwindSlugs( | ||
doc, | ||
_.filter(slugs, 'on.save'), | ||
docGet, | ||
docIsModified | ||
); | ||
if (!unwoundSlugs.length) { | ||
@@ -308,18 +275,70 @@ // console.log('no slugs affected', watcher); | ||
// console.log('slugs',slugs); | ||
doc = await setSlugs( | ||
doc, | ||
unwoundSlugs, | ||
options, | ||
(doc, path) => doc.get(path), | ||
(doc, path, val) => doc.set(path, val), | ||
query => { | ||
if (!doc.model) { | ||
throw new Error('Unique nested slugs not implemented yet'); | ||
doc = await setSlugs(doc, unwoundSlugs, options, docGet, docSet, query => { | ||
if (!doc.model) { | ||
throw new Error('Unique nested slugs not implemented yet'); | ||
} | ||
return doc.model(doc.constructor.modelName).findOne(query); | ||
}); | ||
}); | ||
}; | ||
let docGet = (doc, path) => doc.get(path); | ||
let docSet = (doc, path, val) => doc.set(path, val); | ||
let docIsModified = (doc, path) => doc.isModified(path); | ||
let updIsModified = (upd, path) => _.get(upd, path) !== undefined; | ||
function unwindSlugs(doc, slugs, get, isModified) { | ||
let unwoundSlugs = []; | ||
slugs.forEach(slug => { | ||
let slugPaths = unwindPath(doc, slug.path, get); | ||
let basePath = slug.basePath; | ||
// console.log(slug.path,'vs',slug.path); | ||
if (_.endsWith(basePath, '.*')) basePath += '.'; | ||
slugPaths.forEach(slugPath => { | ||
let unwoundBasePath = slugPath.replace(/\.[^\.]+$/, ''); | ||
if (unwoundBasePath == slugPath) unwoundBasePath = ''; | ||
// console.log("unwoundBasePath",unwoundBasePath); | ||
function unwindFieldPath(fieldPath) { | ||
let slugValueBasePath = unwoundBasePath; | ||
while (_.startsWith(fieldPath, ':')) { | ||
// console.log("relative path ",slugValueBasePath,fieldPath); | ||
let prevValueBasePath = slugValueBasePath; | ||
if (slugValueBasePath.match(/\.\d+$/)) { | ||
slugValueBasePath = slugValueBasePath.replace(/\.\d+$/, ''); | ||
prevValueBasePath = slugValueBasePath; | ||
} | ||
slugValueBasePath = slugValueBasePath.replace(/\.[^\.]+$/, ''); | ||
if (slugValueBasePath == prevValueBasePath) slugValueBasePath = ''; | ||
fieldPath = fieldPath.substr(1); | ||
// console.log("unwind relative path ",slugValueBasePath,fieldPath); | ||
} | ||
return doc.model(doc.constructor.modelName).findOne(query); | ||
if (!_.startsWith(fieldPath, '/')) | ||
fieldPath = | ||
((slugValueBasePath && slugValueBasePath + '.') || '') + fieldPath; | ||
else fieldPath = fieldPath.substr(1); | ||
return fieldPath; | ||
} | ||
); | ||
let unwoundFields = slug.fields.map(unwindFieldPath); | ||
let unwoundGroupPaths = (slug.uniqueGroup || []).map(unwindFieldPath); | ||
if ( | ||
_.some(unwoundFields.concat(unwoundGroupPaths), path => { | ||
return isModified(doc, path); | ||
}) | ||
) { | ||
let s = _.cloneDeep(slug); | ||
s.path = slugPath; | ||
s.basePath = unwoundBasePath; | ||
s.fields = unwoundFields; | ||
s.uniqueGroup = unwoundGroupPaths; | ||
unwoundSlugs.push(s); | ||
} else { | ||
// console.log('fields not changed', unwoundFields); | ||
} | ||
}); | ||
}); | ||
}; | ||
function unwindPath(doc, path, restPathParts) { | ||
return unwoundSlugs; | ||
} | ||
function unwindPath(doc, path, get, restPathParts) { | ||
if (restPathParts === undefined) { | ||
@@ -332,3 +351,4 @@ restPathParts = path.split('.*.'); | ||
let res = []; | ||
let value = doc.get(path); | ||
let value = get(doc, path); | ||
// console.log("unwindPath",doc,path,value); | ||
if (_.isArray(value)) { | ||
@@ -339,16 +359,6 @@ // console.log('value is array?',_.isArray(value),value.length); | ||
// console.log('lets check', childPath); | ||
res = res.concat( | ||
unwindPath( | ||
doc, | ||
path + '.' + i + '.' + restPathParts[0], | ||
_.drop(restPathParts) | ||
) | ||
); | ||
res = res.concat(unwindPath(doc, childPath, get, _.drop(restPathParts))); | ||
} | ||
} else { | ||
// console.log('value is not array',value); | ||
// if(doc.isModified(path)){ | ||
// console.log('modified!'); | ||
res.push(path); | ||
// } | ||
if (!restPathParts || !restPathParts.length) res.push(path); | ||
} | ||
@@ -355,0 +365,0 @@ return res; |
{ | ||
"name": "mongoose-slug-updater", | ||
"version": "2.2.0", | ||
"description": "Mongoose plugin to create and update slugs and unique slugs in any field", | ||
"version": "2.3.0", | ||
"description": "Mongoose plugin to create and update slugs and unique slugs in any field, nested too. Create, Save, Update, FindAndUpdate operations supported.", | ||
"main": "index.js", | ||
@@ -37,3 +37,4 @@ "directories": { | ||
"nice url", | ||
"update slug" | ||
"update slug", | ||
"nested slug" | ||
], | ||
@@ -56,4 +57,4 @@ "author": "Yuri Gor (http://yurigor.com)", | ||
"dependencies": { | ||
"deepdash": "^1.0.1", | ||
"shortid": "^2.2.4", | ||
"deepdash": "^1.3.2", | ||
"shortid": "^2.2.14", | ||
"speakingurl": "^7.0.0" | ||
@@ -63,8 +64,8 @@ }, | ||
"chai": "^4.2.0", | ||
"eslint": "*", | ||
"eslint": "^5.8.0", | ||
"mocha": "^5.2.0", | ||
"mongodb-memory-server": "^2.6.2", | ||
"mongoose": "^5.3.7", | ||
"nodemon": "^1.18.5" | ||
"mongodb-memory-server": "^2.7.0", | ||
"mongoose": "^5.3.10", | ||
"nodemon": "^1.18.6" | ||
} | ||
} |
# mongoose-slug-updater | ||
Mongoose plugin for creating and updating slugs based on mongoose schema fields. | ||
Operations `save`, `update`, `updateOne`, `updateMany` and `findOneAndUpdate` are supported. | ||
Mongoose plugin for creating and updating slugs based on mongoose schema fields.<br> | ||
Operations `save`, `update`, `updateOne`, `updateMany` and `findOneAndUpdate` are supported both for creation and modifying.<br> | ||
Nested documents and arrays supported too with relative/absolute path to any field of the document.<br> | ||
For example you can create a slug based on a document's title and author's name: _my-post-title-slim-shady_, or unique slugs based on just the title: _my-post-title-Nyiy4wW9l_. | ||
Update operators support and nested unique slugs coming soon. | ||
## Installation | ||
@@ -151,4 +154,4 @@ | ||
If you don't want to define your field as unique for some reasons, but still need slug to be unique, | ||
you can use `unique_slug:true` option instead of `unique`. | ||
If you don't want to define your field as unique for some reasons, but still need slug to be unique,<br> | ||
you can use `unique_slug:true` option instead of `unique`.<br> | ||
This option will not cause index creation, but still will be considered by the plugin. | ||
@@ -158,3 +161,4 @@ | ||
Sometimes you only want slugs to be unique within a specific group. This is done with the `uniqueGroup` property which is an array of fields to group by: | ||
Sometimes you only want slugs to be unique within a specific group.<br> | ||
This is done with the `uniqueGroup` property which is an array of fields to group by: | ||
@@ -236,8 +240,8 @@ **example unique per group (using the field named 'group')** | ||
so if you disabled `save` and still want slug to be generated initially, | ||
use `upsert` option of `update***` methods. | ||
use `upsert` option of `update***` methods.<br> | ||
On `update` and `updateMany` multiply affected records also handled, but be careful with performance, | ||
because one-by-one iteration over affected documents may happen in case of unique slugs. | ||
In this case `_id` field is required. | ||
For `update*` family of operations additional queries may be performed, to retrieve data missing in the query. | ||
For example if compound slug was affected by this update. | ||
because one-by-one iteration over affected documents may happen in case of unique slugs.<br> | ||
In this case `_id` field is required.<br> | ||
For `update*` family of operations additional queries may be performed, to retrieve data missing in the query.<br> | ||
For example if compound slug was affected by this update.<br> | ||
So if you already have necessary data - it's better for performance to specify all the fields listed in the compound slug and old slug value in update query. | ||
@@ -267,3 +271,3 @@ | ||
Nested docs and arrays declared inline right in the scheme or as a nested schemas declared separately are also supported. | ||
For now only `save` method supported. `update***` methods family implementation is in progress. | ||
Non-unique nested slugs are currently implemented. Unique nested slugs are coming soon. | ||
@@ -270,0 +274,0 @@ |
'use strict'; | ||
const mongoose = require('mongoose'); | ||
const slug_padding_size = 4, | ||
nIterations = 100; | ||
nIterations = 15; | ||
const slugGenerator = require('../.'); | ||
@@ -138,2 +138,17 @@ const options = { | ||
const SimpleInlineSchema = new mongoose.Schema({ | ||
title: { type: String }, | ||
slug: { type: String, slug: 'title' }, | ||
child:{ | ||
title: { type: String }, | ||
slug: { type: String, slug: 'title' } | ||
}, | ||
children:[ | ||
{ | ||
title: { type: String }, | ||
slug: { type: String, slug: 'title' } | ||
} | ||
] | ||
}); | ||
const InlineSchema = new mongoose.Schema({ | ||
@@ -288,2 +303,3 @@ // root title | ||
const Inline = mongoose.model('InlineSchema', InlineSchema); | ||
const SimpleInline = mongoose.model('SimpleInlineSchema', SimpleInlineSchema); | ||
const InlineUnique = mongoose.model('InlineUniqueSchema', InlineUniqueSchema); | ||
@@ -309,3 +325,4 @@ const SimpleChild = mongoose.model('SimpleChildSchema', SimpleChildSchema); | ||
Inline, | ||
SimpleInline, | ||
InlineUnique, | ||
}; |
@@ -53,282 +53,356 @@ 'use strict'; | ||
it('Save nested doc declared in extrenal schemas', async () => { | ||
let docCfg = { | ||
title: tellme.getText(0), | ||
child: { | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
subChildren: [], | ||
let docCfg = getNewDoc(); | ||
let doc = await Parent.create(docCfg); | ||
testNewDoc(doc); | ||
doc = changeNewDoc(doc); | ||
await doc.save(); | ||
testChangedDoc(doc); | ||
}); | ||
it('UpdateOne nested docs declared in extrenal schemas', async () => { | ||
await Parent.updateOne({}, getNewDoc(), { upsert: true }); | ||
let doc = await Parent.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeNewDoc({}); | ||
await Parent.updateOne({ _id: doc._id }, mdf); | ||
let editedDoc = await Parent.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('Update nested docs declared in extrenal schemas', async () => { | ||
await Parent.update({}, getNewDoc(), { upsert: true }); | ||
let doc = await Parent.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeNewDoc({}); | ||
await Parent.update({ _id: doc._id }, mdf); | ||
let editedDoc = await Parent.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('UpdateMany nested docs declared in extrenal schemas', async () => { | ||
await Parent.updateMany({}, getNewDoc(), { upsert: true }); | ||
let doc = await Parent.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeNewDoc({}); | ||
await Parent.updateMany({ _id: doc._id }, mdf); | ||
let editedDoc = await Parent.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('findOneAndUpdate nested docs declared in extrenal schemas', async () => { | ||
let doc = await Parent.findOneAndUpdate({}, getNewDoc(), { | ||
upsert: true, | ||
new: true, | ||
}); | ||
testNewDoc(doc); | ||
let mdf = changeNewDoc({}); | ||
let editedDoc = await Parent.findOneAndUpdate({ _id: doc._id }, mdf, { | ||
new: true, | ||
}); | ||
testChangedDoc(editedDoc); | ||
}); | ||
}); | ||
function getNewDoc() { | ||
let doc = { | ||
title: tellme.getText(0), | ||
child: { | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
children: [], | ||
}; | ||
subChildren: [], | ||
}, | ||
children: [], | ||
}; | ||
for (let i = 0; i < 9; i++) { | ||
docCfg.child.subChildren.push({ | ||
for (let i = 0; i < 9; i++) { | ||
doc.child.subChildren.push({ | ||
title: tellme.getText(i), | ||
}); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.children.push({ | ||
title: tellme.getText(8 - i), | ||
subChild: { | ||
title: tellme.getText(i), | ||
}); | ||
} | ||
}, | ||
subChildren: _.cloneDeep(doc.child.subChildren), | ||
}); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
docCfg.children.push({ | ||
title: tellme.getText(8 - i), | ||
subChild: { | ||
title: tellme.getText(i), | ||
}, | ||
subChildren: _.cloneDeep(docCfg.child.subChildren), | ||
}); | ||
} | ||
return doc; | ||
} | ||
let doc = await Parent.create(docCfg); | ||
function testNewDoc(doc) { | ||
doc.should.have.property('title').and.equal(tellme.getText(0)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(2)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(3)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(2)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(3)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChildSlug') | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug2') | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug3') | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteChildSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.subChildSlug') | ||
.and.equal(tellme.getSlug(2)); | ||
.property(`child.subChildren.${i}.title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
.property(`child.subChildren.${i}.slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property('child.absoluteRootSlug') | ||
.property(`child.subChildren.${i}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
.property(`child.subChildren.${i}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug2') | ||
.and.equal(tellme.getSlug(2)); | ||
.property(`child.subChildren.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug3') | ||
.and.equal(tellme.getSlug(3)); | ||
.property(`child.subChildren.${i}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(2)); | ||
.property(`children.${i}.title`) | ||
.and.equal(tellme.getText(8 - i)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(2)); | ||
.property(`children.${i}.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
.property(`children.${i}.subChildSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteChildSlug') | ||
.property(`children.${i}.absoluteSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
.property(`children.${i}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.property(`children.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug2`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug3`) | ||
.and.equal(tellme.getSlug(3)); | ||
for (let i = 0; i < 9; i++) { | ||
for (let j = 0; j < 9; j++) { | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.title`) | ||
.and.equal(tellme.getText(i)); | ||
.property(`children.${i}.subChildren.${j}.title`) | ||
.and.equal(tellme.getText(j)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
.property(`children.${i}.subChildren.${j}.slug`) | ||
.and.equal(tellme.getSlug(j)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.absoluteRootSlug`) | ||
.property(`children.${i}.subChildren.${j}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.absoluteChildSlug`) | ||
.property(`children.${i}.subChildren.${j}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property(`children.${i}.slug`) | ||
.property(`children.${i}.subChildren.${j}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.absoluteSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children.${i}.absoluteRootSlug`) | ||
.property(`children.${i}.subChildren.${j}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug2`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug3`) | ||
.and.equal(tellme.getSlug(3)); | ||
for (let j = 0; j < 9; j++) { | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.title`) | ||
.and.equal(tellme.getText(j)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.slug`) | ||
.and.equal(tellme.getSlug(j)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
} | ||
} | ||
} | ||
doc.title = tellme.getText(8); | ||
doc.child.title = tellme.getText(7); | ||
doc.child.subChild.title = tellme.getText(6); | ||
function changeNewDoc(doc) { | ||
let changed = { | ||
title: tellme.getText(8), | ||
child: { | ||
title: tellme.getText(7), | ||
subChild: { title: tellme.getText(6) }, | ||
subChildren: [], | ||
}, | ||
children: [], | ||
}; | ||
for (let i = 0; i < 9; i++) { | ||
doc.child.subChildren[i].title = tellme.getText(8-i); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
changed.child.subChildren[i] = { title: tellme.getText(8 - i) }; | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.children[i].title = tellme.getText(i); | ||
doc.children[i].subChild.title = tellme.getText(8-i); | ||
for(let j =0;j<9;j++){ | ||
doc.children[i].subChildren[j].title = tellme.getText(8-j); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
changed.children[i] = { title: tellme.getText(i), subChildren: [] }; | ||
changed.children[i].subChild = { title: tellme.getText(8 - i) }; | ||
for (let j = 0; j < 9; j++) { | ||
changed.children[i].subChildren[j] = { title: tellme.getText(8 - j) }; | ||
} | ||
} | ||
return _.merge(doc, changed); | ||
} | ||
await doc.save(); | ||
function testChangedDoc(doc) { | ||
doc.should.have.property('title').and.equal(tellme.getText(8)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(6)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(5)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(6)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(5)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(7)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChildSlug') | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug2') | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug3') | ||
.and.equal(tellme.getSlug(5)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(7)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(6)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteChildSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.subChildSlug') | ||
.and.equal(tellme.getSlug(6)); | ||
.property(`child.subChildren.${i}.title`) | ||
.and.equal(tellme.getText(8 - i)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
.property(`child.subChildren.${i}.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property('child.absoluteRootSlug') | ||
.property(`child.subChildren.${i}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`child.subChildren.${i}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug2') | ||
.and.equal(tellme.getSlug(6)); | ||
.property(`child.subChildren.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChildrenSlug3') | ||
.and.equal(tellme.getSlug(5)); | ||
.property(`child.subChildren.${i}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(6)); | ||
.property(`children.${i}.title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(6)); | ||
.property(`children.${i}.slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteRootSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`children.${i}.subChildSlug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteChildSlug') | ||
.property(`children.${i}.absoluteSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
.property(`children.${i}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.property(`children.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug2`) | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug3`) | ||
.and.equal(tellme.getSlug(5)); | ||
for (let i = 0; i < 9; i++) { | ||
for (let j = 0; j < 9; j++) { | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.title`) | ||
.and.equal(tellme.getText(8-i)); | ||
.property(`children.${i}.subChildren.${j}.title`) | ||
.and.equal(tellme.getText(8 - j)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.slug`) | ||
.and.equal(tellme.getSlug(8-i)); | ||
.property(`children.${i}.subChildren.${j}.slug`) | ||
.and.equal(tellme.getSlug(8 - j)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.absoluteRootSlug`) | ||
.property(`children.${i}.subChildren.${j}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.absoluteChildSlug`) | ||
.property(`children.${i}.subChildren.${j}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`child.subChildren.${i}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property(`children.${i}.slug`) | ||
.property(`children.${i}.subChildren.${j}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildSlug`) | ||
.and.equal(tellme.getSlug(8-i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.absoluteSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children.${i}.absoluteRootSlug`) | ||
.property(`children.${i}.subChildren.${j}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children.${i}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug2`) | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildrenSlug3`) | ||
.and.equal(tellme.getSlug(5)); | ||
for (let j = 0; j < 9; j++) { | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.title`) | ||
.and.equal(tellme.getText(8-j)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.slug`) | ||
.and.equal(tellme.getSlug(8-j)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children.${i}.subChildren.${j}.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} |
@@ -8,3 +8,3 @@ 'use strict'; | ||
const { nIterations, Inline } = require('./../models'); | ||
const { nIterations, Inline, SimpleInline } = require('./../models'); | ||
@@ -17,2 +17,3 @@ const tellme = require('./../tellme'); | ||
await Inline.remove({}); | ||
await SimpleInline.remove({}); | ||
}); | ||
@@ -22,5 +23,42 @@ | ||
await Inline.remove({}); | ||
await SimpleInline.remove({}); | ||
}); | ||
it('Save nested docs declared inline', async () => { | ||
let doc = await Inline.create(getNewDoc()); | ||
testNewDoc(doc); | ||
changeDoc(doc); | ||
doc = await doc.save(); | ||
testChangedDoc(doc); | ||
}); | ||
it('UpdateOne upsert simple nested docs declared inline', async () => { | ||
await SimpleInline.updateOne( | ||
{}, | ||
{ | ||
title: tellme.getText(0), | ||
child: { | ||
title: tellme.getText(1), | ||
}, | ||
children: [ | ||
{ | ||
title: tellme.getText(2), | ||
}, | ||
], | ||
}, | ||
{ upsert: true } | ||
); | ||
let doc = await SimpleInline.findOne({}); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
}); | ||
it('Create partial nested docs declared inline', async () => { | ||
let doc = await Inline.create({ | ||
@@ -30,368 +68,507 @@ title: tellme.getText(0), | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
}, | ||
children: [ | ||
{ | ||
title: tellme.getText(0), | ||
subChild: { | ||
title: tellme.getText(8), | ||
title: tellme.getText(2), | ||
}, | ||
], | ||
}); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
}); | ||
it('UpdateOne upsert partial nested docs declared inline', async () => { | ||
await Inline.updateOne( | ||
{}, | ||
{ | ||
title: tellme.getText(0), | ||
child: { | ||
title: tellme.getText(1), | ||
}, | ||
children: [ | ||
{ | ||
title: tellme.getText(2), | ||
}, | ||
subChildren: [ | ||
{ | ||
title: tellme.getText(0), | ||
subChild: { | ||
title: tellme.getText(8), | ||
}, | ||
], | ||
}, | ||
{ upsert: true } | ||
); | ||
let doc = await Inline.findOne({}); | ||
// console.log(doc); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
}); | ||
it('UpdateOne nested docs declared inline', async () => { | ||
await Inline.updateOne({},getNewDoc(),{upsert:true}); | ||
let doc = await Inline.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeDoc({}); | ||
await Inline.updateOne({ _id:doc._id }, mdf); | ||
let editedDoc = await Inline.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('Update nested docs declared inline', async () => { | ||
await Inline.update({},getNewDoc(),{upsert:true}); | ||
let doc = await Inline.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeDoc({}); | ||
await Inline.update({ _id:doc._id }, mdf); | ||
let editedDoc = await Inline.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('UpdateMany nested docs declared inline', async () => { | ||
await Inline.updateMany({},getNewDoc(),{upsert:true}); | ||
let doc = await Inline.findOne({}); | ||
testNewDoc(doc); | ||
let mdf = changeDoc({}); | ||
await Inline.updateMany({ _id:doc._id }, mdf); | ||
let editedDoc = await Inline.findById(doc._id); | ||
testChangedDoc(editedDoc); | ||
}); | ||
it('findOneAndUpdate nested docs declared inline', async () => { | ||
let doc = await Inline.findOneAndUpdate({},getNewDoc(),{upsert:true,new:true}); | ||
testNewDoc(doc); | ||
let mdf = changeDoc({}); | ||
let editedDoc = await Inline.findOneAndUpdate({ _id:doc._id }, mdf,{new:true}); | ||
testChangedDoc(editedDoc); | ||
}); | ||
}); | ||
function getNewDoc() { | ||
return { | ||
title: tellme.getText(0), | ||
child: { | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
}, | ||
children: [ | ||
{ | ||
title: tellme.getText(0), | ||
subChild: { | ||
title: tellme.getText(8), | ||
}, | ||
subChildren: [ | ||
{ | ||
title: tellme.getText(0), | ||
subChild: { | ||
title: tellme.getText(8), | ||
}, | ||
{ | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
{ | ||
title: tellme.getText(2), | ||
subChild: { | ||
title: tellme.getText(6), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(2), | ||
subChild: { | ||
title: tellme.getText(6), | ||
}, | ||
{ | ||
title: tellme.getText(3), | ||
subChild: { | ||
title: tellme.getText(5), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(3), | ||
subChild: { | ||
title: tellme.getText(5), | ||
}, | ||
{ | ||
}, | ||
{ | ||
title: tellme.getText(4), | ||
subChild: { | ||
title: tellme.getText(4), | ||
subChild: { | ||
title: tellme.getText(4), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(5), | ||
subChild: { | ||
title: tellme.getText(3), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(5), | ||
subChild: { | ||
title: tellme.getText(3), | ||
}, | ||
{ | ||
title: tellme.getText(6), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(6), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
{ | ||
title: tellme.getText(7), | ||
subChild: { | ||
title: tellme.getText(1), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(7), | ||
subChild: { | ||
title: tellme.getText(1), | ||
}, | ||
{ | ||
title: tellme.getText(8), | ||
subChild: { | ||
title: tellme.getText(0), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(8), | ||
subChild: { | ||
title: tellme.getText(0), | ||
}, | ||
], | ||
}, | ||
{ | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
], | ||
}, | ||
{ | ||
title: tellme.getText(1), | ||
subChild: { | ||
title: tellme.getText(7), | ||
}, | ||
{ | ||
title: tellme.getText(2), | ||
subChild: { | ||
title: tellme.getText(6), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(2), | ||
subChild: { | ||
title: tellme.getText(6), | ||
}, | ||
{ | ||
title: tellme.getText(3), | ||
subChild: { | ||
title: tellme.getText(5), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(3), | ||
subChild: { | ||
title: tellme.getText(5), | ||
}, | ||
{ | ||
}, | ||
{ | ||
title: tellme.getText(4), | ||
subChild: { | ||
title: tellme.getText(4), | ||
subChild: { | ||
title: tellme.getText(4), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(5), | ||
subChild: { | ||
title: tellme.getText(3), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(5), | ||
subChild: { | ||
title: tellme.getText(3), | ||
}, | ||
{ | ||
title: tellme.getText(6), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(6), | ||
subChild: { | ||
title: tellme.getText(2), | ||
}, | ||
{ | ||
title: tellme.getText(7), | ||
subChild: { | ||
title: tellme.getText(1), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(7), | ||
subChild: { | ||
title: tellme.getText(1), | ||
}, | ||
{ | ||
title: tellme.getText(8), | ||
subChild: { | ||
title: tellme.getText(0), | ||
}, | ||
}, | ||
{ | ||
title: tellme.getText(8), | ||
subChild: { | ||
title: tellme.getText(0), | ||
}, | ||
], | ||
}); | ||
}, | ||
], | ||
}; | ||
} | ||
// console.log(doc); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(3)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('subChildrenSlug5SubChild').and.equal(tellme.getSlug(3)); | ||
doc.should.have.property('subChildrenSlug2SubChild').and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
function testNewDoc(doc) { | ||
doc.should.have.property('title').and.equal(tellme.getText(0)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(3)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(7)); | ||
doc.should.have | ||
.property('subChildrenSlug5SubChild') | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have | ||
.property('subChildrenSlug2SubChild') | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(1)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.and.equal(tellme.getSlug(0)); | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(1)); | ||
.property(`children[${i}].title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property('child.absoluteParentSlug') | ||
.property(`children[${i}].slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.property(`children[${i}].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[${i}].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(7)); | ||
.property(`children[${i}].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(7)); | ||
.property(`children[${i}].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteParentSlug') | ||
.property(`children[${i}].subChild.title`) | ||
.and.equal(tellme.getText(8 - i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.property(`children[${i}].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.property(`children[${i}].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property(`children[${i}].title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[${i}].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[${i}].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[${i}].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have.nested | ||
.property(`children[${i}].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(5)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
doc.title = tellme.getText(8); | ||
doc.child.title = tellme.getText(7); | ||
doc.child.subChild.title = tellme.getText(6); | ||
doc.children[0].title = tellme.getText(4); | ||
doc.children[3].title = tellme.getText(7); | ||
doc.children[4].title = tellme.getText(0); | ||
doc.children[0].subChildren[3].title = tellme.getText(8); | ||
doc.children[0].subChildren[7].title = tellme.getText(2); | ||
doc.children[0].subChildren[5].title = tellme.getText(4); | ||
doc.children[0].subChildren[6].title = tellme.getText(1); | ||
doc.children[0].subChildren[5].subChild.title = tellme.getText(2); | ||
doc.children[0].subChildren[2].subChild.title = tellme.getText(4); | ||
doc.children[7].subChild.title = tellme.getText(3); | ||
doc = await doc.save(); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(6)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(2)); | ||
doc.should.have.property('subChildrenSlug5SubChild').and.equal(tellme.getSlug(2)); | ||
doc.should.have.property('subChildrenSlug2SubChild').and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(7)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(7)); | ||
} | ||
for (let i = 0; i < 9; i++) { | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
.property(`children[0].subChildren[${i}].title`) | ||
.and.equal(tellme.getText(i)); | ||
doc.should.have.nested | ||
.property('child.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`children[0].subChildren[${i}].slug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`children[0].subChildren[${i}].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(6)); | ||
.property(`children[0].subChildren[${i}].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.property(`children[0].subChildren[${i}].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(5)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`children[0].subChildren[${i}].subChild.title`) | ||
.and.equal(tellme.getText(8 - i)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
.property(`children[0].subChildren[${i}].subChild.slug`) | ||
.and.equal(tellme.getSlug(8 - i)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
.property(`children[0].subChildren[${i}].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[${i}].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(i)); | ||
doc.should.have.nested | ||
.property(`children[${i}].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
} | ||
} | ||
doc.should.have.nested | ||
.property(`children[0].title`) | ||
.and.equal(tellme.getText(4)); | ||
doc.should.have.nested | ||
.property(`children[0].slug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[7].subChild.slug`) | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
function changeDoc(doc) { | ||
if(!doc.child)doc.child={}; | ||
if(!doc.child.subChild)doc.child.subChild={}; | ||
if(!doc.children)doc.children=[]; | ||
if(!doc.children[0])doc.children[0]={}; | ||
if(!doc.children[3])doc.children[3]={}; | ||
if(!doc.children[4])doc.children[4]={}; | ||
if(!doc.children[0].subChildren)doc.children[0].subChildren=[]; | ||
if(!doc.children[0].subChildren[2])doc.children[0].subChildren[2]={}; | ||
if(!doc.children[0].subChildren[2].subChild)doc.children[0].subChildren[2].subChild={}; | ||
if(!doc.children[0].subChildren[3])doc.children[0].subChildren[3]={}; | ||
if(!doc.children[0].subChildren[5])doc.children[0].subChildren[5]={}; | ||
if(!doc.children[0].subChildren[5].subChild)doc.children[0].subChildren[5].subChild={}; | ||
if(!doc.children[0].subChildren[6])doc.children[0].subChildren[6]={}; | ||
if(!doc.children[0].subChildren[7])doc.children[0].subChildren[7]={}; | ||
if(!doc.children[0].subChildren[8])doc.children[0].subChildren[8]={}; | ||
if(!doc.children[0].subChildren[8].subChild)doc.children[0].subChildren[8].subChild={}; | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].title`) | ||
.and.equal(tellme.getText(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].slug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[5].subChild.slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[2].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[8].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
}); | ||
if(!doc.children[7])doc.children[7]={}; | ||
if(!doc.children[7].subChildren)doc.children[7].subChildren=[]; | ||
if(!doc.children[7].subChild)doc.children[7].subChild={}; | ||
}); | ||
doc.title = tellme.getText(8); | ||
doc.child.title = tellme.getText(7); | ||
doc.child.subChild.title = tellme.getText(6); | ||
doc.children[0].title = tellme.getText(4); | ||
doc.children[3].title = tellme.getText(7); | ||
doc.children[4].title = tellme.getText(0); | ||
doc.children[0].subChildren[3].title = tellme.getText(8); | ||
doc.children[0].subChildren[7].title = tellme.getText(2); | ||
doc.children[0].subChildren[5].title = tellme.getText(4); | ||
doc.children[0].subChildren[6].title = tellme.getText(1); | ||
doc.children[0].subChildren[5].subChild.title = tellme.getText(2); | ||
doc.children[0].subChildren[2].subChild.title = tellme.getText(4); | ||
doc.children[7].subChild.title = tellme.getText(3); | ||
return doc; | ||
} | ||
function testChangedDoc(doc) { | ||
doc.should.have.property('title').and.equal(tellme.getText(8)); | ||
doc.should.have.property('slug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('absoluteSlug').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('childSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('absoluteChildSlug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.property('subChildSlug').and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property(`children[0].title`) | ||
.and.equal(tellme.getText(4)); | ||
doc.should.have.property('childrenSlug0').and.equal(tellme.getSlug(4)); | ||
doc.should.have.property('childrenSlug4').and.equal(tellme.getSlug(0)); | ||
doc.should.have.property('subChildrenSlug3').and.equal(tellme.getSlug(8)); | ||
doc.should.have.property('subChildrenSlug7').and.equal(tellme.getSlug(2)); | ||
doc.should.have | ||
.property('subChildrenSlug5SubChild') | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have | ||
.property('subChildrenSlug2SubChild') | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested.property('child.title').and.equal(tellme.getText(7)); | ||
doc.should.have.nested.property('child.slug').and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.absoluteSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.relativeParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.subChild.title') | ||
.and.equal(tellme.getText(6)); | ||
doc.should.have.nested | ||
.property('child.subChild.slug') | ||
.and.equal(tellme.getSlug(6)); | ||
doc.should.have.nested | ||
.property('child.subChild.absoluteParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeParentSlug') | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property('child.subChild.relativeGrandParentSlug') | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].slug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(0)); | ||
doc.should.have.nested | ||
.property(`children[7].subChild.title`) | ||
.and.equal(tellme.getText(3)); | ||
doc.should.have.nested | ||
.property(`children[7].subChild.slug`) | ||
.and.equal(tellme.getSlug(3)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].title`) | ||
.and.equal(tellme.getText(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].slug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].absoluteRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].relativeRootSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].absoluteSiblingSlug`) | ||
.and.equal(tellme.getSlug(4)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[7].relativeSiblingSlug`) | ||
.and.equal(tellme.getSlug(1)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[5].subChild.title`) | ||
.and.equal(tellme.getText(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[5].subChild.slug`) | ||
.and.equal(tellme.getSlug(2)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[2].subChild.absoluteParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[8].subChild.absoluteChildSlug`) | ||
.and.equal(tellme.getSlug(7)); | ||
doc.should.have.nested | ||
.property(`children[0].subChildren[3].subChild.relativeParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
doc.should.have.nested | ||
.property(`children[0].subChild.relativeGrandParentSlug`) | ||
.and.equal(tellme.getSlug(8)); | ||
} |
130366
3141
469
Updateddeepdash@^1.3.2
Updatedshortid@^2.2.14