From 93aefc36f50d20d77260ee3f89a2890d021595e5 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Sat, 21 Mar 2015 16:23:25 +0100 Subject: [PATCH] Test embedsOne CRUD methods --- test/relations.integration.js | 51 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/test/relations.integration.js b/test/relations.integration.js index 35017d44..59530b99 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -636,8 +636,7 @@ describe('relations - integration', function() { function(err, group) { if (err) return done(err); test.group = group; - group.cover.build({ url: 'http://image.url' }); - group.save(done); + done(); }); }); @@ -645,6 +644,19 @@ describe('relations - integration', function() { this.app.models.group.destroyAll(done); }); + it('creates an embedded model', function(done) { + var url = '/api/groups/' + this.group.id + '/cover'; + + this.post(url) + .send({ url: 'http://image.url' }) + .expect(200, function(err, res) { + expect(res.body).to.be.eql( + { url: 'http://image.url' } + ); + done(); + }); + }); + it('includes the embedded models', function(done) { var url = '/api/groups/' + this.group.id; @@ -670,6 +682,41 @@ describe('relations - integration', function() { }); }); + it('updates an embedded model', function(done) { + var url = '/api/groups/' + this.group.id + '/cover'; + + this.put(url) + .send({ url: 'http://changed.url' }) + .expect(200, function(err, res) { + expect(res.body.url).to.be.equal('http://changed.url'); + done(); + }); + }); + + it('returns the updated embedded model', function(done) { + var url = '/api/groups/' + this.group.id + '/cover'; + + this.get(url) + .expect(200, function(err, res) { + expect(res.body).to.be.eql( + { url: 'http://changed.url' } + ); + done(); + }); + }); + + it('deletes an embedded model', function(done) { + var url = '/api/groups/' + this.group.id + '/cover'; + + this.del(url).expect(204, done); + }); + + it('deleted the embedded model', function(done) { + var url = '/api/groups/' + this.group.id + '/cover'; + + this.get(url).expect(404, done); + }); + }); describe('embedsMany', function() {