Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jledentu committed Oct 7, 2017
1 parent c7ff056 commit df6bd7a
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions test/unit/models/Post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ describe('PostModel', function() {
})
.then(function(post) {
post.should.have.property('title');
post.title.should.be.a.String();
post.title.should.be.eql('This is a new post!!!');
post.title.should.eql('This is a new post!!!');

post.should.have.property('author');
post.author.should.be.a.String();
post.author.should.be.eql('Jérémie Ledentu');
post.author.should.eql('Jérémie Ledentu');

post.should.have.property('slug');
post.slug.should.be.a.String();
post.slug.should.be.eql('this-is-a-new-post');
post.slug.should.eql('this-is-a-new-post');

post.should.have.property('slugAuthor');
post.slugAuthor.should.be.a.String();
post.slugAuthor.should.be.eql('jeremie-ledentu');
post.slugAuthor.should.eql('jeremie-ledentu');
done();
})
.catch(done);
Expand All @@ -38,19 +34,15 @@ describe('PostModel', function() {
})
.then(function(post) {
post.should.have.property('title');
post.title.should.be.a.String();
post.title.should.be.eql('This is a new post!!');
post.title.should.eql('This is a new post!!');

post.should.have.property('author');
post.author.should.be.a.String();
post.author.should.be.eql('Jérémie Ledentu');
post.author.should.eql('Jérémie Ledentu');

post.should.have.property('slug');
post.slug.should.be.a.String();
post.slug.should.match(/^this-is-a-new-post-/);

post.should.have.property('slugAuthor');
post.slugAuthor.should.be.a.String();
post.slugAuthor.should.match(/^jeremie-ledentu-/);
done();
})
Expand All @@ -65,11 +57,9 @@ describe('PostModel', function() {
})
.then((post) => {
post.should.have.property('slug');
post.slug.should.be.a.String();
post.slug.should.match(/^new-/);

post.should.have.property('author');
post.author.should.be.a.String();
post.slugAuthor.should.match(/^jeremie-ledentu-/);

done();
Expand All @@ -88,6 +78,26 @@ describe('PostModel', function() {
done();
});
});

it('should not use lowercase if lowercase === false in the config', done => {
sails.config.slugs.lowercase = false;

Post.create({
title: 'THIS IS A TITLE IN UPPERCASE',
content: 'Post content',
author: 'Jérémie Ledentu'
})
.then(post => {
post.should.have.property('slug');
post.slug.should.eql('THIS-IS-A-TITLE-IN-UPPERCASE');
post.slugAuthor.should.match(/^Jeremie-Ledentu-/);

sails.config.slugs.lowercase = true;

done();
})
.catch(done);
});
});

describe('#findOneBySlug()', function() {
Expand All @@ -101,10 +111,8 @@ describe('PostModel', function() {
Post.findOneBySlug('this-is-a-new-post')
.then(function(post) {
post.should.have.property('title');
post.title.should.be.a.String();
post.title.should.be.eql('This is a new post!!!');
post.slug.should.be.a.String();
post.slug.should.be.eql('this-is-a-new-post');
post.title.should.eql('This is a new post!!!');
post.slug.should.eql('this-is-a-new-post');
done();
})
.catch(done);
Expand Down

0 comments on commit df6bd7a

Please sign in to comment.