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

Bring test suite up to date + more url normalization #8

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXPRESSO = support/expresso/bin/expresso -I lib
EXPRESSO = support/expresso/bin/expresso -I lib --serial

TESTS = tests/*.test.js

Expand Down
4 changes: 2 additions & 2 deletions lib/types/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.normalizeUrl = (function () {
};

return function (uri) {
var parsedUrl = Url.parse(uri, true)
var parsedUrl = Url.parse(uri)
, urlstr = ""
, protocol = parsedUrl.protocol
, hostname = parsedUrl.hostname
Expand All @@ -50,7 +50,7 @@ module.exports.normalizeUrl = (function () {
"/" // Add trailing /
);
if (query) {
urlstr += "?" + reorderQuery(query);
urlstr += "?" + reorderQuery(Url.parse(uri, true).query);
}
if (hash) {
urlstr += hash;
Expand Down
6 changes: 3 additions & 3 deletions tests/email.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('should');
var should = require('should');
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests');
Expand All @@ -20,14 +20,14 @@ module.exports = {
'test invalid email validation': function () {
var user = new User({email: 'hello'});
user.save(function (err) {
err.message.should.equal('Validator "email is invalid" failed for path email');
err.errors.email.message.should.equal('Validator "email is invalid" failed for path email');
user.isNew.should.be.true;
});
},
'test valid email validation': function () {
var user = new User({ email: '[email protected]' });
user.save(function (err) {
err.should.eql(null);
should.not.exist(err);
user.isNew.should.be.false;
});
},
Expand Down
15 changes: 12 additions & 3 deletions tests/url.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('should');
var should = require('should');
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests');
Expand All @@ -20,14 +20,14 @@ module.exports = {
'test invalid url validation': function () {
var webpage = new Webpage({url: 'file:///home/'});
webpage.save(function (err) {
err.message.should.equal('Validator "url is invalid" failed for path url');
err.errors.url.message.should.equal('Validator "url is invalid" failed for path url');
webpage.isNew.should.be.true;
});
},
'test valid url validation': function () {
var webpage = new Webpage({ url: 'http://www.google.com/' });
webpage.save(function (err) {
err.should.eql(null);
should.not.exist(err);
webpage.isNew.should.be.false;
});
},
Expand All @@ -49,6 +49,15 @@ module.exports = {
});
});
},
'url normalization should prevent trailing "?"': function () {
var webpage = new Webpage({ url: 'http://google.com/maps'});
webpage.save(function (err) {
webpage.url.should.equal('http://google.com/maps');
Webpage.findById(webpage._id, function (err, refreshed) {
refreshed.url.should.equal('http://google.com/maps');
});
});
},
teardown: function(){
db.close();
}
Expand Down
33 changes: 16 additions & 17 deletions tests/useTimestamps.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('should');
var should = require('should');
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, db = mongoose.createConnection('mongodb://localhost/mongoose_types_tests')
Expand All @@ -14,30 +14,29 @@ mongoose.model('TimeCop', TimeCopSchema);
var TimeCop;

module.exports = {
before: function(done){
before: function(){
TimeCop = db.model('TimeCop', TimeCopSchema);
TimeCop.remove({}, function () {
done();
});
TimeCop.remove({}, function () {});
},
'createdAt and updatedAt should be set to the same value on creation': function (done) {
'createdAt and updatedAt should be set to the same value on creation': function () {
var cop = new TimeCop({ email: '[email protected]' });
cop.save( function (err) {
cop.createdAt.should.be.an.instanceof(Date);
cop.updatedAt.should.be.an.instanceof(Date);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably check for equality between createdAt and updatedAt.

done();
});
},
'updatedAt should be later than createdAt upon updating': function (done) {
TimeCop.findOne({email: '[email protected]'}, function (err, found) {
found.email = '[email protected]';
setTimeout( function () {
found.save( function (err, updated) {
updated.updatedAt.should.be.greater.than(updated.createdAt);
assert.ok(updated.updatedAt > updated.createdAt);
done();
});
}, 1000);
'updatedAt should be later than createdAt upon updating': function () {
var cop = new TimeCop({ email: '[email protected]' });
cop.save( function (err) {
should.not.exist(err);
TimeCop.findOne({email: '[email protected]'}, function (err, found) {
found.email = '[email protected]';
setTimeout( function () {
found.save( function (err, updated) {
updated.updatedAt.should.be.above(updated.createdAt);
});
}, 500);
});
});
},
teardown: function(){
Expand Down