2015-01-10 06:31:47 +03:00
|
|
|
var should = require('should'),
|
2016-02-09 17:14:24 +03:00
|
|
|
sinon = require('sinon'),
|
2016-02-12 23:04:26 +03:00
|
|
|
nock = require('nock'),
|
2015-10-13 14:55:24 +03:00
|
|
|
parsePackageJson = require('../../server/utils/parse-package-json'),
|
|
|
|
readDirectory = require('../../server/utils/read-directory'),
|
|
|
|
readThemes = require('../../server/utils/read-themes'),
|
2016-02-12 23:04:26 +03:00
|
|
|
gravatar = require('../../server/utils/gravatar'),
|
2016-03-29 23:19:42 +03:00
|
|
|
tmp = require('tmp'),
|
2015-10-13 14:55:24 +03:00
|
|
|
utils = require('../../server/utils'),
|
|
|
|
join = require('path').join,
|
|
|
|
fs = require('fs');
|
2015-01-10 06:31:47 +03:00
|
|
|
|
|
|
|
// To stop jshint complaining
|
|
|
|
should.equal(true, true);
|
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
describe('Server Utilities', function () {
|
|
|
|
describe('Safe String', function () {
|
|
|
|
var safeString = utils.safeString,
|
|
|
|
options = {};
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should remove beginning and ending whitespace', function () {
|
|
|
|
var result = safeString(' stringwithspace ', options);
|
|
|
|
result.should.equal('stringwithspace');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should remove non ascii characters', function () {
|
|
|
|
var result = safeString('howtowin✓', options);
|
|
|
|
result.should.equal('howtowin');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should replace spaces with dashes', function () {
|
|
|
|
var result = safeString('how to win', options);
|
|
|
|
result.should.equal('how-to-win');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should replace most special characters with dashes', function () {
|
2016-01-05 19:52:23 +03:00
|
|
|
var result = safeString('a:b/c?d#e[f]g!h$i&j(k)l*m+n,o;{p}=q\\r%s<t>u|v^w~x£y"z@1.2`3', options);
|
|
|
|
result.should.equal('a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-1-2-3');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should replace all of the html4 compat symbols in ascii except hyphen and underscore', function () {
|
|
|
|
// note: This is missing the soft-hyphen char that isn't much-liked by linters/browsers/etc,
|
|
|
|
// it passed the test before it was removed
|
|
|
|
var result = safeString('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿');
|
|
|
|
result.should.equal('_-c-y-ss-c-a-r-deg-23up-1o-1-41-23-4');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should replace all of the foreign chars in ascii', function () {
|
|
|
|
var result = safeString('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ');
|
|
|
|
result.should.equal('aaaaaaaeceeeeiiiidnoooooxouuuuuthssaaaaaaaeceeeeiiiidnooooo-ouuuuythy');
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should remove special characters at the beginning of a string', function () {
|
|
|
|
var result = safeString('.Not special', options);
|
|
|
|
result.should.equal('not-special');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should remove apostrophes ', function () {
|
|
|
|
var result = safeString('how we shouldn\'t be', options);
|
|
|
|
result.should.equal('how-we-shouldnt-be');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should convert to lowercase', function () {
|
|
|
|
var result = safeString('This has Upper Case', options);
|
|
|
|
result.should.equal('this-has-upper-case');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should convert multiple dashes into a single dash', function () {
|
|
|
|
var result = safeString('This :) means everything', options);
|
|
|
|
result.should.equal('this-means-everything');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
it('should remove trailing dashes from the result', function () {
|
|
|
|
var result = safeString('This.', options);
|
|
|
|
result.should.equal('this');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle pound signs', function () {
|
|
|
|
var result = safeString('WHOOPS! I spent all my £ again!', options);
|
|
|
|
result.should.equal('whoops-i-spent-all-my-again');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should properly handle unicode punctuation conversion', function () {
|
|
|
|
var result = safeString('に間違いがないか、再度確認してください。再読み込みしてください。', options);
|
|
|
|
result.should.equal('nijian-wei-iganaika-zai-du-que-ren-sitekudasai-zai-du-miip-misitekudasai');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not lose or convert dashes if options are passed with truthy importing flag', function () {
|
|
|
|
var result,
|
|
|
|
options = {importing: true};
|
|
|
|
result = safeString('-slug-with-starting-ending-and---multiple-dashes-', options);
|
|
|
|
result.should.equal('-slug-with-starting-ending-and---multiple-dashes-');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should still remove/convert invalid characters when passed options with truthy importing flag', function () {
|
|
|
|
var result,
|
|
|
|
options = {importing: true};
|
|
|
|
result = safeString('-slug-&with-✓-invalid-characters-に\'', options);
|
|
|
|
result.should.equal('-slug--with--invalid-characters-ni');
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
});
|
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
describe('parse-package-json', function () {
|
|
|
|
it('should parse valid package.json', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var pkgJson, tmpFile;
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
tmpFile = tmp.fileSync();
|
2015-10-13 14:55:24 +03:00
|
|
|
pkgJson = JSON.stringify({
|
|
|
|
name: 'test',
|
|
|
|
version: '0.0.0'
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
parsePackageJson(tmpFile.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function (pkg) {
|
|
|
|
pkg.should.eql({
|
|
|
|
name: 'test',
|
|
|
|
version: '0.0.0'
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
2015-10-28 17:13:54 +03:00
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(tmpFile.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when name is missing', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var pkgJson, tmpFile;
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
tmpFile = tmp.fileSync();
|
2015-10-13 14:55:24 +03:00
|
|
|
pkgJson = JSON.stringify({
|
|
|
|
version: '0.0.0'
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
parsePackageJson(tmpFile.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function () {
|
|
|
|
done(new Error('parsePackageJson succeeded, but should\'ve failed'));
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
2016-03-29 23:19:42 +03:00
|
|
|
err.context.should.equal(tmpFile.name);
|
2015-10-13 14:55:24 +03:00
|
|
|
err.help.should.equal('This will be required in future. Please see http://docs.ghost.org/themes/');
|
|
|
|
|
|
|
|
done();
|
2015-10-28 17:13:54 +03:00
|
|
|
})
|
2016-03-29 23:19:42 +03:00
|
|
|
.catch(done)
|
|
|
|
.finally(tmpFile.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when version is missing', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var pkgJson, tmpFile;
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
tmpFile = tmp.fileSync();
|
2015-10-13 14:55:24 +03:00
|
|
|
pkgJson = JSON.stringify({
|
|
|
|
name: 'test'
|
|
|
|
});
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
parsePackageJson(tmpFile.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function () {
|
|
|
|
done(new Error('parsePackageJson succeeded, but should\'ve failed'));
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
2016-03-29 23:19:42 +03:00
|
|
|
err.context.should.equal(tmpFile.name);
|
2015-10-13 14:55:24 +03:00
|
|
|
err.help.should.equal('This will be required in future. Please see http://docs.ghost.org/themes/');
|
|
|
|
|
|
|
|
done();
|
2015-10-28 17:13:54 +03:00
|
|
|
})
|
2016-03-29 23:19:42 +03:00
|
|
|
.catch(done)
|
|
|
|
.finally(tmpFile.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when JSON is invalid', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var pkgJson, tmpFile;
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
tmpFile = tmp.fileSync();
|
2015-10-13 14:55:24 +03:00
|
|
|
pkgJson = '{name:"test"}';
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
parsePackageJson(tmpFile.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function () {
|
|
|
|
done(new Error('parsePackageJson succeeded, but should\'ve failed'));
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
err.message.should.equal('Theme package.json file is malformed');
|
2016-03-29 23:19:42 +03:00
|
|
|
err.context.should.equal(tmpFile.name);
|
2015-10-13 14:55:24 +03:00
|
|
|
err.help.should.equal('This will be required in future. Please see http://docs.ghost.org/themes/');
|
|
|
|
|
|
|
|
done();
|
2015-10-28 17:13:54 +03:00
|
|
|
})
|
2016-03-29 23:19:42 +03:00
|
|
|
.catch(done)
|
|
|
|
.finally(tmpFile.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when file is missing', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var tmpFile = tmp.fileSync();
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
tmpFile.removeCallback();
|
|
|
|
parsePackageJson(tmpFile.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function () {
|
|
|
|
done(new Error('parsePackageJson succeeded, but should\'ve failed'));
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
err.message.should.equal('Could not read package.json file');
|
2016-03-29 23:19:42 +03:00
|
|
|
err.context.should.equal(tmpFile.name);
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
done();
|
2015-10-28 17:13:54 +03:00
|
|
|
})
|
2016-03-29 23:19:42 +03:00
|
|
|
.catch(done);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
});
|
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
describe('read-directory', function () {
|
|
|
|
it('should read directory recursively', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var themePath = tmp.dirSync({unsafeCleanup: true});
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
// create example theme
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themePath.name, 'partials'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'index.hbs'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'partials', 'navigation.hbs'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
readDirectory(themePath.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function (tree) {
|
|
|
|
tree.should.eql({
|
|
|
|
partials: {
|
2016-03-29 23:19:42 +03:00
|
|
|
'navigation.hbs': join(themePath.name, 'partials', 'navigation.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
},
|
2016-03-29 23:19:42 +03:00
|
|
|
'index.hbs': join(themePath.name, 'index.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
2015-10-28 17:13:54 +03:00
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(themePath.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should read directory and ignore unneeded items', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var themePath = tmp.dirSync({unsafeCleanup: true});
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
// create example theme
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themePath.name, 'partials'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'index.hbs'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'partials', 'navigation.hbs'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
// create some trash
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themePath.name, 'node_modules'));
|
|
|
|
fs.mkdirSync(join(themePath.name, 'bower_components'));
|
|
|
|
fs.mkdirSync(join(themePath.name, '.git'));
|
|
|
|
fs.writeFileSync(join(themePath.name, '.DS_Store'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
readDirectory(themePath.name, {ignore: ['.git']})
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function (tree) {
|
|
|
|
tree.should.eql({
|
|
|
|
partials: {
|
2016-03-29 23:19:42 +03:00
|
|
|
'navigation.hbs': join(themePath.name, 'partials', 'navigation.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
},
|
2016-03-29 23:19:42 +03:00
|
|
|
'index.hbs': join(themePath.name, 'index.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
2015-10-28 17:13:54 +03:00
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(themePath.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should read directory and parse package.json files', function (done) {
|
|
|
|
var themePath, pkgJson;
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
themePath = tmp.dirSync({unsafeCleanup: true});
|
2015-10-13 14:55:24 +03:00
|
|
|
pkgJson = JSON.stringify({
|
|
|
|
name: 'test',
|
|
|
|
version: '0.0.0'
|
|
|
|
});
|
|
|
|
|
|
|
|
// create example theme
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themePath.name, 'partials'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'package.json'), pkgJson);
|
|
|
|
fs.writeFileSync(join(themePath.name, 'index.hbs'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'partials', 'navigation.hbs'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
readDirectory(themePath.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function (tree) {
|
|
|
|
tree.should.eql({
|
|
|
|
partials: {
|
2016-03-29 23:19:42 +03:00
|
|
|
'navigation.hbs': join(themePath.name, 'partials', 'navigation.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
},
|
2016-03-29 23:19:42 +03:00
|
|
|
'index.hbs': join(themePath.name, 'index.hbs'),
|
2015-10-13 14:55:24 +03:00
|
|
|
'package.json': {
|
|
|
|
name: 'test',
|
|
|
|
version: '0.0.0'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
2015-10-28 17:13:54 +03:00
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(themePath.removeCallback);
|
2015-10-28 17:13:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should read directory and ignore invalid package.json files', function (done) {
|
|
|
|
var themePath, pkgJson;
|
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
themePath = tmp.dirSync({unsafeCleanup: true});
|
2015-10-28 17:13:54 +03:00
|
|
|
pkgJson = JSON.stringify({
|
|
|
|
name: 'test'
|
|
|
|
});
|
|
|
|
|
|
|
|
// create example theme
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themePath.name, 'partials'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'package.json'), pkgJson);
|
|
|
|
fs.writeFileSync(join(themePath.name, 'index.hbs'));
|
|
|
|
fs.writeFileSync(join(themePath.name, 'partials', 'navigation.hbs'));
|
2015-10-28 17:13:54 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
readDirectory(themePath.name)
|
2015-10-28 17:13:54 +03:00
|
|
|
.then(function (tree) {
|
|
|
|
tree.should.eql({
|
|
|
|
partials: {
|
2016-03-29 23:19:42 +03:00
|
|
|
'navigation.hbs': join(themePath.name, 'partials', 'navigation.hbs')
|
2015-10-28 17:13:54 +03:00
|
|
|
},
|
2016-03-29 23:19:42 +03:00
|
|
|
'index.hbs': join(themePath.name, 'index.hbs'),
|
2015-10-28 17:13:54 +03:00
|
|
|
'package.json': null
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(themePath.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
});
|
2015-09-23 13:54:56 +03:00
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
describe('read-themes', function () {
|
|
|
|
it('should read directory and include only folders', function (done) {
|
2016-03-29 23:19:42 +03:00
|
|
|
var themesPath = tmp.dirSync({unsafeCleanup: true});
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
// create trash
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.writeFileSync(join(themesPath.name, 'casper.zip'));
|
|
|
|
fs.writeFileSync(join(themesPath.name, '.DS_Store'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
|
|
|
// create actual theme
|
2016-03-29 23:19:42 +03:00
|
|
|
fs.mkdirSync(join(themesPath.name, 'casper'));
|
|
|
|
fs.mkdirSync(join(themesPath.name, 'casper', 'partials'));
|
|
|
|
fs.writeFileSync(join(themesPath.name, 'casper', 'index.hbs'));
|
|
|
|
fs.writeFileSync(join(themesPath.name, 'casper', 'partials', 'navigation.hbs'));
|
2015-10-13 14:55:24 +03:00
|
|
|
|
2016-03-29 23:19:42 +03:00
|
|
|
readThemes(themesPath.name)
|
2015-10-13 14:55:24 +03:00
|
|
|
.then(function (tree) {
|
|
|
|
tree.should.eql({
|
|
|
|
casper: {
|
|
|
|
partials: {
|
2016-03-29 23:19:42 +03:00
|
|
|
'navigation.hbs': join(themesPath.name, 'casper', 'partials', 'navigation.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
},
|
2016-03-29 23:19:42 +03:00
|
|
|
'index.hbs': join(themesPath.name, 'casper', 'index.hbs')
|
2015-10-13 14:55:24 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
2015-10-28 17:13:54 +03:00
|
|
|
.catch(done)
|
2016-03-29 23:19:42 +03:00
|
|
|
.finally(themesPath.removeCallback);
|
2015-10-13 14:55:24 +03:00
|
|
|
});
|
2015-09-23 13:54:56 +03:00
|
|
|
});
|
|
|
|
|
2016-02-12 23:04:26 +03:00
|
|
|
describe('gravatar-lookup', function () {
|
|
|
|
var currentEnv = process.env.NODE_ENV;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
// give environment a value that will call gravatar
|
|
|
|
process.env.NODE_ENV = 'production';
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
// reset the environment
|
|
|
|
process.env.NODE_ENV = currentEnv;
|
|
|
|
});
|
|
|
|
|
|
|
|
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(11)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
gravatar.lookup({email: 'exists@example.com'}, 10).then(function (result) {
|
|
|
|
should.exist(result);
|
|
|
|
should.not.exist(result.image);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-09 17:14:24 +03:00
|
|
|
describe('redirect301', function () {
|
|
|
|
it('performs a 301 correctly', function (done) {
|
|
|
|
var res = {};
|
|
|
|
|
|
|
|
res.set = sinon.spy();
|
|
|
|
|
|
|
|
res.redirect = function (code, path) {
|
|
|
|
code.should.equal(301);
|
|
|
|
path.should.eql('my/awesome/path');
|
|
|
|
res.set.calledWith({'Cache-Control': 'public, max-age=' + utils.ONE_YEAR_S}).should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.redirect301(res, 'my/awesome/path');
|
|
|
|
});
|
|
|
|
});
|
2015-01-10 06:31:47 +03:00
|
|
|
});
|