UNPKG

paradigm-facebook-ia

Version:
147 lines (106 loc) 4.79 kB
const FacebookIAAPI = require('../../src/lib/facebook-ia-api') function syncTimeout(ms) { return new Promise((resolve) => { setTimeout(() => { resolve() }, ms) }) } /** @test {apiEndpoints} */ describe('API Endpoints', function() { before(function() { this.client = new FacebookIAAPI( process.env.FB_PAGE_ID, process.env.FB_ACCESS_TOKEN ) this.goodMarkup = ` <html lang="en" prefix="op: http://media.facebook.com/op#"> <head> <meta charset="utf-8"> <meta property="op:markup_version" content="v1.0"> <title>Woman Reported Missing By Her Mom Ends Up On 'The Bachelor'</title> <link rel="canonical" href="http://www.guacamoley.com/trending/2018/02/02/Z1Wg8QO/bachelor-missing-person"> </head> <body> <article> <header><h1>Woman Reported Missing By Her Mom Ends Up On 'The Bachelor'</h1> <time class="op-published" datetime="2018-02-02T18:07:41.458Z">3 hours ago</time> <time class="op-modified" datetime="2018-02-02T21:22:02.052Z">29 seconds ago</time> <address><a rel="facebook" href="http://facebook.com/mgatollari">Mustafa Gatollari</a></address> <figure> <img src="http://media.guacamoley.com/1ibMn5/840x440/cover-bachelor-1517604765947.jpg"><figcaption>instagram</figcaption> </figure> </header> <p>Body text</p> </article> </body> </html> ` this.badMarkup = ` <html lang="en" prefix="op: http://media.facebook.com/op#"> <head> <meta charset="utf-8"> <meta property="op:markup_version" content="v1.0"> <title>Woman Reported Missing By Her Mom Ends Up On 'The Bachelor'</title> </head> <body> <article> <header><h1>Woman Reported Missing By Her Mom Ends Up On 'The Bachelor'</h1> <time class="op-published" datetime="2018-02-02T18:07:41.458Z">3 hours ago</time> <time class="op-modified" datetime="2018-02-02T21:22:02.052Z">29 seconds ago</time> <address><a rel="facebook" href="http://facebook.com/mgatollari">Mustafa Gatollari</a></address> <figure> <img src="http://media.guacamoley.com/1ibMn5/840x440/cover-bachelor-1517604765947.jpg"><figcaption>instagram</figcaption> </figure> </header> <p>Body text</p> </article> </body> </html> ` }) /** @test {apiEndpoints#createArticle} */ it('should create good article', async function() { this.timeout(30000) const res = await this.client.createArticle(this.goodMarkup) expect(res.id).to.not.be.undefined this.goodImportId = res.id }) /** @test {apiEndpoints#getArticleImportStatus} */ it('should get article import status for good article', async function() { this.timeout(60000) const res = await this.client.getArticleImportStatus(this.goodImportId) expect(res.status).to.equal('IN_PROGRESS') await syncTimeout(30000) const res2 = await this.client.getArticleImportStatus(this.goodImportId) expect(res2.status).to.equal('SUCCESS') expect(res2.instant_article.canonical_url).to.equal( 'http://www.guacamoley.com/trending/2018/02/02/Z1Wg8QO/bachelor-missing-person' ) expect(res2.instant_article.html_source).to.equal(this.goodMarkup.trim()) this.goodArticleId = res2.instant_article.id }) /** @test {apiEndpoints#createArticle} */ it('should create bad article', async function() { this.timeout(30000) const res = await this.client.createArticle(this.badMarkup) expect(res.id).to.not.be.undefined this.badImportId = res.id }) /** @test {apiEndpoints#getArticleImportStatus} */ it('should get article import status for bad article', async function() { this.timeout(60000) await syncTimeout(30000) const res = await this.client.getArticleImportStatus(this.badImportId) expect(res.status).to.equal('FAILED') expect(res.errors).to.deep.equal([{ level: "ERROR", message: "Missing Article's Canonical URL: There is no URL specified for this article. A canonical URL needs to be claimed and placed within the HTML to generate an Instant Article. Refer to URLs under Publishing Articles in the Instant Articles documentation for more information on claiming and inserting a canonical URL." }]) }) /** @test {apiEndpoints#updateArticle} */ it('should delete an article', async function() { this.timeout(30000) await this.client.deleteArticle(this.goodArticleId) }) })