Skip to content

Commit

Permalink
test: convert #3973 test to async/await to try to work around deno te…
Browse files Browse the repository at this point in the history
…st failures re: #9056
  • Loading branch information
vkarpov15 committed Sep 5, 2022
1 parent 8697ce5 commit 32e8055
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions test/model.populate.test.js
Expand Up @@ -3783,7 +3783,7 @@ describe('model: populate:', function() {
}
});

it('4 level population (gh-3973)', function(done) {
it('4 level population (gh-3973)', async function() {
const level4Schema = new Schema({
name: { type: String }
});
Expand All @@ -3809,36 +3809,29 @@ describe('model: populate:', function() {
const level1 = db.model('Test', level1Schema);

const l4docs = [{ name: 'level 4' }];
const l4 = await level4.create(l4docs);

level4.create(l4docs, function(error, l4) {
assert.ifError(error);
const l3docs = [{ name: 'level 3', level4: l4[0]._id }];
level3.create(l3docs, function(error, l3) {
assert.ifError(error);
const l2docs = [{ name: 'level 2', level3: l3[0]._id }];
level2.create(l2docs, function(error, l2) {
assert.ifError(error);
const l1docs = [{ name: 'level 1', level2: l2[0]._id }];
level1.create(l1docs, function(error, l1) {
assert.ifError(error);
const opts = {
path: 'level2',
populate: {
path: 'level3',
populate: {
path: 'level4'
}
}
};
level1.findById(l1[0]._id).populate(opts).exec(function(error, obj) {
assert.ifError(error);
assert.equal(obj.level2[0].level3[0].level4[0].name, 'level 4');
done();
});
});
});
});
});
const l3docs = [{ name: 'level 3', level4: l4[0]._id }];
const l3 = await level3.create(l3docs);

const l2docs = [{ name: 'level 2', level3: l3[0]._id }];
const l2 = await level2.create(l2docs);

const l1docs = [{ name: 'level 1', level2: l2[0]._id }];
const l1 = await level1.create(l1docs);

const opts = {
path: 'level2',
populate: {
path: 'level3',
populate: {
path: 'level4'
}
}
};

const obj = await level1.findById(l1[0]._id).populate(opts).exec();
assert.equal(obj.level2[0].level3[0].level4[0].name, 'level 4');
});

it('deep populate two paths (gh-3974)', function(done) {
Expand Down

0 comments on commit 32e8055

Please sign in to comment.