service tests for [itunes] (#1464)

This commit is contained in:
chris48s
2018-01-21 22:50:04 +00:00
committed by Paul Melnikow
parent 1d8926672c
commit e3ac9c3db5
2 changed files with 48 additions and 0 deletions

View File

@@ -2101,6 +2101,15 @@ cache(function(data, match, sendBadge, request) {
}
try {
var data = JSON.parse(buffer);
if (data.resultCount === 0) {
/* Note the 'not found' response from iTunes is:
status code = 200,
body = { "resultCount":0, "results": [] }
*/
badgeData.text[1] = 'not found';
sendBadge(format, badgeData);
return;
}
var version = data.results[0].version;
badgeData.text[1] = versionText(version);
badgeData.colorscheme = versionColor(version);

39
service-tests/itunes.js Normal file
View File

@@ -0,0 +1,39 @@
'use strict';
const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const { isVPlusDottedVersionAtLeastOne } = require('./helpers/validators');
const t = new ServiceTester({ id: 'itunes', title: 'iTunes' });
module.exports = t;
t.create('iTunes version (valid)')
.get('/v/324684580.json')
.expectJSONTypes(Joi.object().keys({
name: 'itunes app store',
value: isVPlusDottedVersionAtLeastOne
}));
t.create('iTunes version (not found)')
.get('/v/9.json')
.expectJSON({name: 'itunes app store', value: 'not found'});
t.create('iTunes version (invalid)')
.get('/v/x.json')
.expectJSON({name: 'itunes app store', value: 'invalid'});
t.create('iTunes version (connection error)')
.get('/v/324684580.json')
.networkOff()
.expectJSON({name: 'itunes app store', value: 'inaccessible'});
t.create('iTunes version (unexpected response)')
.get('/v/324684580.json')
.intercept(nock => nock('https://itunes.apple.com')
.get('/lookup?id=324684580')
.reply(200, "{{{{{invalid json}}")
)
.expectJSON({name: 'itunes app store', value: 'invalid'});