Ghost/core/test/unit/utils/gravatar_spec.js
Katharina Irrgang 228c1c16fd
Tidy up unit test files (#9340)
refs #9178

- first iteration of tidying up the unit tests
- this is useful in the current stage, because if i move files in the server folder, i need a clean folder/file structure to detect which tests needs to move
- this is a simple cleanup to reflect the current server folder structure
2017-12-14 03:36:50 +01:00

54 lines
1.7 KiB
JavaScript

var should = require('should'), // jshint ignore:line
nock = require('nock'),
configUtils = require('../../utils/configUtils'),
gravatar = require('../../../server/utils/gravatar');
describe('Utils: gravatar-lookup', function () {
beforeEach(function () {
configUtils.set('privacy:useGravatar', true);
});
afterEach(function () {
configUtils.restore();
});
it('can successfully lookup a gravatar url', function (done) {
nock('https://www.gravatar.com')
.get('/avatar/ef6dcde5c99bb8f685dd451ccc3e050a?s=250&d=404&r=x')
.reply(200);
gravatar.lookup({email: 'exists@example.com'}).then(function (result) {
should.exist(result);
should.exist(result.image);
result.image.should.eql('//www.gravatar.com/avatar/ef6dcde5c99bb8f685dd451ccc3e050a?s=250&d=mm&r=x');
done();
}).catch(done);
});
it('can handle a non existant gravatar', function (done) {
nock('https://www.gravatar.com')
.get('/avatar/3a2963a39ebba98fb0724a1db2f13d63?s=250&d=404&r=x')
.reply(404);
gravatar.lookup({email: 'invalid@example.com'}).then(function (result) {
should.exist(result);
should.not.exist(result.image);
done();
}).catch(done);
});
it('will timeout', function (done) {
nock('https://www.gravatar.com')
.get('/avatar/ef6dcde5c99bb8f685dd451ccc3e050a?s=250&d=404&r=x')
.delay(15)
.reply(200);
gravatar.lookup({email: 'exists@example.com'}, 10).then(function (result) {
should.not.exist(result);
done();
}).catch(done);
});
});