Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted destroy tests for consistency #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 35 additions & 54 deletions interfaces/semantic/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
});
});
});
});
Expand All @@ -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();
});
});
});

});
});
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
"Dan Wilkerson <[email protected]>"
],
"dependencies": {
"@sailshq/lodash": "3.10.2",
"async": "2.0.1",
Expand Down