test/relation: add missing error handlers
This commit is contained in:
parent
8935b978f3
commit
baec1b5b77
|
@ -4509,10 +4509,13 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should setup related items', function(done) {
|
it('should setup related items', function(done) {
|
||||||
Job.create({ name: 'Job 1' }, function(err, p) {
|
Job.create({ name: 'Job 1' }, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
job1 = p;
|
job1 = p;
|
||||||
Job.create({ name: 'Job 2' }, function(err, p) {
|
Job.create({ name: 'Job 2' }, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
job2 = p;
|
job2 = p;
|
||||||
Job.create({ name: 'Job 3' }, function(err, p) {
|
Job.create({ name: 'Job 3' }, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
job3 = p;
|
job3 = p;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -4522,11 +4525,13 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should associate items on scope', function(done) {
|
it('should associate items on scope', function(done) {
|
||||||
Category.create({ name: 'Category A' }, function(err, cat) {
|
Category.create({ name: 'Category A' }, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
var link = cat.items.build();
|
var link = cat.items.build();
|
||||||
link.job(job1);
|
link.job(job1);
|
||||||
var link = cat.items.build();
|
var link = cat.items.build();
|
||||||
link.job(job2);
|
link.job(job2);
|
||||||
cat.save(function(err, cat) {
|
cat.save(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
var job = cat.items.at(0);
|
var job = cat.items.at(0);
|
||||||
job.should.be.instanceof(Link);
|
job.should.be.instanceof(Link);
|
||||||
job.should.not.have.property('jobId');
|
job.should.not.have.property('jobId');
|
||||||
|
@ -4542,6 +4547,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should include related items on scope', function(done) {
|
it('should include related items on scope', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(2);
|
cat.links.should.have.length(2);
|
||||||
|
|
||||||
// denormalized properties:
|
// denormalized properties:
|
||||||
|
@ -4556,6 +4562,7 @@ describe('relations', function() {
|
||||||
should.not.exist(cat.items.at(1).job());
|
should.not.exist(cat.items.at(1).job());
|
||||||
|
|
||||||
cat.items(function(err, items) {
|
cat.items(function(err, items) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.items.at(0).job().should.be.instanceof(Job);
|
cat.items.at(0).job().should.be.instanceof(Job);
|
||||||
cat.items.at(1).job().should.be.instanceof(Job);
|
cat.items.at(1).job().should.be.instanceof(Job);
|
||||||
cat.items.at(1).job().name.should.equal('Job 2');
|
cat.items.at(1).job().name.should.equal('Job 2');
|
||||||
|
@ -4566,8 +4573,10 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should remove embedded items by id', function(done) {
|
it('should remove embedded items by id', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(2);
|
cat.links.should.have.length(2);
|
||||||
cat.items.destroy(job1.id, function(err) {
|
cat.items.destroy(job1.id, function(err) {
|
||||||
|
if (err) return done(err);
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
cat.links.should.have.length(1);
|
cat.links.should.have.length(1);
|
||||||
done();
|
done();
|
||||||
|
@ -4577,6 +4586,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should find items on scope', function(done) {
|
it('should find items on scope', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(1);
|
cat.links.should.have.length(1);
|
||||||
cat.items.at(0).id.should.eql(job2.id);
|
cat.items.at(0).id.should.eql(job2.id);
|
||||||
cat.items.at(0).name.should.equal(job2.name);
|
cat.items.at(0).name.should.equal(job2.name);
|
||||||
|
@ -4585,6 +4595,7 @@ describe('relations', function() {
|
||||||
should.not.exist(cat.items.at(0).job());
|
should.not.exist(cat.items.at(0).job());
|
||||||
|
|
||||||
cat.items(function(err, items) {
|
cat.items(function(err, items) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.items.at(0).job().should.be.instanceof(Job);
|
cat.items.at(0).job().should.be.instanceof(Job);
|
||||||
cat.items.at(0).job().name.should.equal('Job 2');
|
cat.items.at(0).job().name.should.equal('Job 2');
|
||||||
done();
|
done();
|
||||||
|
@ -4594,8 +4605,10 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should add related items to scope', function(done) {
|
it('should add related items to scope', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(1);
|
cat.links.should.have.length(1);
|
||||||
cat.items.add(job3, function(err, link) {
|
cat.items.add(job3, function(err, link) {
|
||||||
|
if (err) return done(err);
|
||||||
link.should.be.instanceof(Link);
|
link.should.be.instanceof(Link);
|
||||||
link.id.should.eql(job3.id);
|
link.id.should.eql(job3.id);
|
||||||
link.name.should.equal('Job 3');
|
link.name.should.equal('Job 3');
|
||||||
|
@ -4608,6 +4621,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should find items on scope', function(done) {
|
it('should find items on scope', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(2);
|
cat.links.should.have.length(2);
|
||||||
|
|
||||||
cat.items.at(0).should.be.instanceof(Link);
|
cat.items.at(0).should.be.instanceof(Link);
|
||||||
|
@ -4622,8 +4636,10 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should remove embedded items by reference id', function(done) {
|
it('should remove embedded items by reference id', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(2);
|
cat.links.should.have.length(2);
|
||||||
cat.items.remove(job2.id, function(err) {
|
cat.items.remove(job2.id, function(err) {
|
||||||
|
if (err) return done(err);
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
cat.links.should.have.length(1);
|
cat.links.should.have.length(1);
|
||||||
done();
|
done();
|
||||||
|
@ -4633,6 +4649,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should have removed embedded items by reference id', function(done) {
|
it('should have removed embedded items by reference id', function(done) {
|
||||||
Category.findOne(function(err, cat) {
|
Category.findOne(function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.have.length(1);
|
cat.links.should.have.length(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -4642,9 +4659,11 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should create items on scope', function(done) {
|
it('should create items on scope', function(done) {
|
||||||
Category.create({ name: 'Category B' }, function(err, cat) {
|
Category.create({ name: 'Category B' }, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
category = cat;
|
category = cat;
|
||||||
var link = cat.items.build({ notes: 'Some notes...' });
|
var link = cat.items.build({ notes: 'Some notes...' });
|
||||||
link.job.create({ name: 'Job 1' }, function(err, p) {
|
link.job.create({ name: 'Job 1' }, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
jobId = p.id;
|
jobId = p.id;
|
||||||
cat.links[0].id.should.eql(p.id);
|
cat.links[0].id.should.eql(p.id);
|
||||||
cat.links[0].name.should.equal('Job 1'); // denormalized
|
cat.links[0].name.should.equal('Job 1'); // denormalized
|
||||||
|
@ -4657,12 +4676,14 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should find items on scope', function(done) {
|
it('should find items on scope', function(done) {
|
||||||
Category.findById(category.id, function(err, cat) {
|
Category.findById(category.id, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.name.should.equal('Category B');
|
cat.name.should.equal('Category B');
|
||||||
cat.links.toObject().should.eql([
|
cat.links.toObject().should.eql([
|
||||||
{ id: jobId, name: 'Job 1', notes: 'Some notes...' },
|
{ id: jobId, name: 'Job 1', notes: 'Some notes...' },
|
||||||
]);
|
]);
|
||||||
cat.items.at(0).should.equal(cat.links[0]);
|
cat.items.at(0).should.equal(cat.links[0]);
|
||||||
cat.items(function(err, items) { // alternative access
|
cat.items(function(err, items) { // alternative access
|
||||||
|
if (err) return done(err);
|
||||||
items.should.be.an.array;
|
items.should.be.an.array;
|
||||||
items.should.have.length(1);
|
items.should.have.length(1);
|
||||||
items[0].job(function(err, p) {
|
items[0].job(function(err, p) {
|
||||||
|
@ -4675,8 +4696,10 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should update items on scope - and save parent', function(done) {
|
it('should update items on scope - and save parent', function(done) {
|
||||||
Category.findById(category.id, function(err, cat) {
|
Category.findById(category.id, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
var link = cat.items.at(0);
|
var link = cat.items.at(0);
|
||||||
link.updateAttributes({ notes: 'Updated notes...' }, function(err, link) {
|
link.updateAttributes({ notes: 'Updated notes...' }, function(err, link) {
|
||||||
|
if (err) return done(err);
|
||||||
link.notes.should.equal('Updated notes...');
|
link.notes.should.equal('Updated notes...');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -4685,6 +4708,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should find items on scope - verify update', function(done) {
|
it('should find items on scope - verify update', function(done) {
|
||||||
Category.findById(category.id, function(err, cat) {
|
Category.findById(category.id, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.name.should.equal('Category B');
|
cat.name.should.equal('Category B');
|
||||||
cat.links.toObject().should.eql([
|
cat.links.toObject().should.eql([
|
||||||
{ id: jobId, name: 'Job 1', notes: 'Updated notes...' },
|
{ id: jobId, name: 'Job 1', notes: 'Updated notes...' },
|
||||||
|
@ -4695,7 +4719,9 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should remove items from scope - and save parent', function(done) {
|
it('should remove items from scope - and save parent', function(done) {
|
||||||
Category.findById(category.id, function(err, cat) {
|
Category.findById(category.id, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.items.at(0).destroy(function(err, link) {
|
cat.items.at(0).destroy(function(err, link) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.links.should.eql([]);
|
cat.links.should.eql([]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -4704,6 +4730,7 @@ describe('relations', function() {
|
||||||
|
|
||||||
it('should find items on scope - verify destroy', function(done) {
|
it('should find items on scope - verify destroy', function(done) {
|
||||||
Category.findById(category.id, function(err, cat) {
|
Category.findById(category.id, function(err, cat) {
|
||||||
|
if (err) return done(err);
|
||||||
cat.name.should.equal('Category B');
|
cat.name.should.equal('Category B');
|
||||||
cat.links.should.eql([]);
|
cat.links.should.eql([]);
|
||||||
done();
|
done();
|
||||||
|
|
Loading…
Reference in New Issue