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

Commit

Permalink
Browse files Browse the repository at this point in the history
…ient into perf-n-bugs

* 'master' of https://github.com/Financial-Times/ft-api-client:
  fixed allTags
  Added search string to brand tags
  tidy up
  Add contentClassification property to article model
  • Loading branch information
wheresrhys committed Mar 23, 2015
2 parents 1725576 + 5e1488b commit cf066de
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
33 changes: 31 additions & 2 deletions lib/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Object.defineProperty(Article.prototype, 'genre', {
Object.defineProperty(Article.prototype, 'brand', {
get: function () {
if (this.raw.item.metadata && this.raw.item.metadata.brand && this.raw.item.metadata.brand.length) {
return this.raw.item.metadata.brand[0].term;
return withSearchString(this.raw.item.metadata.brand[0].term);
}
return undefined;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ Object.defineProperty(Article.prototype, 'allTags', {
get: function () {
return _.uniq([this.primaryTheme, this.primarySection]
.concat(this.authors, this.people, this.organisations,
this.packages, this.regions, this.sections,this.topics,
this.regions, this.topics,
this.subjects, this.brand, this.sections)
.filter(function (tag) { return !!tag; }), function (tag) {
return tag.searchString;
Expand Down Expand Up @@ -512,4 +512,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 cf066de

Please sign in to comment.