Fix the test case
This commit is contained in:
parent
b627220059
commit
b5f702afd3
|
@ -27,11 +27,11 @@ describe('relations - integration', function() {
|
||||||
this.app.models.widget.destroyAll(done);
|
this.app.models.widget.destroyAll(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.only('polymorphicHasMany', function() {
|
describe('polymorphicHasMany', function() {
|
||||||
|
|
||||||
before(function defineProductAndCategoryModels() {
|
before(function defineProductAndCategoryModels() {
|
||||||
var Group = app.model(
|
var Team = app.model(
|
||||||
'Group',
|
'Team',
|
||||||
{ properties: { name: 'string' },
|
{ properties: { name: 'string' },
|
||||||
dataSource: 'db'
|
dataSource: 'db'
|
||||||
}
|
}
|
||||||
|
@ -60,22 +60,22 @@ describe('relations - integration', function() {
|
||||||
discriminator: 'imageableType'
|
discriminator: 'imageableType'
|
||||||
} });
|
} });
|
||||||
|
|
||||||
Reader.belongsTo(Group);
|
Reader.belongsTo(Team);
|
||||||
});
|
});
|
||||||
|
|
||||||
before(function createEvent(done) {
|
before(function createEvent(done) {
|
||||||
var test = this;
|
var test = this;
|
||||||
app.models.Group.create({ name: 'Group 1' },
|
app.models.Team.create({ name: 'Team 1' },
|
||||||
function(err, group) {
|
function(err, team) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
test.group = group;
|
test.team = team;
|
||||||
app.models.Reader.create({ name: 'Reader 1' },
|
app.models.Reader.create({ name: 'Reader 1' },
|
||||||
function(err, reader) {
|
function(err, reader) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
test.reader = reader;
|
test.reader = reader;
|
||||||
reader.pictures.create({ name: 'Picture 1' });
|
reader.pictures.create({ name: 'Picture 1' });
|
||||||
reader.pictures.create({ name: 'Picture 2' });
|
reader.pictures.create({ name: 'Picture 2' });
|
||||||
reader.group = test.group;
|
reader.team(test.team);
|
||||||
reader.save(done);
|
reader.save(done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ describe('relations - integration', function() {
|
||||||
// console.log(res.body);
|
// console.log(res.body);
|
||||||
expect(res.body[0].name).to.be.equal('Picture 1');
|
expect(res.body[0].name).to.be.equal('Picture 1');
|
||||||
expect(res.body[1].name).to.be.equal('Picture 2');
|
expect(res.body[1].name).to.be.equal('Picture 2');
|
||||||
expect(res.body[0].imageable).to.be.eql({ name: 'Reader 1', id: 1});
|
expect(res.body[0].imageable).to.be.eql({ name: 'Reader 1', id: 1, teamId: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -117,13 +117,12 @@ describe('relations - integration', function() {
|
||||||
it('includes related models scoped to the related parent model', function(done) {
|
it('includes related models scoped to the related parent model', function(done) {
|
||||||
var url = '/api/pictures';
|
var url = '/api/pictures';
|
||||||
this.get(url)
|
this.get(url)
|
||||||
.query({'filter': {'include' : {'relation': 'imageable', 'scope': { 'include' : 'group'}}}})
|
.query({'filter': {'include' : {'relation': 'imageable', 'scope': { 'include' : 'team'}}}})
|
||||||
.expect(200, function(err, res) {
|
.expect(200, function(err, res) {
|
||||||
console.log(res.body);
|
|
||||||
expect(res.body[0].name).to.be.equal('Picture 1');
|
expect(res.body[0].name).to.be.equal('Picture 1');
|
||||||
expect(res.body[1].name).to.be.equal('Picture 2');
|
expect(res.body[1].name).to.be.equal('Picture 2');
|
||||||
expect(res.body[0].imageable).to.be.eql({ name: 'Reader 1', id: 1});
|
expect(res.body[0].imageable.name).to.be.eql('Reader 1');
|
||||||
expect(res.body[0].imageable.group).to.be.eql({ name: 'Group 1', id: 1});
|
expect(res.body[0].imageable.team).to.be.eql({ name: 'Team 1', id: 1});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue