From af5d8be8aab6ad6030bc55799e07dac5697805cc Mon Sep 17 00:00:00 2001 From: Dan Wilkerson Date: Thu, 22 Feb 2018 16:29:51 -0500 Subject: [PATCH] Adjusted destroy tests for consistency --- interfaces/semantic/destroy.js | 89 +++++++++++++--------------------- package.json | 5 +- 2 files changed, 39 insertions(+), 55 deletions(-) diff --git a/interfaces/semantic/destroy.js b/interfaces/semantic/destroy.js index e01984e..fc4c9af 100644 --- a/interfaces/semantic/destroy.js +++ b/interfaces/semantic/destroy.js @@ -4,23 +4,27 @@ var _ = require('@sailshq/lodash'); describe('Semantic Interface', function() { describe('.destroy()', function() { describe('a single record', function() { - before(function(done) { - Semantic.User.create({ first_name: 'Destroy', last_name: 'Test' }, function(err) { - if (err) { - return done(err); - } - - return done(); - }); + + var user; + + beforeEach(function(done) { + Semantic.User.create({ first_name: 'Destroy', last_name: 'Test' }, function(err, record) { + if (err) { + return done(err); + } + + user = record; + return done(); + }); }); - it('should destroy a record', function(done) { - Semantic.User.destroy({ first_name: 'Destroy' }, function(err, report) { + it('should destroy a record by first_name', function(done) { + Semantic.User.destroy({ first_name: user.first_name }, function(err, report) { if (err) { return done(err); } - Semantic.User.find({ first_name: 'Destroy' }, function(err, users) { + Semantic.User.find({ first_name: user.first_name }, function(err, users) { if (err) { return done(err); } @@ -31,43 +35,22 @@ describe('Semantic Interface', function() { }); }); }); - }); - - describe('with numeric ID', function() { - var user; - // Create a user to test destroy on - before(function(done) { - Semantic.User.create({ first_name: 'Destroy', last_name: 'Test' }, function(err, record) { + it('should destroy a record by id', function(done) { + Semantic.User.destroy({ id: user.id }, function(err, status) { if (err) { return done(err); } - user = record; - - return done(); - }); - }); + Semantic.User.find({ id: user.id }, function(err, users) { + if (err) { + return done(err); + } - it('should destroy a record', function(done) { - Semantic.User.destroy(user.id, function(err, status) { - if (err) { - return done(err); - } - - return done(); - }); - }); - - it('should return an empty array when searched for', function(done) { - Semantic.User.find({ first_name: 'Destroy' }, function(err, users) { - if (err) { - return done(err); - } - - assert.strictEqual(users.length, 0); - - return done(); + assert.strictEqual(users.length, 0); + + return done(); + }); }); }); }); @@ -82,26 +65,24 @@ describe('Semantic Interface', function() { }); it('should destroy all the records', function(done) { - Semantic.User.destroy({}, function(err, users) { + Semantic.User.destroy({ first_name: 'dummy_test' }, function(err, users) { if (err) { return done(err); } - - return done(); - }); - }); - it('should return an empty array when searched for', function(done) { - Semantic.User.find({ first_name: 'Destroy' }, function(err, users) { - if (err) { - return done(err); - } + Semantic.User.find({ first_name: 'dummy_test' }, function(err, users) { - assert.strictEqual(users.length, 0); + if(err) { + return done(err); + } + + assert.strictEqual(users.length, 0); - return done(); + return done(); + }); }); }); + }); }); }); diff --git a/package.json b/package.json index 664d06a..ef86712 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,11 @@ { "name": "waterline-adapter-tests", "description": "Integration tests for waterline adapters", - "version": "1.0.0-13", + "version": "1.0.0-14", "author": "Cody Stoltman ", + "contributors": [ + "Dan Wilkerson " + ], "dependencies": { "@sailshq/lodash": "3.10.2", "async": "2.0.1",