diff --git a/lib/models/article.js b/lib/models/article.js index f604c2c..abee54c 100644 --- a/lib/models/article.js +++ b/lib/models/article.js @@ -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; diff --git a/test/models/articleSpec.js b/test/models/articleSpec.js index 51a19e4..d364f41 100644 --- a/test/models/articleSpec.js +++ b/test/models/articleSpec.js @@ -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); @@ -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'); + }); + + }); + });