From 454984e7b6d80da32854efbaa42424ce93c07a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Wahl=C3=A9?= Date: Wed, 4 Apr 2018 10:00:36 +0000 Subject: [PATCH 1/2] Fix parsing of Google Play information --- index.js | 10 +++++----- test/index.spec.js | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 4ecf01d..33fe656 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ /*! * reviews-to-slack - * Copyright(c) 2016 Niklas Wahlén + * Copyright(c) 2018 Niklas Wahlén * MIT Licensed */ @@ -141,13 +141,13 @@ exports.setupGooglePlayAppInformation = function (config, appInformation, callba request.get(appInformation.appLink, function (error, response, body) { if (error) { console.error('WARNING: [' + config.appId + '] Could not fetch app information, ' + error) - } else { + } else if (body) { const $ = cheerio.load(body) - appInformation.appName = $('.id-app-title').text().trim() + appInformation.appName = $('[itemprop="name"]').text().trim() if (config.debug) console.log('INFO: [' + config.appId + '] Fetched app name: ' + appInformation.appName) - var webpIcon = $('.cover-image').attr('src') - if (!webpIcon.startsWith('http')) { + var webpIcon = $('[itemprop="image"]').attr('src') + if (typeof webpIcon === 'string' && !webpIcon.startsWith('http')) { webpIcon = 'https:' + webpIcon } appInformation.appIcon = webpIcon + '-no-tmp.png' // Force png as Slack currently cannot display the WebP image. diff --git a/test/index.spec.js b/test/index.spec.js index 99ba5e1..1e6d229 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -236,12 +236,10 @@ describe('The module', function () { }) it('sets up Google Play app information when not overriden', function * () { - const config = { - appId: 'com.mock.id' - } + const config = { appId: 'com.mock.id' } var appInformation = {} - const body = ' Expected App Title ' + const body = '

Expected App Title

' const requestGetStub = this.sandbox.stub(request, 'get').callsFake(function (url, callback) { callback(null, null, body) @@ -254,4 +252,36 @@ describe('The module', function () { expect(appInformation.appName).to.eql('Expected App Title') expect(appInformation.appIcon).to.eql('https:cover-image-src-no-tmp.png') }) + + it('handels empty Google Play page body gracefully', function * () { + const config = { appId: 'com.mock.id' } + var appInformation = {} + + const requestGetStub = this.sandbox.stub(request, 'get').callsFake(function (url, callback) { + callback(null, null, '') + }) + + reviews.setupGooglePlayAppInformation(config, appInformation, function () {}) + + expect(requestGetStub.callCount).to.eql(1) + expect(appInformation.appLink).to.eql('https://play.google.com/store/apps/details?id=com.mock.id') + expect(appInformation.appName).to.eql('') + expect(appInformation.appIcon).to.eql('undefined-no-tmp.png') + }) + + it('handels null Google Play page response gracefully', function * () { + const config = { appId: 'com.mock.id' } + var appInformation = {} + + const requestGetStub = this.sandbox.stub(request, 'get').callsFake(function (url, callback) { + callback(null, null, null) + }) + + reviews.setupGooglePlayAppInformation(config, appInformation, function () {}) + + expect(requestGetStub.callCount).to.eql(1) + expect(appInformation.appLink).to.eql('https://play.google.com/store/apps/details?id=com.mock.id') + expect(appInformation.appName).to.eql(undefined) + expect(appInformation.appIcon).to.eql(undefined) + }) }) From 7c9069f095063bdbb2c3dba20b19ee31aaa7a741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Wahl=C3=A9?= Date: Wed, 4 Apr 2018 10:00:39 +0000 Subject: [PATCH 2/2] 2.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bee46bc..9023151 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reviews-to-slack", - "version": "2.1.0", + "version": "2.1.1", "description": "Post app reviews to Slack", "scripts": { "test": "npm run lint && npm run test-unit",