Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [twitter] tests #1394

Merged
merged 3 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6403,18 +6403,20 @@ cache(function(data, match, sendBadge, request) {
badgeData.text[1] = '';
request(options, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
// The data is formatted as an array.
var data = JSON.parse(buffer)[0];
// data.followers_count could be zero… don't just check if falsey.
if (data !== undefined && data.followers_count != null){
if (data === undefined){
badgeData.text[1] = 'invalid user';
} else if (data.followers_count != null){// data.followers_count could be zero… don't just check if falsey.
badgeData.text[1] = metric(data.followers_count);
}
} catch(e) {
log.error(e);
badgeData.text[1] = 'invalid';
}
sendBadge(format, badgeData);
});
Expand Down
41 changes: 41 additions & 0 deletions service-tests/twitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');

const {
isMetric
} = require('./helpers/validators');

const t = new ServiceTester({ id: 'twitter', title: 'Twitter' });
module.exports = t;

t.create('Followers')
.get('/follow/shields_io.json')
.expectJSONTypes(Joi.object().keys({
name: 'Follow @shields_io',
value: isMetric
}));

t.create('Followers - Custom Label')
.get('/follow/shields_io.json?label=Follow')
.expectJSONTypes(Joi.object().keys({
name: 'Follow',
value: isMetric
}));

t.create('Invalid Username Specified')
.get('/follow/invalidusernamethatshouldnotexist.json?label=Follow')
.expectJSONTypes(Joi.object().keys({
name: 'Follow',
value: 'invalid user'
}));

t.create('No connection')
.get('/follow/shields_io.json?label=Follow')
.networkOff()
.expectJSON({ name: 'Follow', value: 'inaccessible' });

t.create('URL')
.get('/url/https/shields.io.json')
.expectJSON({ name: 'tweet', value: '' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a confusing badge URL!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Don't think it would be a very often used badge,
As it would need to be included as an <object> for the link to actually work.
Otherwise its the same as using https://img.shields.io/:tweet--grey.svg?style=social&logo=twitter

Will be good once we can get #966 implemented to see how often certain badges are being used.