Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #121 from Financial-Times/content-classification
Browse files Browse the repository at this point in the history
Content classification
  • Loading branch information
aintgoin2goa committed Feb 26, 2015
2 parents 98ef3d4 + 87a2b3d commit c32fe85
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,33 @@ Object.defineProperty(Article.prototype, 'isWeekend', {
}
});

Object.defineProperty(Article.prototype, 'contentClassification', {
get : function(){
if(this._contentClassification){
return this._contentClassification;
}

var results = /cms\/s\/([0-3])\//i.exec(this.raw.item.location.uri);
var classification = 'unconditional';
if(results.length > 1){
switch(results[1]){
case '0' :
case '1' :
classification = 'conditional_standard';
break;
case '2' :
classification = 'unconditional';
break;
case '3' :
classification = 'conditional_premium';
}
}

this._contentClassification = classification;
return classification;
}
});



module.exports = Article;
25 changes: 24 additions & 1 deletion test/models/articleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ describe('Article model', function(){
article3: JSON.parse(fs.readFileSync('test/fixtures/b9d1b2ca-5dfe-11e4-bc04-00144feabdc0', { encoding: 'utf8' })),
article4: JSON.parse(fs.readFileSync('test/fixtures/a60413c2-7c46-11e3-9179-00144feabdc0', { encoding: 'utf8' })),
article5: JSON.parse(fs.readFileSync('test/fixtures/07de76b4-5e05-11e4-bc04-00144feabdc0', { encoding: 'utf8' })),
weekendArticle : JSON.parse(fs.readFileSync('test/fixtures/7803a998-7aeb-11e4-8646-00144feabdc0(weekend)', { encoding: 'utf8' }))
weekendArticle : JSON.parse(fs.readFileSync('test/fixtures/7803a998-7aeb-11e4-8646-00144feabdc0(weekend)', { encoding: 'utf8' })),
premiumArticle : JSON.parse(fs.readFileSync('test/fixtures/03b49444-16c9-11e3-bced-00144feabdc0', { encoding: 'utf8' })),
unconditionalArticle : JSON.parse(fs.readFileSync('test/fixtures/03b49444-16c9-11e3-bced-00144feabdc0', { encoding: 'utf8' }))
};

fixtures.article2.item.location.uri = fixtures.article2.item.location.uri.replace('/0/', '/1/');
fixtures.premiumArticle.item.location.uri = fixtures.premiumArticle.item.location.uri.replace('/0/', '/3/');
fixtures.unconditionalArticle.item.location.uri = fixtures.unconditionalArticle.item.location.uri.replace('/0/', '/2/');


describe('publicly exposed', function () {
var client = require('../../api');
expect(client.models.v1.Article).to.equal(Article);
Expand Down Expand Up @@ -286,4 +293,20 @@ describe('Article model', function(){

});

describe('Access', function(){

it('Should be able to ge the content classification level for an article', function(){
var article1 = new Article(fixtures.article);
var article2 = new Article(fixtures.article2);
var article3 = new Article(fixtures.premiumArticle);
var article4 = new Article(fixtures.unconditionalArticle);

expect(article1.contentClassification).to.equal('conditional_standard');
expect(article2.contentClassification).to.equal('conditional_standard');
expect(article3.contentClassification).to.equal('conditional_premium');
expect(article4.contentClassification).to.equal('unconditional');
});

});

});

0 comments on commit c32fe85

Please sign in to comment.