Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Created March 25, 2014 21:29
Show Gist options
  • Select an option

  • Save heymichaelp/9771799 to your computer and use it in GitHub Desktop.

Select an option

Save heymichaelp/9771799 to your computer and use it in GitHub Desktop.
var moment = require('moment');
var Review = function( review ) {
this.review = review;
}
Review.prototype.authorFullName = function() {
return [ this.review.author.firstName, this.review.author.lastName ].join(' ');
}
Review.prototype.asteriskRating = function() {
return '*****'.substr( 0, this.review.rating );
}
Review.prototype.ratedOn = function() {
return moment( this.review.ratedOn ).format('L');
}
Review.prototype.data = function() {
return {
authorFullName: this.authorFullName(),
asteriskRating: this.asteriskRating(),
ratedOn: this.ratedOn()
}
}
module.exports = Review;
var Review = require('../examples/05_view');
var expect = require('chai').expect;
var review;
describe('Review', function() {
beforeEach( function() {
data = {
author: {
firstName: 'John',
lastName: 'Smith'
},
rating: 3,
status: 'active',
ratedOn: new Date('2/8/2013')
}
review = new Review( data ).data();
})
it('has the formatted authorFullName', function() {
expect( review.authorFullName ).to.equal('John Smith');
})
it('has the formatted asteriskRating', function() {
expect( review.asteriskRating ).to.equal('***');
})
it('has the formatted ratedOn', function() {
expect( review.ratedOn ).to.equal('02/08/2013');
})
it('only exposes view object properties', function() {
expect( review ).to.not.have.property('status');
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment