UNPKG

paradigm-core

Version:
199 lines (168 loc) 7.14 kB
const AppleNewsAPI = require('../../lib/apple-news-api') const simpleArticle = require('../fixtures/simple') const simpleArticleUpdate = require('../fixtures/simple-update') /** @test {apiEndpoints} */ describe('API Endpoints', function() { before(function() { this.client = new AppleNewsAPI({ channelId: process.env.APPLE_NEWS_CHANNEL, apiId: process.env.APPLE_NEWS_KEY, apiSecret: process.env.APPLE_NEWS_SECRET }) }) /** @test {apiEndpoints#createArticle} */ it('should create an article', async function() { this.timeout(30000) const article = await this.client.createArticle( simpleArticle, { 'header.jpg': 'https://upload.wikimedia.org/wikipedia/commons/6/65/Winter_forrest_-_near_Budapest%2C_Hungary.jpg' } ) this.article = article expect(article.createdAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.id).to.not.be.undefined expect(article.type).to.equal('article') expect(article.shareUrl).to.not.be.undefined expect(article.links).to.not.be.undefined expect(article.state).to.equal('PROCESSING') expect(article.accessoryText).to.be.null expect(article.title).to.equal('Simple with Headline under Header Image') expect(article.maturityRating).to.be.null expect(article.warnings).to.deep.equal([]) expect(article.isCandidateToBeFeatured).to.be.false expect(article.isSponsored).to.be.false expect(article.isPreview).to.be.true expect(article.isDevelopingStory).to.be.false expect(article.document.version).to.equal('1.0') expect(article.document.identifier).to.equal('Apple_Demo') expect(article.document.title).to.equal( 'Simple with Headline under Header Image' ) expect(article.document.language).to.equal('en') expect(article.document.layout.columns).to.equal(7) expect(article.document.layout.width).to.equal(1024) expect(article.document.layout.margin).to.equal(70) expect(article.document.layout.gutter).to.equal(40) expect(article.document.subtitle).to.equal( 'Non occidere quae cumque vi ventia' ) expect(article.document.metadata.excerpt).to.equal('Excerpt') expect(article.document.metadata.thumbnailURL).to.equal( 'bundle://header.jpg' ) expect(article.document.components.length).to.equal(10) expect(article.document.documentStyle).to.deep.equal({ backgroundColor: '#f6f6f6' }) expect(article.document.componentLayouts).to.not.be.undefined }) /** @test {apiEndpoints#createArticle} */ it('should read an article', async function() { this.timeout(30000) const article = await this.client.readArticle(this.article.id) expect(article.createdAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.id).to.not.be.undefined expect(article.type).to.equal('article') expect(article.shareUrl).to.not.be.undefined expect(article.links).to.not.be.undefined expect(article.state).to.equal('PROCESSING') expect(article.accessoryText).to.be.null expect(article.title).to.equal('Simple with Headline under Header Image') expect(article.maturityRating).to.be.null expect(article.warnings).to.deep.equal([]) expect(article.isCandidateToBeFeatured).to.be.false expect(article.isSponsored).to.be.false expect(article.isPreview).to.be.true expect(article.isDevelopingStory).to.be.false expect(article.document.version).to.equal('1.0') expect(article.document.identifier).to.equal('Apple_Demo') expect(article.document.title).to.equal( 'Simple with Headline under Header Image' ) expect(article.document.language).to.equal('en') expect(article.document.layout.columns).to.equal(7) expect(article.document.layout.width).to.equal(1024) expect(article.document.layout.margin).to.equal(70) expect(article.document.layout.gutter).to.equal(40) expect(article.document.subtitle).to.equal( 'Non occidere quae cumque vi ventia' ) expect(article.document.metadata.excerpt).to.equal('Excerpt') expect(article.document.metadata.thumbnailURL).to.equal( 'bundle://header.jpg' ) expect(article.document.components.length).to.equal(10) expect(article.document.documentStyle).to.deep.equal({ backgroundColor: '#f6f6f6' }) expect(article.document.componentLayouts).to.not.be.undefined }) /** @test {apiEndpoints#updateArticle} */ it('should update an article', async function() { this.timeout(30000) const article = await this.client.updateArticle( this.article.id, this.article.revision, simpleArticleUpdate, { 'header.jpg': 'https://upload.wikimedia.org/wikipedia/commons/6/65/Winter_forrest_-_near_Budapest%2C_Hungary.jpg' } ) expect(article.createdAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.modifiedAt).to.not.be.undefined expect(article.id).to.not.be.undefined expect(article.type).to.equal('article') expect(article.shareUrl).to.not.be.undefined expect(article.links).to.not.be.undefined expect(article.state).to.equal('PROCESSING') expect(article.accessoryText).to.be.null expect(article.title).to.equal('Updated Simple with Headline under Header Image') expect(article.maturityRating).to.be.null expect(article.warnings).to.deep.equal([]) expect(article.isCandidateToBeFeatured).to.be.false expect(article.isSponsored).to.be.false expect(article.isPreview).to.be.true expect(article.isDevelopingStory).to.be.false expect(article.document.version).to.equal('1.0') expect(article.document.identifier).to.equal('Apple_Demo') expect(article.document.title).to.equal( 'Updated Simple with Headline under Header Image' ) expect(article.document.language).to.equal('en') expect(article.document.layout.columns).to.equal(7) expect(article.document.layout.width).to.equal(1024) expect(article.document.layout.margin).to.equal(70) expect(article.document.layout.gutter).to.equal(40) expect(article.document.subtitle).to.equal( 'Non occidere quae cumque vi ventia' ) expect(article.document.metadata.excerpt).to.equal('Updated Excerpt') expect(article.document.metadata.thumbnailURL).to.equal( 'bundle://header.jpg' ) expect(article.document.components.length).to.equal(10) expect(article.document.documentStyle).to.deep.equal({ backgroundColor: '#f6f6f6' }) expect(article.document.componentLayouts).to.not.be.undefined }) /** @test {apiEndpoints#updateArticle} */ it('should delete an article', function(done) { (async () => { this.timeout(30000) await this.client.deleteArticle(this.article.id) // Fetching a non-existent article should error try { await this.client.readArticle(this.article.id) } catch(err) { done() } })() }) })