|
|
|
@ -11,6 +11,12 @@ var debug = require('debug')('loopback:test:relations.integration');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
|
|
|
|
|
describe('relations - integration', function() {
|
|
|
|
|
before(function(done) {
|
|
|
|
|
if (app.booting) {
|
|
|
|
|
return app.once('booted', done);
|
|
|
|
|
}
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lt.beforeEach.withApp(app);
|
|
|
|
|
|
|
|
|
@ -91,6 +97,7 @@ describe('relations - integration', function() {
|
|
|
|
|
this.get(url)
|
|
|
|
|
.query({'filter': {'include' : 'pictures'}})
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
// console.log(res.body);
|
|
|
|
|
expect(res.body.name).to.be.equal('Reader 1');
|
|
|
|
|
expect(res.body.pictures).to.be.eql([
|
|
|
|
@ -106,6 +113,7 @@ describe('relations - integration', function() {
|
|
|
|
|
this.get(url)
|
|
|
|
|
.query({'filter': {'include' : 'imageable'}})
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
// console.log(res.body);
|
|
|
|
|
expect(res.body[0].name).to.be.equal('Picture 1');
|
|
|
|
|
expect(res.body[1].name).to.be.equal('Picture 2');
|
|
|
|
@ -119,6 +127,7 @@ describe('relations - integration', function() {
|
|
|
|
|
this.get(url)
|
|
|
|
|
.query({'filter': {'include' : {'relation': 'imageable', 'scope': { 'include' : 'team'}}}})
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body[0].name).to.be.equal('Picture 1');
|
|
|
|
|
expect(res.body[1].name).to.be.equal('Picture 2');
|
|
|
|
|
expect(res.body[0].imageable.name).to.be.eql('Reader 1');
|
|
|
|
@ -133,6 +142,7 @@ describe('relations - integration', function() {
|
|
|
|
|
it('should invoke scoped methods remotely', function(done) {
|
|
|
|
|
this.get('/api/stores/superStores')
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.array;
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
@ -369,7 +379,7 @@ describe('relations - integration', function() {
|
|
|
|
|
self.url = root.relUrl;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -408,7 +418,7 @@ describe('relations - integration', function() {
|
|
|
|
|
self.url = root.relUrl;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -453,7 +463,7 @@ describe('relations - integration', function() {
|
|
|
|
|
self.url = root.relUrl;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -473,7 +483,7 @@ describe('relations - integration', function() {
|
|
|
|
|
'/patients/rel/' + '999';
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -492,7 +502,7 @@ describe('relations - integration', function() {
|
|
|
|
|
self.url = root.relUrl;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -547,7 +557,7 @@ describe('relations - integration', function() {
|
|
|
|
|
'/patients/' + root.patient.id;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -568,7 +578,7 @@ describe('relations - integration', function() {
|
|
|
|
|
'/patients/' + root.patient.id;
|
|
|
|
|
self.patient = root.patient;
|
|
|
|
|
self.physician = root.physician;
|
|
|
|
|
done();
|
|
|
|
|
done(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -684,6 +694,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.have.property('products');
|
|
|
|
|
expect(res.body.products).to.eql([
|
|
|
|
|
{
|
|
|
|
@ -703,6 +714,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.have.property('products');
|
|
|
|
|
expect(res.body.products).to.eql([
|
|
|
|
|
{
|
|
|
|
@ -764,6 +776,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.name).to.be.equal('Group 1');
|
|
|
|
|
expect(res.body.poster).to.be.eql(
|
|
|
|
|
{ url: 'http://image.url' }
|
|
|
|
@ -777,6 +790,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql(
|
|
|
|
|
{ url: 'http://image.url' }
|
|
|
|
|
);
|
|
|
|
@ -800,6 +814,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql(
|
|
|
|
|
{ url: 'http://changed.url' }
|
|
|
|
|
);
|
|
|
|
@ -857,6 +872,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.name).to.be.equal('List A');
|
|
|
|
|
expect(res.body.todoItems).to.be.eql([
|
|
|
|
|
{ content: 'Todo 1', id: 1 },
|
|
|
|
@ -871,6 +887,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ content: 'Todo 1', id: 1 },
|
|
|
|
|
{ content: 'Todo 2', id: 2 }
|
|
|
|
@ -885,6 +902,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ content: 'Todo 2', id: 2 }
|
|
|
|
|
]);
|
|
|
|
@ -910,6 +928,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ content: 'Todo 1', id: 1 },
|
|
|
|
|
{ content: 'Todo 2', id: 2 },
|
|
|
|
@ -924,6 +943,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql(
|
|
|
|
|
{ content: 'Todo 3', id: 3 }
|
|
|
|
|
);
|
|
|
|
@ -946,6 +966,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ content: 'Todo 1', id: 1 },
|
|
|
|
|
{ content: 'Todo 3', id: 3 }
|
|
|
|
@ -957,6 +978,7 @@ describe('relations - integration', function() {
|
|
|
|
|
it('returns a 404 response when embedded model is not found', function(done) {
|
|
|
|
|
var url = '/api/todo-lists/' + this.todoList.id + '/items/2';
|
|
|
|
|
this.get(url).expect(404, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.error.status).to.be.equal(404);
|
|
|
|
|
expect(res.body.error.message).to.be.equal('Unknown "todoItem" id "2".');
|
|
|
|
|
expect(res.body.error.code).to.be.equal('MODEL_NOT_FOUND');
|
|
|
|
@ -1044,6 +1066,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.ingredientIds).to.eql([test.ingredient1]);
|
|
|
|
|
expect(res.body).to.not.have.property('ingredients');
|
|
|
|
|
done();
|
|
|
|
@ -1069,6 +1092,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 },
|
|
|
|
|
{ name: 'Sugar', id: test.ingredient2 },
|
|
|
|
@ -1084,6 +1108,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 },
|
|
|
|
|
{ name: 'Butter', id: test.ingredient3 }
|
|
|
|
@ -1099,6 +1124,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Butter', id: test.ingredient3 }
|
|
|
|
|
]);
|
|
|
|
@ -1113,6 +1139,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.ingredientIds).to.eql([
|
|
|
|
|
test.ingredient1, test.ingredient3
|
|
|
|
|
]);
|
|
|
|
@ -1131,6 +1158,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql(
|
|
|
|
|
{ name: 'Butter', id: test.ingredient3 }
|
|
|
|
|
);
|
|
|
|
@ -1146,6 +1174,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.ingredientIds).to.eql(expected);
|
|
|
|
|
expect(res.body).to.not.have.property('ingredients');
|
|
|
|
|
done();
|
|
|
|
@ -1169,6 +1198,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 },
|
|
|
|
|
{ name: 'Sugar', id: test.ingredient2 }
|
|
|
|
@ -1183,6 +1213,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 }
|
|
|
|
|
]);
|
|
|
|
@ -1210,6 +1241,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 },
|
|
|
|
|
{ name: 'Sugar', id: test.ingredient2 }
|
|
|
|
@ -1235,6 +1267,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Sugar', id: test.ingredient2 }
|
|
|
|
|
]);
|
|
|
|
@ -1248,6 +1281,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.eql([
|
|
|
|
|
{ name: 'Chocolate', id: test.ingredient1 },
|
|
|
|
|
{ name: 'Sugar', id: test.ingredient2 }
|
|
|
|
@ -1261,6 +1295,7 @@ describe('relations - integration', function() {
|
|
|
|
|
|
|
|
|
|
this.get(url)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
|
expect(res.body.name).to.equal('Photo 1');
|
|
|
|
|
done();
|
|
|
|
@ -1395,6 +1430,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/' + test.book.id + '/pages')
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.an.array;
|
|
|
|
|
expect(res.body).to.have.length(1);
|
|
|
|
|
expect(res.body[0].name).to.equal('Page 1');
|
|
|
|
@ -1406,6 +1442,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/pages/' + test.page.id + '/notes/' + test.note.id)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.headers['x-before']).to.equal('before');
|
|
|
|
|
expect(res.headers['x-after']).to.equal('after');
|
|
|
|
|
expect(res.body).to.be.an.object;
|
|
|
|
@ -1418,6 +1455,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/unknown/pages/' + test.page.id + '/notes')
|
|
|
|
|
.expect(404, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body.error).to.be.an.object;
|
|
|
|
|
var expected = 'could not find a model with id unknown';
|
|
|
|
|
expect(res.body.error.message).to.equal(expected);
|
|
|
|
@ -1430,6 +1468,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/images/' + test.image.id + '/book/pages')
|
|
|
|
|
.end(function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.an.array;
|
|
|
|
|
expect(res.body).to.have.length(1);
|
|
|
|
|
expect(res.body[0].name).to.equal('Page 1');
|
|
|
|
@ -1441,6 +1480,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/images/' + test.image.id + '/book/pages/' + test.page.id)
|
|
|
|
|
.end(function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.an.object;
|
|
|
|
|
expect(res.body.name).to.equal('Page 1');
|
|
|
|
|
done();
|
|
|
|
@ -1451,6 +1491,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/' + test.book.id + '/pages/' + test.page.id + '/notes')
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.an.array;
|
|
|
|
|
expect(res.body).to.have.length(1);
|
|
|
|
|
expect(res.body[0].text).to.equal('Page Note 1');
|
|
|
|
@ -1462,6 +1503,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/' + test.book.id + '/pages/' + test.page.id + '/notes/' + test.note.id)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.headers['x-before']).to.equal('before');
|
|
|
|
|
expect(res.headers['x-after']).to.equal('after');
|
|
|
|
|
expect(res.body).to.be.an.object;
|
|
|
|
@ -1474,6 +1516,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/' + test.book.id + '/chapters/' + test.chapter.id + '/notes/' + test.cnote.id)
|
|
|
|
|
.expect(200, function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.headers['x-before']).to.empty;
|
|
|
|
|
expect(res.headers['x-after']).to.empty;
|
|
|
|
|
done();
|
|
|
|
@ -1497,6 +1540,7 @@ describe('relations - integration', function() {
|
|
|
|
|
var test = this;
|
|
|
|
|
this.get('/api/books/' + test.book.id + '/pages/' + this.page.id + '/throws')
|
|
|
|
|
.end(function(err, res) {
|
|
|
|
|
if (err) return done(err);
|
|
|
|
|
expect(res.body).to.be.an('object');
|
|
|
|
|
expect(res.body.error).to.be.an('object');
|
|
|
|
|
expect(res.body.error.name).to.equal('Error');
|
|
|
|
|