💄 🐷 Test consistency (#8199)

no issue

- change out should.equal for // jshint ignore:line
- ensure should is the first require in every test, and ALWAYS require
- make sinon the second require, and sandbox the last thing
- ALWAYS use sandbox, futureproofs tests against contributors who don't know it
- change require formatting
This commit is contained in:
Hannah Wolfe 2017-03-21 08:24:11 +00:00 committed by Katharina Irrgang
parent fad0ac7213
commit 47e00900cc
185 changed files with 2337 additions and 2079 deletions

View File

@ -1,7 +1,7 @@
var should = require('should'),
var should = require('should'),
// Stuff we are testing
ampComponentsHelper = require('../lib/helpers/amp_components');
ampComponentsHelper = require('../lib/helpers/amp_components');
describe('{{amp_components}} helper', function () {
it('adds script tag for a gif', function () {

View File

@ -1,9 +1,9 @@
var should = require('should'),
rewire = require('rewire'),
configUtils = require('../../../../test/utils/configUtils'),
var should = require('should'),
rewire = require('rewire'),
configUtils = require('../../../../test/utils/configUtils'),
// Stuff we are testing
ampContentHelper = rewire('../lib/helpers/amp_content');
ampContentHelper = rewire('../lib/helpers/amp_content');
// TODO: Amperize really needs to get stubbed, so we can test returning errors
// properly and make this test faster!

View File

@ -1,14 +1,15 @@
/*globals describe, beforeEach, afterEach, it*/
var rewire = require('rewire'),
ampController = rewire('../lib/router'),
path = require('path'),
sinon = require('sinon'),
Promise = require('bluebird'),
errors = require('../../../errors'),
should = require('should'),
configUtils = require('../../../../test/utils/configUtils'),
themes = require('../../../themes'),
sandbox = sinon.sandbox.create();
var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
path = require('path'),
Promise = require('bluebird'),
ampController = rewire('../lib/router'),
errors = require('../../../errors'),
configUtils = require('../../../../test/utils/configUtils'),
themes = require('../../../themes'),
sandbox = sinon.sandbox.create();
// Helper function to prevent unit tests
// from failing via timeout when they

View File

@ -1,9 +1,8 @@
var should = require('should'),
card = require('../cards/hr'),
SimpleDom = require('simple-dom'),
var should = require('should'), // jshint ignore:line
card = require('../cards/hr'),
SimpleDom = require('simple-dom'),
opts;
should = should;
describe('HR card', function () {
it('generates a horizontal rule', function () {
opts = {

View File

@ -1,9 +1,8 @@
var should = require('should'),
card = require('../cards/html'),
SimpleDom = require('simple-dom'),
var should = require('should'), // jshint ignore:line
card = require('../cards/html'),
SimpleDom = require('simple-dom'),
opts;
should = should;
describe('HTML card', function () {
it('HTML Card renders', function () {
opts = {

View File

@ -1,9 +1,8 @@
var should = require('should'),
card = require('../cards/image'),
SimpleDom = require('simple-dom'),
var should = require('should'), // jshint ignore:line
card = require('../cards/image'),
SimpleDom = require('simple-dom'),
opts;
should = should;
describe('Image card', function () {
it('generates an image', function () {
opts = {

View File

@ -1,9 +1,8 @@
var should = require('should'),
card = require('../cards/markdown'),
SimpleDom = require('simple-dom'),
var should = require('should'), // jshint ignore:line
card = require('../cards/markdown'),
SimpleDom = require('simple-dom'),
opts;
should = should;
describe('Markdown card', function () {
it('Markdown Card renders', function () {
opts = {

View File

@ -1,9 +1,8 @@
var should = require('should'),
card = require('../atoms/soft-return'),
SimpleDom = require('simple-dom'),
var should = require('should'), // jshint ignore:line
card = require('../atoms/soft-return'),
SimpleDom = require('simple-dom'),
opts;
should = should;
describe('Soft return card', function () {
it('generates a `br` tag', function () {
opts = {

View File

@ -1,10 +1,11 @@
/*globals describe, beforeEach, afterEach, it*/
var privateController = require('../lib/router').controller,
should = require('should'),
path = require('path'),
sinon = require('sinon'),
configUtils = require('../../../../test/utils/configUtils'),
themes = require('../../../themes'),
var should = require('should'),
sinon = require('sinon'),
configUtils = require('../../../../test/utils/configUtils'),
path = require('path'),
themes = require('../../../themes'),
privateController = require('../lib/router').controller,
sandbox = sinon.sandbox.create();
describe('Private Controller', function () {

View File

@ -1,6 +1,6 @@
// We use the name input_password to match the helper for consistency:
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var should = require('should'),
var should = require('should'),
// Stuff we are testing
input_password = require('../lib/helpers/input_password');

View File

@ -1,14 +1,15 @@
/*globals describe, beforeEach, afterEach, it*/
var crypto = require('crypto'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
privateBlogging = require('../lib/middleware'),
api = require('../../../api'),
errors = require('../../../errors'),
fs = require('fs');
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
crypto = require('crypto'),
Promise = require('bluebird'),
api = require('../../../api'),
errors = require('../../../errors'),
fs = require('fs'),
should.equal(true, true);
privateBlogging = require('../lib/middleware'),
sandbox = sinon.sandbox.create();
function hash(password, salt) {
var hasher = crypto.createHash('sha256');
@ -19,12 +20,7 @@ function hash(password, salt) {
}
describe('Private Blogging', function () {
var sandbox,
apiSettingsStub;
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
var apiSettingsStub;
afterEach(function () {
sandbox.restore();
@ -98,8 +94,10 @@ describe('Private Blogging', function () {
status: function () {
return this;
},
send: function () {},
set: function () {},
send: function () {
},
set: function () {
},
isPrivateBlog: true
};
});

View File

@ -1,5 +1,5 @@
var should = require('should'),
router = require('../../../../../server/apps/subscribers/lib/router');
router = require('../lib/router');
describe('UNIT: Apps Subscriber Router', function () {
it('[failure] email is invalid, ensure it`s sanitized', function (done) {

View File

@ -1,9 +1,9 @@
// # Module tests
// This tests using Ghost as an npm module
var should = require('should'),
testUtils = require('../../utils'),
ghost = testUtils.startGhost,
i18n = require('../../../../core/server/i18n');
var should = require('should'),
testUtils = require('../../utils'),
ghost = testUtils.startGhost,
i18n = require('../../../../core/server/i18n');
i18n.init();

View File

@ -3,12 +3,13 @@
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
// But then again testing real code, rather than mock code, might be more useful...
var request = require('supertest'),
should = require('should'),
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../utils'),
ghost = testUtils.startGhost,
i18n = require('../../../../core/server/i18n'),
config = require('../../../../core/server/config');
config = require('../../../../core/server/config'),
request;
i18n.init();
@ -49,7 +50,7 @@ describe('Admin Routing', function () {
ghostServer = _ghostServer;
return ghostServer.start();
}).then(function () {
request = request(config.get('url'));
request = supertest.agent(config.get('url'));
done();
}).catch(function (e) {
console.log('Ghost Error: ', e);
@ -135,7 +136,7 @@ describe('Admin Routing', function () {
describe('FORK', function () {
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
describe('Require HTTPS - redirect', function () {
var forkedGhost, request;
var forkedGhost;
before(function (done) {
testUtils.fork.ghost({
@ -146,8 +147,7 @@ describe('Admin Routing', function () {
}, 'testhttps')
.then(function (child) {
forkedGhost = child;
request = require('supertest');
request = request('http://localhost:2390');
request = supertest.agent('http://localhost:2390');
}).then(done)
.catch(done);
});

View File

@ -1,13 +1,13 @@
var supertest = require('supertest'),
should = require('should'),
moment = require('moment'),
testUtils = require('../../../utils'),
user = testUtils.DataGenerator.forModel.users[0],
userForKnex = testUtils.DataGenerator.forKnex.users[0],
models = require('../../../../../core/server/models'),
config = require('../../../../../core/server/config'),
utils = require('../../../../../core/server/utils'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
moment = require('moment'),
user = testUtils.DataGenerator.forModel.users[0],
userForKnex = testUtils.DataGenerator.forKnex.users[0],
models = require('../../../../../core/server/models'),
config = require('../../../../../core/server/config'),
utils = require('../../../../../core/server/utils'),
ghost = testUtils.startGhost,
request;
describe('Authentication API', function () {

View File

@ -1,8 +1,8 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Configuration API', function () {

View File

@ -1,9 +1,9 @@
var supertest = require('supertest'),
should = require('should'),
path = require('path'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
path = require('path'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('DB API', function () {

View File

@ -2,12 +2,11 @@
// As it stands, these tests depend on the database, and as such are integration tests.
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
// But then again testing real code, rather than mock code, might be more useful...
var supertest = require('supertest'),
should = require('should'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
require('should-http');

View File

@ -1,8 +1,8 @@
var testUtils = require('../../../utils'),
supertest = require('supertest'),
should = require('should'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Notifications API', function () {

View File

@ -1,10 +1,10 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Post API', function () {

View File

@ -1,9 +1,9 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
_ = require('lodash'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
_ = require('lodash'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Public API', function () {

View File

@ -1,8 +1,8 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Settings API', function () {

View File

@ -1,8 +1,8 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Slug API', function () {

View File

@ -1,9 +1,9 @@
var supertest = require('supertest'),
should = require('should'),
testUtils = require('../../../utils'),
db = require('../../../../../core/server/data/db'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
db = require('../../../../../core/server/data/db'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
failedLoginAttempt,
count,
checkBruteTable,
@ -104,7 +104,7 @@ describe('Spam Prevention API', function () {
return done(err);
}
if (count < config.get('spam:user_login:freeRetries') + 1) {
if (count < config.get('spam:user_login:freeRetries') + 1) {
return failedLoginAttempt(email);
}
@ -161,7 +161,7 @@ describe('Spam Prevention API', function () {
return done(err);
}
if (count < config.get('spam:user_login:freeRetries') + 1) {
if (count < config.get('spam:user_login:freeRetries') + 1) {
return failedLoginAttempt(owner.email);
}

View File

@ -1,8 +1,8 @@
var testUtils = require('../../../utils'),
should = require('should'),
supertest = require('supertest'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Tag API', function () {

View File

@ -1,6 +1,6 @@
var testUtils = require('../../../utils'),
should = require('should'),
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
fs = require('fs-extra'),
join = require('path').join,
tmp = require('tmp'),

View File

@ -1,18 +1,14 @@
var testUtils = require('../../../utils'),
/*jshint unused:false*/
should = require('should'),
path = require('path'),
fs = require('fs-extra'),
supertest = require('supertest'),
ghost = testUtils.startGhost,
rewire = require('rewire'),
config = require('../../../../../core/server/config'),
var should = require('should'), // jshint ignore:line
supertest = require('supertest'),
testUtils = require('../../../utils'),
path = require('path'),
fs = require('fs-extra'),
ghost = testUtils.startGhost,
config = require('../../../../../core/server/config'),
request;
describe('Upload Icon API', function () {
var accesstoken = '',
getIconDimensions,
icons = [], ghostServer;
var accesstoken = '', icons = [], ghostServer;
before(function (done) {
// starting ghost automatically populates the db
@ -46,7 +42,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon.png'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -62,7 +58,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_multi_sizes.ico'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_multi_sizes.ico'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -77,7 +73,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_32x_single.ico'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_32x_single.ico'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -110,7 +106,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghosticon.jpg'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghosticon.jpg'))
.expect(415)
.end(function (err) {
if (err) {
@ -126,7 +122,7 @@ describe('Upload Icon API', function () {
.set('Authorization', 'Bearer ' + accesstoken)
.set('content-type', 'image/png')
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.pngx'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.pngx'))
.expect(415)
.end(function (err) {
if (err) {
@ -140,7 +136,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_not_square.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_not_square.png'))
.expect(422)
.end(function (err) {
if (err) {
@ -154,7 +150,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_size_too_large.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_size_too_large.png'))
.expect(413)
.end(function (err) {
if (err) {
@ -168,7 +164,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_too_large.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_too_large.png'))
.expect(422)
.end(function (err) {
if (err) {
@ -182,7 +178,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_too_small.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_too_small.png'))
.expect(422)
.end(function (err) {
if (err) {
@ -196,7 +192,7 @@ describe('Upload Icon API', function () {
request.post(testUtils.API.getApiQuery('uploads/icon'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_16x_single.ico'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/favicon_16x_single.ico'))
.expect(422)
.end(function (err) {
if (err) {

View File

@ -1,11 +1,10 @@
var testUtils = require('../../../utils'),
/*jshint unused:false*/
should = require('should'),
path = require('path'),
fs = require('fs-extra'),
supertest = require('supertest'),
ghost = testUtils.startGhost,
config = require('../../../../../core/server/config'),
var should = require('should'), // jshint ignore:line
supertest = require('supertest'),
testUtils = require('../../../utils'),
path = require('path'),
fs = require('fs-extra'),
ghost = testUtils.startGhost,
config = require('../../../../../core/server/config'),
request;
describe('Upload API', function () {
@ -45,7 +44,7 @@ describe('Upload API', function () {
request.post(testUtils.API.getApiQuery('uploads'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.png'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.png'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -61,7 +60,7 @@ describe('Upload API', function () {
request.post(testUtils.API.getApiQuery('uploads'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghosticon.jpg'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghosticon.jpg'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -77,7 +76,7 @@ describe('Upload API', function () {
request.post(testUtils.API.getApiQuery('uploads'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/loadingcat.gif'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/loadingcat.gif'))
.expect(200)
.end(function (err, res) {
if (err) {
@ -110,7 +109,7 @@ describe('Upload API', function () {
request.post(testUtils.API.getApiQuery('uploads'))
.set('Authorization', 'Bearer ' + accesstoken)
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/csv/single-column-with-header.csv'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/csv/single-column-with-header.csv'))
.expect(415)
.end(function (err) {
if (err) {
@ -126,7 +125,7 @@ describe('Upload API', function () {
.set('Authorization', 'Bearer ' + accesstoken)
.set('content-type', 'image/png')
.expect('Content-Type', /json/)
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.pngx'))
.attach('uploadimage', path.join(__dirname, '/../../../utils/fixtures/images/ghost-logo.pngx'))
.expect(415)
.end(function (err) {
if (err) {

View File

@ -1,9 +1,9 @@
var testUtils = require('../../../utils'),
should = require('should'),
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../../utils'),
ObjectId = require('bson-objectid'),
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
config = require('../../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('User API', function () {

View File

@ -1,14 +1,14 @@
// # Channel Route Tests
// As it stands, these tests depend on the database, and as such are integration tests.
// These tests are here to cover the headers sent with requests and high-level redirects that can't be
// tested with the unit tests
var request = require('supertest'),
should = require('should'),
cheerio = require('cheerio'),
testUtils = require('../../utils'),
config = require('../../../../core/server/config'),
ghost = testUtils.startGhost;
var should = require('should'),
supertest = require('supertest'),
testUtils = require('../../utils'),
cheerio = require('cheerio'),
config = require('../../../../core/server/config'),
ghost = testUtils.startGhost,
request;
describe('Channel Routes', function () {
var ghostServer;
@ -33,7 +33,7 @@ describe('Channel Routes', function () {
ghostServer = _ghostServer;
return ghostServer.start();
}).then(function () {
request = request(config.get('url'));
request = supertest.agent(config.get('url'));
done();
}).catch(function (e) {
console.log('Ghost Error: ', e);

View File

@ -2,19 +2,20 @@
// As it stands, these tests depend on the database, and as such are integration tests.
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
// But then again testing real code, rather than mock code, might be more useful...
var request = require('supertest'),
should = require('should'),
moment = require('moment'),
var should = require('should'),
sinon = require('sinon'),
supertest = require('supertest'),
testUtils = require('../../utils'),
moment = require('moment'),
cheerio = require('cheerio'),
_ = require('lodash'),
testUtils = require('../../utils'),
config = require('../../../server/config'),
settingsCache = require('../../../server/settings/cache'),
origCache = _.cloneDeep(settingsCache),
sandbox = sinon.sandbox.create(),
ghost = testUtils.startGhost;
ghost = testUtils.startGhost,
request,
sandbox = sinon.sandbox.create();
describe('Frontend Routing', function () {
var ghostServer;
@ -54,7 +55,7 @@ describe('Frontend Routing', function () {
ghostServer = _ghostServer;
return ghostServer.start();
}).then(function () {
request = request(config.get('url'));
request = supertest.agent(config.get('url'));
done();
}).catch(function (e) {
console.log('Ghost Error: ', e);
@ -543,27 +544,28 @@ describe('Frontend Routing', function () {
});
describe('FORK', function () {
describe('Subdirectory (no slash)', function () {
var forkedGhost, request;
var forkedGhost;
function killFork(done) {
if (forkedGhost) {
forkedGhost.kill(done);
} else {
done(new Error('No forked ghost process exists, test setup must have failed.'));
}
}
describe('Subdirectory (no slash)', function () {
before(function (done) {
testUtils.fork.ghost({
url: 'http://localhost/blog'
}, 'testsubdir')
.then(function (child) {
forkedGhost = child;
request = require('supertest');
request = request('http://localhost:' + child.port);
request = supertest.agent('http://localhost:' + child.port);
}).then(done).catch(done);
});
after(function (done) {
if (forkedGhost) {
forkedGhost.kill(done);
} else {
done(new Error('No forked ghost process exists, test setup must have failed.'));
}
});
after(killFork);
it('http://localhost should 404', function (done) {
request.get('/')
@ -626,26 +628,17 @@ describe('Frontend Routing', function () {
});
describe('Subdirectory (with slash)', function () {
var forkedGhost, request;
before(function (done) {
testUtils.fork.ghost({
url: 'http://localhost/blog/'
}, 'testsubdir')
.then(function (child) {
forkedGhost = child;
request = require('supertest');
request = request('http://localhost:' + child.port);
request = supertest.agent('http://localhost:' + child.port);
}).then(done).catch(done);
});
after(function (done) {
if (forkedGhost) {
forkedGhost.kill(done);
} else {
done(new Error('No forked ghost process exists, test setup must have failed.'));
}
});
after(killFork);
it('http://localhost should 404', function (done) {
request.get('/')
@ -717,8 +710,6 @@ describe('Frontend Routing', function () {
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
describe('HTTPS', function () {
var forkedGhost, request;
before(function (done) {
testUtils.fork.ghost({
url: 'http://localhost:2370/',
@ -728,18 +719,11 @@ describe('Frontend Routing', function () {
}, 'testhttps')
.then(function (child) {
forkedGhost = child;
request = require('supertest');
request = request('http://localhost:2370');
request = supertest.agent('http://localhost:2370');
}).then(done).catch(done);
});
after(function (done) {
if (forkedGhost) {
forkedGhost.kill(done);
} else {
done(new Error('No forked ghost process exists, test setup must have failed.'));
}
});
after(killFork);
it('should set links to url over non-HTTPS', function (done) {
request.get('/')
@ -760,8 +744,6 @@ describe('Frontend Routing', function () {
});
describe('Redirects (use redirects.json from test/utils/fixtures/data)', function () {
var forkedGhost, request;
before(function (done) {
testUtils.fork.ghost({
url: 'http://localhost:2370/',
@ -774,18 +756,11 @@ describe('Frontend Routing', function () {
}, 'testredirects')
.then(function (child) {
forkedGhost = child;
request = require('supertest');
request = request('http://localhost:2370');
request = supertest.agent('http://localhost:2370');
}).then(done).catch(done);
});
after(function (done) {
if (forkedGhost) {
forkedGhost.kill(done);
} else {
done(new Error('No forked ghost process exists, test setup must have failed.'));
}
});
after(killFork);
describe('1 case', function () {
it('with trailing slash', function (done) {

View File

@ -1,11 +1,11 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
var should = require('should'),
testUtils = require('../../utils'),
_ = require('lodash'),
// Stuff we are testing
PostAPI = require('../../../server/api/posts'),
TagAPI = require('../../../server/api/tags'),
UserAPI = require('../../../server/api/users');
PostAPI = require('../../../server/api/posts'),
TagAPI = require('../../../server/api/tags'),
UserAPI = require('../../../server/api/users');
describe('Advanced Browse', function () {
// Initialise the DB just once, the tests are fetch-only
@ -20,7 +20,11 @@ describe('Advanced Browse', function () {
describe('Advanced Use Cases', function () {
describe('1. Posts - filter: "tags: [photo, video] + id: -4", limit: "3", include: "tags"', function () {
it('Will fetch 3 posts with tags which match `photo` or `video` and are not the post with id 4.', function (done) {
PostAPI.browse({filter: 'tags: [photo, video] + id: -' + testUtils.filterData.data.posts[3].id, limit: 3, include: 'tags'}).then(function (result) {
PostAPI.browse({
filter: 'tags: [photo, video] + id: -' + testUtils.filterData.data.posts[3].id,
limit: 3,
include: 'tags'
}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);
@ -69,7 +73,10 @@ describe('Advanced Browse', function () {
describe('2. Posts - filter: "tag:photo,featured:true,image:-null", include: "tags"', function () {
it('Will fetch posts which have either a tag of `photo`, are marked `featured` or have an image.', function (done) {
PostAPI.browse({filter: 'tag:photo,featured:true,image:-null', include: 'tags'}).then(function (result) {
PostAPI.browse({
filter: 'tag:photo,featured:true,image:-null',
include: 'tags'
}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
@ -119,7 +126,12 @@ describe('Advanced Browse', function () {
describe.skip('3. Tags - filter="count.posts:>=1" order="count.posts DESC" limit="all"', function () {
// @TODO add support for counts/aggregates in order & filter params
it('Will fetch all tags, ordered by post count, where the post count is at least 1.', function (done) {
TagAPI.browse({filter: 'count.posts:>=1', order: 'count.posts DESC', limit: 'all', include: 'count.posts'}).then(function (result) {
TagAPI.browse({
filter: 'count.posts:>=1',
order: 'count.posts DESC',
limit: 'all',
include: 'count.posts'
}).then(function (result) {
// 1. Result should have the correct base structure
should.exist(result);
result.should.have.property('tags');
@ -145,7 +157,10 @@ describe('Advanced Browse', function () {
describe('4. Posts - filter="author:[leslie,pat]+(tag:audio,image:-null)"', function () {
// Note that `pat` doesn't exist (it's `pat-smith`)
it('Will fetch posts by the author `leslie` or `pat` which are either have tag `audio` or an image.', function (done) {
PostAPI.browse({filter: 'author:[leslie,pat]+(tag:audio,image:-null)', include: 'author,tags'}).then(function (result) {
PostAPI.browse({
filter: 'author:[leslie,pat]+(tag:audio,image:-null)',
include: 'author,tags'
}).then(function (result) {
var ids, authors;
// 1. Result should have the correct base structure
should.exist(result);
@ -202,7 +217,11 @@ describe('Advanced Browse', function () {
describe.skip('5. Users - filter="posts.tags:photo" order="count.posts DESC" limit="3"', function () {
// @TODO: add support for joining through posts and tags for users
it('Will fetch the 3 most prolific users who write posts with the tag `photo` ordered by most posts.', function (done) {
UserAPI.browse({filter: 'posts.tags:special', order: 'count.posts DESC', limit: 3}).then(function (result) {
UserAPI.browse({
filter: 'posts.tags:special',
order: 'count.posts DESC',
limit: 3
}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);
@ -240,7 +259,11 @@ describe('Advanced Browse', function () {
describe.skip('6. Posts filter="published_at:>\'2015-07-20\'" limit="5"}}', function () {
it('Will fetch 5 posts after a given date.', function (done) {
PostAPI.browse({filter: 'published_at:>\'2015-07-20\'', limit: 5, include: 'tags'}).then(function (result) {
PostAPI.browse({
filter: 'published_at:>\'2015-07-20\'',
limit: 5,
include: 'tags'
}).then(function (result) {
// 1. Result should have the correct base structure
should.exist(result);
result.should.have.property('posts');
@ -597,7 +620,12 @@ describe('Advanced Browse', function () {
});
it('Will fetch posts with a given author', function (done) {
PostAPI.browse({filter: 'author:leslie', include: 'tag,author', limit: 5, page: 2}).then(function (result) {
PostAPI.browse({
filter: 'author:leslie',
include: 'tag,author',
limit: 5,
page: 2
}).then(function (result) {
var ids;
// 1. Result should have the correct base structure
should.exist(result);

View File

@ -1,18 +1,19 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
sinon = require('sinon'),
Promise = require('bluebird'),
uid = require('../../../server/utils').uid,
AuthAPI = require('../../../server/api/authentication'),
mail = require('../../../server/api/mail'),
models = require('../../../server/models'),
errors = require('../../../server/errors'),
sandbox = sinon.sandbox.create(),
context = testUtils.context,
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
_ = require('lodash'),
Promise = require('bluebird'),
uid = require('../../../server/utils').uid,
AuthAPI = require('../../../server/api/authentication'),
mail = require('../../../server/api/mail'),
models = require('../../../server/models'),
errors = require('../../../server/errors'),
context = testUtils.context,
Accesstoken,
Refreshtoken,
User;
User,
sandbox = sinon.sandbox.create();
describe('Authentication API', function () {
var testInvite = {
@ -254,7 +255,10 @@ describe('Authentication API', function () {
it('should allow an invitation to be accepted', function () {
var invite;
return models.Invite.add({email: '123@meins.de', role_id: testUtils.DataGenerator.Content.roles[0].id}, context.internal)
return models.Invite.add({
email: '123@meins.de',
role_id: testUtils.DataGenerator.Content.roles[0].id
}, context.internal)
.then(function (_invite) {
invite = _invite;
invite.toJSON().role_id.should.eql(testUtils.DataGenerator.Content.roles[0].id);
@ -298,7 +302,8 @@ describe('Authentication API', function () {
return models.Invite.edit({
status: 'sent',
expires: Date.now() - 10000}, _.merge({}, {id: invite.id}, context.internal));
expires: Date.now() - 10000
}, _.merge({}, {id: invite.id}, context.internal));
})
.then(function () {
return AuthAPI.acceptInvitation({
@ -333,8 +338,8 @@ describe('Authentication API', function () {
it('should not generate a password reset token for an invalid email address', function (done) {
var badResetRequest = {
passwordreset: [{email: ''}]
};
passwordreset: [{email: ''}]
};
AuthAPI.generateResetToken(badResetRequest).then(function () {
done(new Error('reset token was generated for invalid email address'));
@ -499,11 +504,11 @@ describe('Authentication API', function () {
it('should not allow setup to be updated', function (done) {
var setupData = {
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
AuthAPI.updateSetup({setup: [setupData]}, {}).then(function () {
done(new Error('Update was able to be run'));
@ -532,11 +537,11 @@ describe('Authentication API', function () {
it('should not allow setup to be updated', function (done) {
var setupData = {
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
AuthAPI.updateSetup({setup: [setupData]}, context.author).then(function () {
done(new Error('Update was able to be run'));
@ -565,11 +570,11 @@ describe('Authentication API', function () {
it('should allow setup to be updated', function (done) {
var setupData = {
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
name: 'test user',
email: 'test@example.com',
password: 'areallygoodpassword',
blogTitle: 'a test blog'
};
AuthAPI.updateSetup({setup: [setupData]}, context.owner).then(function (result) {
should.exist(result);

View File

@ -1,7 +1,7 @@
var testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
rewire = require('rewire'),
configUtils = require('../../utils/configUtils'),
// Stuff we are testing
ConfigurationAPI = rewire('../../../server/api/configuration');

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
dbAPI = require('../../../server/api/db'),
ModelTag = require('../../../server/models/tag'),
ModelPost = require('../../../server/models/post');
var should = require('should'),
testUtils = require('../../utils'),
_ = require('lodash'),
dbAPI = require('../../../server/api/db'),
ModelTag = require('../../../server/models/tag'),
ModelPost = require('../../../server/models/post');
describe('DB API', function () {
// Keep the DB clean

View File

@ -1,6 +1,6 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
Promise = require('bluebird'),
@ -8,6 +8,7 @@ var testUtils = require('../../utils'),
mail = require('../../../server/api/mail'),
errors = require('../../../server/errors'),
context = testUtils.context,
sandbox = sinon.sandbox.create();
describe('Invites API', function () {

View File

@ -1,6 +1,6 @@
var should = require('should'),
_ = require('lodash'),
testUtils = require('../../utils'),
_ = require('lodash'),
configUtils = require('../../utils/configUtils'),
i18n = require('../../../../core/server/i18n'),
mailData = {

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
var should = require('should'),
testUtils = require('../../utils'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
NotificationsAPI = require('../../../server/api/notifications'),
SettingsAPI = require('../../../server/api/settings');
SettingsAPI = require('../../../server/api/settings');
describe('Notifications API', function () {
// Keep the DB clean
@ -166,7 +166,7 @@ describe('Notifications API', function () {
var notification = result.notifications[0];
NotificationsAPI.destroy(
_.extend({}, testUtils.context.internal, {id: notification.id})
_.extend({}, testUtils.context.internal, {id: notification.id})
).then(function () {
return SettingsAPI.read(_.extend({key: 'seenNotifications'}, testUtils.context.internal));
}).then(function (response) {

View File

@ -1,16 +1,17 @@
var Promise = require('bluebird'),
should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils'),
errors = require('../../../server/errors'),
db = require('../../../server/data/db'),
models = require('../../../server/models'),
PostAPI = require('../../../server/api/posts'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
_ = require('lodash'),
ObjectId = require('bson-objectid'),
Promise = require('bluebird'),
configUtils = require('../../utils/configUtils'),
errors = require('../../../server/errors'),
db = require('../../../server/data/db'),
models = require('../../../server/models'),
PostAPI = require('../../../server/api/posts'),
settingsCache = require('../../../server/settings/cache'),
sandbox = sinon.sandbox.create();
sandbox = sinon.sandbox.create();
describe('Post API', function () {
var localSettingsCache = {};
@ -23,7 +24,7 @@ describe('Post API', function () {
// we insert the posts via the model layer, because right now the test utils insert dates wrong
beforeEach(function (done) {
Promise.mapSeries(testUtils.DataGenerator.forKnex.posts, function (post) {
return models.Post.add(post, {context: {internal:true}});
return models.Post.add(post, {context: {internal: true}});
}).then(function () {
done();
}).catch(done);
@ -31,7 +32,7 @@ describe('Post API', function () {
beforeEach(function (done) {
Promise.mapSeries(testUtils.DataGenerator.forKnex.tags, function (tag) {
return models.Tag.add(tag, {context: {internal:true}});
return models.Tag.add(tag, {context: {internal: true}});
}).then(function () {
done();
}).catch(done);
@ -106,7 +107,10 @@ describe('Post API', function () {
});
it('can exclude featured posts for user 1', function (done) {
PostAPI.browse(_.merge({status: 'all', filter: 'featured:false'}, testUtils.context.owner)).then(function (results) {
PostAPI.browse(_.merge({
status: 'all',
filter: 'featured:false'
}, testUtils.context.owner)).then(function (results) {
should.exist(results.posts);
results.posts.length.should.eql(1);
results.posts[0].featured.should.eql(false);
@ -290,7 +294,12 @@ describe('Post API', function () {
});
it('can fetch all posts for a tag', function (done) {
PostAPI.browse({context: {user: 1}, status: 'all', filter: 'tags:kitchen-sink', include: 'tags'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
filter: 'tags:kitchen-sink',
include: 'tags'
}).then(function (results) {
results.posts.length.should.be.eql(2);
_.each(results.posts, function (post) {
@ -323,7 +332,12 @@ describe('Post API', function () {
});
it('can fetch all posts for an author', function (done) {
PostAPI.browse({context: {user: 1}, status: 'all', filter: 'author:joe-bloggs', include: 'author'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
filter: 'author:joe-bloggs',
include: 'author'
}).then(function (results) {
should.exist(results.posts);
results.posts.length.should.eql(6);
@ -370,7 +384,12 @@ describe('Post API', function () {
});
it('with context.user can fetch multiple fields', function (done) {
PostAPI.browse({context: {user: 1}, status: 'all', limit: 5, fields: 'slug,published_at'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
limit: 5,
fields: 'slug,published_at'
}).then(function (results) {
should.exist(results.posts);
should.exist(results.posts[0].published_at);
@ -394,7 +413,12 @@ describe('Post API', function () {
});
it('with context.user can fetch multiple fields and be case insensitive', function (done) {
PostAPI.browse({context: {user: 1}, status: 'all', limit: 5, fields: 'Slug,Published_At'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
limit: 5,
fields: 'Slug,Published_At'
}).then(function (results) {
should.exist(results.posts);
should.exist(results.posts[0].published_at);
@ -406,7 +430,12 @@ describe('Post API', function () {
});
it('with context.user can fetch multiple fields ignoring spaces', function (done) {
PostAPI.browse({context: {user: 1}, status: 'all', limit: 5, fields: ' slug , published_at '}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
limit: 5,
fields: ' slug , published_at '
}).then(function (results) {
should.exist(results.posts);
should.exist(results.posts[0].published_at);
@ -437,7 +466,12 @@ describe('Post API', function () {
posts = _(testUtils.DataGenerator.Content.posts).reject('page').value();
expectedTitles = _(posts).map('title').sortBy().value();
PostAPI.browse({context: {user: 1}, status: 'all', order: 'title asc', fields: 'title'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
order: 'title asc',
fields: 'title'
}).then(function (results) {
should.exist(results.posts);
var titles = _.map(results.posts, 'title');
@ -453,7 +487,12 @@ describe('Post API', function () {
posts = _(testUtils.DataGenerator.Content.posts).reject('page').value();
expectedTitles = _(posts).map('title').sortBy().reverse().value();
PostAPI.browse({context: {user: 1}, status: 'all', order: 'title DESC', fields: 'title'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
order: 'title DESC',
fields: 'title'
}).then(function (results) {
should.exist(results.posts);
var titles = _.map(results.posts, 'title');
@ -469,7 +508,12 @@ describe('Post API', function () {
posts = _(testUtils.DataGenerator.Content.posts).reject('page').value();
expectedTitles = _(posts).map('title').sortBy().value();
PostAPI.browse({context: {user: 1}, status: 'all', order: 'bunny DESC, title ASC', fields: 'title'}).then(function (results) {
PostAPI.browse({
context: {user: 1},
status: 'all',
order: 'bunny DESC, title ASC',
fields: 'title'
}).then(function (results) {
should.exist(results.posts);
var titles = _.map(results.posts, 'title');
@ -547,7 +591,11 @@ describe('Post API', function () {
});
it('can fetch post with by id', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[1].id, status: 'all'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[1].id,
status: 'all'
}).then(function (results) {
should.exist(results.posts);
results.posts[0].id.should.eql(testUtils.DataGenerator.Content.posts[1].id);
results.posts[0].slug.should.eql('ghostly-kitchen-sink');
@ -556,7 +604,11 @@ describe('Post API', function () {
});
it('can include tags', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'tags'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'tags'
}).then(function (results) {
should.exist(results.posts[0].tags);
results.posts[0].tags[0].slug.should.eql('chorizo');
done();
@ -564,7 +616,11 @@ describe('Post API', function () {
});
it('can include author', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[1].id, include: 'author'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[1].id,
include: 'author'
}).then(function (results) {
should.exist(results.posts[0].author.name);
results.posts[0].author.name.should.eql('Joe Bloggs');
done();
@ -572,7 +628,11 @@ describe('Post API', function () {
});
it('can include next post', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'next'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'next'
}).then(function (results) {
should.exist(results.posts[0].next.slug);
results.posts[0].next.slug.should.eql('not-so-short-bit-complex');
done();
@ -580,7 +640,11 @@ describe('Post API', function () {
});
it('can include next post with author and tags', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'next,next.tags,next.author'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'next,next.tags,next.author'
}).then(function (results) {
should.exist(results.posts[0].next.slug);
results.posts[0].next.slug.should.eql('not-so-short-bit-complex');
results.posts[0].next.author.should.be.an.Object();
@ -590,7 +654,11 @@ describe('Post API', function () {
});
it('can include next post with just tags', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[1].id, include: 'next,next.tags'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[1].id,
include: 'next,next.tags'
}).then(function (results) {
should.exist(results.posts[0].next.slug);
results.posts[0].next.slug.should.eql('short-and-sweet');
results.posts[0].next.author.should.eql('1');
@ -601,7 +669,11 @@ describe('Post API', function () {
});
it('can include previous post', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'previous'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'previous'
}).then(function (results) {
should.exist(results.posts[0].previous.slug);
results.posts[0].previous.slug.should.eql('ghostly-kitchen-sink');
done();
@ -609,7 +681,11 @@ describe('Post API', function () {
});
it('can include previous post with author and tags', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'previous,previous.author,previous.tags'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'previous,previous.author,previous.tags'
}).then(function (results) {
should.exist(results.posts[0].previous.slug);
results.posts[0].previous.slug.should.eql('ghostly-kitchen-sink');
results.posts[0].previous.author.should.be.an.Object();
@ -622,7 +698,11 @@ describe('Post API', function () {
});
it('can include previous post with just author', function (done) {
PostAPI.read({context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[2].id, include: 'previous,previous.author'}).then(function (results) {
PostAPI.read({
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[2].id,
include: 'previous,previous.author'
}).then(function (results) {
should.exist(results.posts[0].previous.slug);
should.not.exist(results.posts[0].previous.tags);
results.posts[0].previous.slug.should.eql('ghostly-kitchen-sink');
@ -647,7 +727,10 @@ describe('Post API', function () {
describe('Destroy', function () {
it('can delete a post', function (done) {
var options = {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id};
var options = {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
};
PostAPI.read(options).then(function (results) {
should.exist(results.posts[0]);
@ -679,7 +762,10 @@ describe('Post API', function () {
describe('Edit', function () {
it('can edit own post', function (done) {
PostAPI.edit({posts:[{status: 'test'}]}, {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id}).then(function (results) {
PostAPI.edit({posts: [{status: 'test'}]}, {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
}).then(function (results) {
should.exist(results.posts);
done();
}).catch(done);
@ -688,7 +774,10 @@ describe('Post API', function () {
it('cannot edit others post', function (done) {
PostAPI.edit(
{posts: [{status: 'test'}]},
{context: {user: testUtils.DataGenerator.Content.users[3].id}, id: testUtils.DataGenerator.Content.posts[0].id}
{
context: {user: testUtils.DataGenerator.Content.users[3].id},
id: testUtils.DataGenerator.Content.posts[0].id
}
).then(function () {
done(new Error('expected permission error'));
}).catch(function (err) {
@ -700,7 +789,10 @@ describe('Post API', function () {
// These tests are for #6920
it('should update post & not delete tags with `tags` not included', function (done) {
var options = {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id},
var options = {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
},
includeOptions = {include: 'tags'},
startTags;
@ -740,7 +832,10 @@ describe('Post API', function () {
});
it('should update post & not delete tags with `tags` set to undefined', function (done) {
var options = {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id},
var options = {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
},
includeOptions = {include: 'tags'},
startTags;
@ -780,7 +875,10 @@ describe('Post API', function () {
});
it('should update post & not delete tags with `tags` set to null', function (done) {
var options = {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id},
var options = {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
},
includeOptions = {include: 'tags'},
startTags;
@ -820,7 +918,10 @@ describe('Post API', function () {
});
it('should update post & should delete tags with `tags` set to []', function (done) {
var options = {context: {user: testUtils.DataGenerator.Content.users[1].id}, id: testUtils.DataGenerator.Content.posts[0].id},
var options = {
context: {user: testUtils.DataGenerator.Content.users[1].id},
id: testUtils.DataGenerator.Content.posts[0].id
},
includeOptions = {include: 'tags'};
// Step 1, fetch a post from the API with tags

View File

@ -1,8 +1,8 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
RoleAPI = require('../../../server/api/roles'),
context = testUtils.context;
var should = require('should'),
testUtils = require('../../utils'),
_ = require('lodash'),
RoleAPI = require('../../../server/api/roles'),
context = testUtils.context;
describe('Roles API', function () {
// Keep the DB clean

View File

@ -1,8 +1,8 @@
var should = require('should'),
testUtils = require('../../utils'),
moment = require('moment'),
Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
testUtils = require('../../utils'),
config = require(__dirname + '/../../../server/config'),
sequence = require(config.get('paths').corePath + '/server/utils/sequence'),
errors = require(config.get('paths').corePath + '/server/errors'),

View File

@ -1,12 +1,12 @@
var testUtils = require('../../utils'),
should = require('should'),
_ = require('lodash'),
var should = require('should'),
testUtils = require('../../utils'),
_ = require('lodash'),
// Stuff we are testing
SettingsAPI = require('../../../server/api/settings'),
settingsCache = require('../../../server/settings/cache'),
defaultContext = {user: 1},
internalContext = {internal: true},
SettingsAPI = require('../../../server/api/settings'),
settingsCache = require('../../../server/settings/cache'),
defaultContext = {user: 1},
internalContext = {internal: true},
callApiWithContext,
getErrorDetails;
@ -51,7 +51,9 @@ describe('Settings API', function () {
testUtils.API.checkResponse(results.settings[0], 'setting');
// Check for a core setting
should.not.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
should.not.exist(_.find(results.settings, function (setting) {
return setting.type === 'core';
}));
}).catch(getErrorDetails);
});
@ -63,7 +65,9 @@ describe('Settings API', function () {
testUtils.API.checkResponse(results.settings[0], 'setting');
// Check for a core setting
should.not.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
should.not.exist(_.find(results.settings, function (setting) {
return setting.type === 'core';
}));
}).catch(getErrorDetails);
});
@ -75,7 +79,9 @@ describe('Settings API', function () {
testUtils.API.checkResponse(results.settings[0], 'setting');
// Check for a core setting
should.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
should.exist(_.find(results.settings, function (setting) {
return setting.type === 'core';
}));
}).catch(getErrorDetails);
});
@ -89,7 +95,7 @@ describe('Settings API', function () {
});
it('cannot read core settings if not an internal request', function () {
return callApiWithContext(defaultContext, 'read', {key: 'dbHash'}).then(function () {
return callApiWithContext(defaultContext, 'read', {key: 'dbHash'}).then(function () {
throw new Error('Allowed to read dbHash with external request');
}).catch(function (error) {
should.exist(error);

View File

@ -1,7 +1,7 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
SlugAPI = require('../../../server/api/slugs');
SlugAPI = require('../../../server/api/slugs');
describe('Slug API', function () {
// Keep the DB clean
@ -14,57 +14,57 @@ describe('Slug API', function () {
it('can generate post slug', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'post', name: 'A fancy Title'})
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('a-fancy-title');
done();
}).catch(done);
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('a-fancy-title');
done();
}).catch(done);
});
it('can generate tag slug', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'tag', name: 'A fancy Title'})
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('a-fancy-title');
done();
}).catch(done);
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('a-fancy-title');
done();
}).catch(done);
});
it('can generate user slug', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'user', name: 'user name'})
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('user-name');
done();
}).catch(done);
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('user-name');
done();
}).catch(done);
});
it('can generate app slug', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'tag', name: 'app name'})
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('app-name');
done();
}).catch(done);
.then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'slugs');
results.slugs.length.should.be.above(0);
testUtils.API.checkResponse(results.slugs[0], 'slug');
results.slugs[0].slug.should.equal('app-name');
done();
}).catch(done);
});
it('rejects unknown types with BadRequestError', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'unknown-type', name: 'A fancy Title'})
.then(function () {
done(new Error('Generate a slug for an unknown type is not rejected.'));
}).catch(function (error) {
.then(function () {
done(new Error('Generate a slug for an unknown type is not rejected.'));
}).catch(function (error) {
error.errorType.should.equal('BadRequestError');
done();
}).catch(done);
@ -72,9 +72,9 @@ describe('Slug API', function () {
it('rejects invalid types with ValidationError', function (done) {
SlugAPI.generate({context: {user: 1}, type: 'unknown type', name: 'A fancy Title'})
.then(function () {
done(new Error('Generate a slug for an unknown type is not rejected.'));
}).catch(function (errors) {
.then(function () {
done(new Error('Generate a slug for an unknown type is not rejected.'));
}).catch(function (errors) {
errors.should.have.property('errorType', 'ValidationError');
done();
}).catch(done);

View File

@ -1,20 +1,25 @@
var testUtils = require('../../utils'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
fs = require('fs'),
_ = require('lodash'),
context = testUtils.context,
errors = require('../../../server/errors'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
fs = require('fs'),
_ = require('lodash'),
context = testUtils.context,
errors = require('../../../server/errors'),
serverUtils = require('../../../server/utils'),
apiUtils = require('../../../server/api/utils'),
SubscribersAPI = require('../../../server/api/subscribers');
apiUtils = require('../../../server/api/utils'),
SubscribersAPI = require('../../../server/api/subscribers'),
sandbox = sinon.sandbox.create();
describe('Subscribers API', function () {
// Keep the DB clean
before(testUtils.teardown);
afterEach(testUtils.teardown);
afterEach(function () {
sandbox.restore();
});
beforeEach(testUtils.setup('users:roles', 'perms:subscriber', 'perms:init', 'posts', 'subscriber'));
should.exist(SubscribersAPI);
@ -93,7 +98,7 @@ describe('Subscribers API', function () {
describe('Edit', function () {
var newSubscriberEmail = 'subscriber@updated.com',
firstSubscriber = testUtils.DataGenerator.Content.subscribers[0].id;
firstSubscriber = testUtils.DataGenerator.Content.subscribers[0].id;
it('can edit a subscriber (admin)', function (done) {
SubscribersAPI.edit({subscribers: [{email: newSubscriberEmail}]}, _.extend({}, context.admin, {id: firstSubscriber}))
@ -238,12 +243,12 @@ describe('Subscribers API', function () {
stub;
beforeEach(function () {
sinon.stub(fs, 'unlink', function (path, cb) {
sandbox.stub(fs, 'unlink', function (path, cb) {
cb();
});
sinon.stub(apiUtils, 'checkFileExists').returns(true);
stub = sinon.stub(apiUtils, 'checkFileIsValid').returns(true);
sinon.stub(serverUtils, 'readCSV', function () {
sandbox.stub(apiUtils, 'checkFileExists').returns(true);
stub = sandbox.stub(apiUtils, 'checkFileIsValid').returns(true);
sandbox.stub(serverUtils, 'readCSV', function () {
if (scope.csvError) {
return Promise.reject(new Error('csv'));
}
@ -253,15 +258,11 @@ describe('Subscribers API', function () {
});
afterEach(function () {
fs.unlink.restore();
apiUtils.checkFileExists.restore();
apiUtils.checkFileIsValid.restore();
serverUtils.readCSV.restore();
scope.csvError = false;
});
it('check that fn works in general', function (done) {
scope.values = [{email: 'lol@hallo.de'}, {email: 'test'}, {email:'lol@hallo.de'}];
scope.values = [{email: 'lol@hallo.de'}, {email: 'test'}, {email: 'lol@hallo.de'}];
SubscribersAPI.importCSV(_.merge(testUtils.context.internal, {path: '/somewhere'}))
.then(function (result) {

View File

@ -1,11 +1,11 @@
var testUtils = require('../../utils'),
should = require('should'),
Promise = require('bluebird'),
_ = require('lodash'),
var should = require('should'),
testUtils = require('../../utils'),
Promise = require('bluebird'),
_ = require('lodash'),
// Stuff we are testing
context = testUtils.context,
context = testUtils.context,
TagAPI = require('../../../server/api/tags');
TagAPI = require('../../../server/api/tags');
// there are some random generated tags in test database
// which can't be sorted easily using _.sortBy()
@ -68,9 +68,9 @@ describe('Tags API', function () {
.then(function () {
done(new Error('Adding a tag with an invalid name is not rejected.'));
}).catch(function (errors) {
errors.should.have.enumerable(0).with.property('errorType', 'ValidationError');
done();
}).catch(done);
errors.should.have.enumerable(0).with.property('errorType', 'ValidationError');
done();
}).catch(done);
});
});
@ -100,11 +100,11 @@ describe('Tags API', function () {
it('No-auth CANNOT edit tag', function (done) {
TagAPI.edit({tags: [{name: newTagName}]}, _.extend({}, {id: firstTag}))
.then(function () {
done(new Error('Add tag is not denied without authentication.'));
}, function () {
done();
}).catch(done);
.then(function () {
done(new Error('Add tag is not denied without authentication.'));
}, function () {
done();
}).catch(done);
});
it('rejects invalid names with ValidationError', function (done) {
@ -114,9 +114,9 @@ describe('Tags API', function () {
.then(function () {
done(new Error('Adding a tag with an invalid name is not rejected.'));
}).catch(function (errors) {
errors.should.have.enumerable(0).with.property('errorType', 'ValidationError');
done();
}).catch(done);
errors.should.have.enumerable(0).with.property('errorType', 'ValidationError');
done();
}).catch(done);
});
});

View File

@ -1,17 +1,18 @@
var testUtils = require('../../utils'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
models = require('../../../server/models'),
errors = require('../../../server/errors'),
events = require('../../../server/events'),
UserAPI = require('../../../server/api/users'),
db = require('../../../server/data/db'),
sandbox = sinon.sandbox.create(),
context = testUtils.context,
userIdFor = testUtils.users.ids,
roleIdFor = testUtils.roles.ids;
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
Promise = require('bluebird'),
_ = require('lodash'),
models = require('../../../server/models'),
errors = require('../../../server/errors'),
events = require('../../../server/events'),
UserAPI = require('../../../server/api/users'),
db = require('../../../server/data/db'),
context = testUtils.context,
userIdFor = testUtils.users.ids,
roleIdFor = testUtils.roles.ids,
sandbox = sinon.sandbox.create();
describe('Users API', function () {
var eventsTriggered;
@ -120,7 +121,10 @@ describe('Users API', function () {
});
it('Can browse with roles', function (done) {
UserAPI.browse(_.extend({}, testUtils.context.admin, {status: 'all', include: 'roles'})).then(function (response) {
UserAPI.browse(_.extend({}, testUtils.context.admin, {
status: 'all',
include: 'roles'
})).then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'users');
should.exist(response.users);
@ -310,17 +314,17 @@ describe('Users API', function () {
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.owner, {id: userIdFor.admin}));
}).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.owner, {id: userIdFor.editor}));
}).then(function (response) {
checkEditResponse(response);
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.owner, {id: userIdFor.editor}));
}).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.owner, {id: userIdFor.author}));
}).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.owner, {id: userIdFor.author}));
}).then(function (response) {
checkEditResponse(response);
done();
}).catch(done);
done();
}).catch(done);
});
it('Admin can edit Admin, Editor and Author roles', function (done) {
@ -329,14 +333,14 @@ describe('Users API', function () {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.admin, {id: userIdFor.editor}));
}).then(function (response) {
checkEditResponse(response);
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.admin, {id: userIdFor.author}));
}).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName}]}, _.extend({}, context.admin, {id: userIdFor.author}));
}).then(function (response) {
checkEditResponse(response);
done();
}).catch(done);
done();
}).catch(done);
});
it('Admin CANNOT edit Owner role', function (done) {
@ -344,19 +348,34 @@ describe('Users API', function () {
.then(function () {
done(new Error('Admin should not be able to edit owner account'));
}).catch(function (error) {
error.errorType.should.eql('NoPermissionError');
done();
});
error.errorType.should.eql('NoPermissionError');
done();
});
});
it('Admin can edit Admin, Editor and Author roles with roles in payload', function (done) {
UserAPI.edit({users: [{name: newName, roles: [roleIdFor.admin]}]}, _.extend({}, context.admin, {id: userIdFor.admin})).then(function (response) {
UserAPI.edit({
users: [{
name: newName,
roles: [roleIdFor.admin]
}]
}, _.extend({}, context.admin, {id: userIdFor.admin})).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName, roles: [roleIdFor.editor]}]}, _.extend({}, context.admin, {id: userIdFor.editor}));
return UserAPI.edit({
users: [{
name: newName,
roles: [roleIdFor.editor]
}]
}, _.extend({}, context.admin, {id: userIdFor.editor}));
}).then(function (response) {
checkEditResponse(response);
return UserAPI.edit({users: [{name: newName, roles: [roleIdFor.author]}]}, _.extend({}, context.admin, {id: userIdFor.author}));
return UserAPI.edit({
users: [{
name: newName,
roles: [roleIdFor.author]
}]
}, _.extend({}, context.admin, {id: userIdFor.author}));
}).then(function (response) {
checkEditResponse(response);
@ -452,7 +471,12 @@ describe('Users API', function () {
it('Author can edit self with role set', function (done) {
// Next test that author CAN edit self
UserAPI.edit(
{users: [{name: newName, roles: [roleIdFor.author]}]}, _.extend({}, context.author, {id: userIdFor.author})
{
users: [{
name: newName,
roles: [roleIdFor.author]
}]
}, _.extend({}, context.author, {id: userIdFor.author})
).then(function (response) {
checkEditResponse(response);
done();
@ -462,7 +486,12 @@ describe('Users API', function () {
it('Author can edit self with role set as string', function (done) {
// Next test that author CAN edit self
UserAPI.edit(
{users: [{name: newName, roles: [roleIdFor.author.toString()]}]}, _.extend({}, context.author, {id: userIdFor.author})
{
users: [{
name: newName,
roles: [roleIdFor.author.toString()]
}]
}, _.extend({}, context.author, {id: userIdFor.author})
).then(function (response) {
checkEditResponse(response);
done();
@ -471,7 +500,12 @@ describe('Users API', function () {
it('Does not allow password to be set', function (done) {
UserAPI.edit(
{users: [{name: 'newname', password: 'newpassword'}]}, _.extend({}, context.author, {id: userIdFor.author})
{
users: [{
name: 'newname',
password: 'newpassword'
}]
}, _.extend({}, context.author, {id: userIdFor.author})
).then(function () {
return models.User.findOne({id: userIdFor.author}).then(function (response) {
response.get('name').should.eql('newname');
@ -876,15 +910,15 @@ describe('Users API', function () {
// Editor
return UserAPI.destroy(_.extend({}, context.owner, {id: userIdFor.editor}));
}).then(function (response) {
should.not.exist(response);
should.not.exist(response);
// Author
return UserAPI.destroy(_.extend({}, context.owner, {id: userIdFor.author}));
}).then(function (response) {
should.not.exist(response);
// Author
return UserAPI.destroy(_.extend({}, context.owner, {id: userIdFor.author}));
}).then(function (response) {
should.not.exist(response);
done();
}).catch(done);
done();
}).catch(done);
});
});
@ -905,15 +939,15 @@ describe('Users API', function () {
// Editor
return UserAPI.destroy(_.extend({}, context.admin, {id: testUtils.DataGenerator.Content.extraUsers[1].id}));
}).then(function (response) {
should.not.exist(response);
should.not.exist(response);
// Author
return UserAPI.destroy(_.extend({}, context.admin, {id: testUtils.DataGenerator.Content.extraUsers[2].id}));
}).then(function (response) {
should.not.exist(response);
// Author
return UserAPI.destroy(_.extend({}, context.admin, {id: testUtils.DataGenerator.Content.extraUsers[2].id}));
}).then(function (response) {
should.not.exist(response);
done();
}).catch(done);
done();
}).catch(done);
});
});

View File

@ -1,11 +1,11 @@
var testUtils = require('../utils/index'),
should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../utils/index'),
_ = require('lodash'),
// Stuff we are testing
exporter = require('../../server/data/export'),
utils = require('../../server/utils'),
exporter = require('../../server/data/export'),
utils = require('../../server/utils'),
sandbox = sinon.sandbox.create();

View File

@ -1,17 +1,17 @@
var testUtils = require('../utils/index'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
moment = require('moment'),
assert = require('assert'),
_ = require('lodash'),
validator = require('validator'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../utils/index'),
Promise = require('bluebird'),
moment = require('moment'),
assert = require('assert'),
_ = require('lodash'),
validator = require('validator'),
// Stuff we are testing
db = require('../../server/data/db'),
exporter = require('../../server/data/export'),
importer = require('../../server/data/import'),
DataImporter = require('../../server/data/import/data-importer'),
db = require('../../server/data/db'),
exporter = require('../../server/data/export'),
importer = require('../../server/data/import'),
DataImporter = require('../../server/data/import/data-importer'),
knex = db.knex,
sandbox = sinon.sandbox.create();
@ -732,7 +732,7 @@ describe('Import (new test structure)', function () {
// Test the users and roles
users = importedData[0];
posts = importedData[1];
tags = importedData[2];
tags = importedData[2];
// Grab the users
// the owner user is first
@ -953,7 +953,7 @@ describe('Import (new test structure)', function () {
// Test the users and roles
users = importedData[0];
posts = importedData[1];
tags = importedData[2];
tags = importedData[2];
// Grab the users
// the owner user is first
@ -1181,7 +1181,7 @@ describe('Import (new test structure)', function () {
// Test the users and roles
users = importedData[0];
posts = importedData[1];
tags = importedData[2];
tags = importedData[2];
// Grab the users
// the owner user is first

View File

@ -1,6 +1,6 @@
var testUtils = require('../utils'),
should = require('should'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../utils'),
_ = require('lodash'),
Promise = require('bluebird'),
Models = require('../../server/models'),

View File

@ -1,15 +1,15 @@
/*jshint unused:false*/
var should = require('should'),
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
testUtils = require('../../../utils'),
Promise = require('bluebird'),
moment = require('moment'),
sinon = require('sinon'),
rewire = require('rewire'),
_ = require('lodash'),
config = require('../../../../server/config'),
testUtils = require(config.get('paths').corePath + '/test/utils'),
events = require(config.get('paths').corePath + '/server/events'),
models = require(config.get('paths').corePath + '/server/models');
models = require(config.get('paths').corePath + '/server/models'),
sandbox = sinon.sandbox.create();
describe('Models: listeners', function () {
var eventsToRemember = {},
@ -28,7 +28,7 @@ describe('Models: listeners', function () {
beforeEach(testUtils.setup('owner', 'user-token:0'));
beforeEach(function () {
sinon.stub(events, 'on', function (eventName, callback) {
sandbox.stub(events, 'on', function (eventName, callback) {
eventsToRemember[eventName] = callback;
});
@ -36,7 +36,7 @@ describe('Models: listeners', function () {
});
afterEach(function (done) {
events.on.restore();
sandbox.restore();
scope.posts = [];
testUtils.teardown(done);
});

View File

@ -1,12 +1,14 @@
var testUtils = require('../../utils'),
should = require('should'),
events = require('../../../server/events'),
utils = require('../../../server/utils'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
events = require('../../../server/events'),
utils = require('../../../server/utils'),
sinon = require('sinon'),
sandbox = sinon.sandbox.create(),
// Stuff we are testing
AccesstokenModel = require('../../../server/models/accesstoken').Accesstoken;
AccesstokenModel = require('../../../server/models/accesstoken').Accesstoken,
sandbox = sinon.sandbox.create();
describe('Accesstoken Model', function () {
// Keep the DB clean
@ -31,13 +33,13 @@ describe('Accesstoken Model', function () {
client_id: testUtils.DataGenerator.forKnex.clients[0].id,
expires: Date.now() + utils.ONE_MONTH_MS
})
.then(function (token) {
should.exist(token);
// Assert
eventSpy.calledOnce.should.be.true();
eventSpy.calledWith('token.added').should.be.true();
.then(function (token) {
should.exist(token);
// Assert
eventSpy.calledOnce.should.be.true();
eventSpy.calledWith('token.added').should.be.true();
done();
}).catch(done);
done();
}).catch(done);
});
});

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
// Stuff we are testing
AppFieldsModel = require('../../../server/models/app-field').AppField,
context = testUtils.context.admin;
AppFieldsModel = require('../../../server/models/app-field').AppField,
context = testUtils.context.admin;
describe('App Fields Model', function () {
// Keep the DB clean

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
// Stuff we are testing
AppSettingModel = require('../../../server/models/app-setting').AppSetting,
context = testUtils.context.admin;
context = testUtils.context.admin;
describe('App Setting Model', function () {
// Keep the DB clean

View File

@ -1,11 +1,11 @@
var testUtils = require('../../utils'),
should = require('should'),
sequence = require('../../../server/utils/sequence'),
_ = require('lodash'),
var should = require('should'),
testUtils = require('../../utils'),
sequence = require('../../../server/utils/sequence'),
_ = require('lodash'),
// Stuff we are testing
AppModel = require('../../../server/models/app').App,
context = testUtils.context.admin;
AppModel = require('../../../server/models/app').App,
context = testUtils.context.admin;
describe('App Model', function () {
// Keep the DB clean

View File

@ -1,5 +1,5 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
models = require('../../../server/models');
describe('Invite Model', function () {

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
// Stuff we are testing
PermissionModel = require('../../../server/models/permission').Permission,
context = testUtils.context.admin;
context = testUtils.context.admin;
describe('Permission Model', function () {
// Keep the DB clean

View File

@ -1,20 +1,20 @@
var testUtils = require('../../utils'),
should = require('should'),
moment = require('moment'),
_ = require('lodash'),
Promise = require('bluebird'),
sinon = require('sinon'),
sequence = require('../../../server/utils/sequence'),
settingsCache = require('../../../server/settings/cache'),
ghostBookshelf = require('../../../server/models/base'),
PostModel = require('../../../server/models/post').Post,
TagModel = require('../../../server/models/tag').Tag,
events = require('../../../server/events'),
errors = require('../../../server/errors'),
configUtils = require('../../utils/configUtils'),
DataGenerator = testUtils.DataGenerator,
context = testUtils.context.owner,
sandbox = sinon.sandbox.create();
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
moment = require('moment'),
_ = require('lodash'),
Promise = require('bluebird'),
sequence = require('../../../server/utils/sequence'),
settingsCache = require('../../../server/settings/cache'),
ghostBookshelf = require('../../../server/models/base'),
PostModel = require('../../../server/models/post').Post,
TagModel = require('../../../server/models/tag').Tag,
events = require('../../../server/events'),
errors = require('../../../server/errors'),
configUtils = require('../../utils/configUtils'),
DataGenerator = testUtils.DataGenerator,
context = testUtils.context.owner,
sandbox = sinon.sandbox.create();
/**
* IMPORTANT:
@ -1199,37 +1199,37 @@ describe('Post Model', function () {
// Create the second post
return PostModel.add(secondPost, context);
}).then(function (createdSecondPost) {
// Store the slug for comparison later
secondPost.slug = createdSecondPost.get('slug');
// Store the slug for comparison later
secondPost.slug = createdSecondPost.get('slug');
Object.keys(eventsTriggered).length.should.eql(1);
should.exist(eventsTriggered['post.added']);
Object.keys(eventsTriggered).length.should.eql(1);
should.exist(eventsTriggered['post.added']);
// Update with a conflicting slug from the first post
return createdSecondPost.save({
slug: firstPost.slug
}, context);
}).then(function (updatedSecondPost) {
// Should have updated from original
updatedSecondPost.get('slug').should.not.equal(secondPost.slug);
// Should not have a conflicted slug from the first
updatedSecondPost.get('slug').should.not.equal(firstPost.slug);
// Update with a conflicting slug from the first post
return createdSecondPost.save({
slug: firstPost.slug
}, context);
}).then(function (updatedSecondPost) {
// Should have updated from original
updatedSecondPost.get('slug').should.not.equal(secondPost.slug);
// Should not have a conflicted slug from the first
updatedSecondPost.get('slug').should.not.equal(firstPost.slug);
Object.keys(eventsTriggered).length.should.eql(2);
should.exist(eventsTriggered['post.edited']);
Object.keys(eventsTriggered).length.should.eql(2);
should.exist(eventsTriggered['post.edited']);
return PostModel.findOne({
id: updatedSecondPost.id,
status: 'all'
});
}).then(function (foundPost) {
// Should have updated from original
foundPost.get('slug').should.not.equal(secondPost.slug);
// Should not have a conflicted slug from the first
foundPost.get('slug').should.not.equal(firstPost.slug);
return PostModel.findOne({
id: updatedSecondPost.id,
status: 'all'
});
}).then(function (foundPost) {
// Should have updated from original
foundPost.get('slug').should.not.equal(secondPost.slug);
// Should not have a conflicted slug from the first
foundPost.get('slug').should.not.equal(firstPost.slug);
done();
}).catch(done);
done();
}).catch(done);
});
});
@ -1405,14 +1405,14 @@ describe('Post Model', function () {
// We're going to delete all posts by user 1
var authorData = {id: testUtils.DataGenerator.Content.users[0].id};
PostModel.findAll({context:{internal:true}}).then(function (found) {
PostModel.findAll({context: {internal: true}}).then(function (found) {
// There are 50 posts to begin with
found.length.should.equal(50);
return PostModel.destroyByAuthor(authorData);
}).then(function (results) {
// User 1 has 13 posts in the database
results.length.should.equal(13);
return PostModel.findAll({context:{internal:true}});
return PostModel.findAll({context: {internal: true}});
}).then(function (found) {
// Only 37 should remain
found.length.should.equal(37);
@ -1801,7 +1801,10 @@ describe('Post Model', function () {
startTags = _.cloneDeep(post.tags);
// Step 2, edit a single property of the post... we aren't doing anything with tags here...
return PostModel.edit({title: 'new title', tags: undefined}, _.extend({}, context, {id: postId}));
return PostModel.edit({
title: 'new title',
tags: undefined
}, _.extend({}, context, {id: postId}));
}).then(function (edited) {
should.exist(edited);
var post = edited.toJSON(toJSONOpts);

View File

@ -1,9 +1,9 @@
var testUtils = require('../../utils'),
should = require('should'),
var should = require('should'),
testUtils = require('../../utils'),
// Stuff we are testing
RoleModel = require('../../../server/models/role').Role,
context = testUtils.context.admin;
RoleModel = require('../../../server/models/role').Role,
context = testUtils.context.admin;
describe('Role Model', function () {
// Keep the DB clean

View File

@ -1,13 +1,13 @@
var testUtils = require('../../utils'),
should = require('should'),
sinon = require('sinon'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
// Stuff we are testing
SettingsModel = require('../../../server/models/settings').Settings,
db = require('../../../server/data/db'),
events = require('../../../server/events'),
sandbox = sinon.sandbox.create(),
context = testUtils.context.admin;
SettingsModel = require('../../../server/models/settings').Settings,
db = require('../../../server/data/db'),
events = require('../../../server/events'),
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
describe('Settings Model', function () {
var eventSpy;

View File

@ -1,15 +1,15 @@
var testUtils = require('../../utils'),
should = require('should'),
sinon = require('sinon'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
// Stuff we are testing
ModelsTag = require('../../../server/models/tag'),
ModelsPost = require('../../../server/models/post'),
events = require('../../../server/events'),
context = testUtils.context.admin,
ModelsTag = require('../../../server/models/tag'),
ModelsPost = require('../../../server/models/post'),
events = require('../../../server/events'),
context = testUtils.context.admin,
TagModel,
PostModel,
sandbox = sinon.sandbox.create();
sandbox = sinon.sandbox.create();
describe('Tag Model', function () {
var eventSpy;
@ -27,8 +27,8 @@ describe('Tag Model', function () {
});
before(function () {
TagModel = ModelsTag.Tag;
PostModel = ModelsPost.Post;
TagModel = ModelsTag.Tag;
PostModel = ModelsPost.Post;
should.exist(TagModel);
should.exist(PostModel);

View File

@ -1,17 +1,17 @@
var testUtils = require('../../utils'),
should = require('should'),
Promise = require('bluebird'),
sinon = require('sinon'),
_ = require('lodash'),
var should = require('should'),
sinon = require('sinon'),
testUtils = require('../../utils'),
Promise = require('bluebird'),
_ = require('lodash'),
// Stuff we are testing
errors = require('../../../server/errors'),
gravatar = require('../../../server/utils/gravatar'),
UserModel = require('../../../server/models/user').User,
RoleModel = require('../../../server/models/role').Role,
events = require('../../../server/events'),
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
errors = require('../../../server/errors'),
gravatar = require('../../../server/utils/gravatar'),
UserModel = require('../../../server/models/user').User,
RoleModel = require('../../../server/models/role').Role,
events = require('../../../server/events'),
context = testUtils.context.admin,
sandbox = sinon.sandbox.create();
describe('User Model', function run() {
var eventsTriggered = {};

View File

@ -1,5 +1,5 @@
var _ = require('lodash'),
should = require('should'),
var should = require('should'),
_ = require('lodash'),
rewire = require('rewire'),
uuid = require('uuid'),
testUtils = require('../utils'),

View File

@ -5,6 +5,7 @@ var should = require('should'), // jshint ignore:line
redirectAdminUrls = require('../../server/admin/middleware')[0],
sandbox = sinon.sandbox.create();
describe('Admin App', function () {
afterEach(function () {
sandbox.restore();

View File

@ -1,6 +1,5 @@
var rewire = require('rewire'),
/*jshint unused:false*/
should = require('should'),
var should = require('should'), // jshint ignore:line
rewire = require('rewire'),
NotificationAPI = rewire('../../../server/api/notifications');
describe('UNIT: Notification API', function () {

View File

@ -1,11 +1,12 @@
var should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
var should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
Promise = require('bluebird'),
ObjectId = require('bson-objectid'),
permissions = require('../../server/permissions'),
errors = require('../../server/errors'),
apiUtils = require('../../server/api/utils'),
sandbox = sinon.sandbox.create();
describe('API Utils', function () {
@ -419,7 +420,10 @@ describe('API Utils', function () {
describe('checkFileIsValid', function () {
it('returns true if file has valid extension and type', function () {
apiUtils.checkFileIsValid({name: 'test.txt', mimetype: 'text'}, ['text'], ['.txt']).should.be.true();
apiUtils.checkFileIsValid({name: 'test.jpg', mimetype: 'jpeg'}, ['text', 'jpeg'], ['.txt', '.jpg']).should.be.true();
apiUtils.checkFileIsValid({
name: 'test.jpg',
mimetype: 'jpeg'
}, ['text', 'jpeg'], ['.txt', '.jpg']).should.be.true();
});
it('returns false if file has invalid extension', function () {

View File

@ -1,17 +1,18 @@
var should = require('should'),
sinon = require('sinon'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
_ = require('lodash'),
// Stuff we are testing
Filters = require('../../server/filters').Filters;
Filters = require('../../server/filters').Filters,
sandbox = sinon.sandbox.create();
describe('Filters', function () {
var filters, sandbox;
var filters;
beforeEach(function () {
filters = new Filters();
sandbox = sinon.sandbox.create();
});
afterEach(function () {

View File

@ -1,27 +1,27 @@
var path = require('path'),
var should = require('should'),
sinon = require('sinon'),
path = require('path'),
EventEmitter = require('events').EventEmitter,
should = require('should'),
sinon = require('sinon'),
_ = require('lodash'),
Promise = require('bluebird'),
helpers = require('../../server/helpers'),
filters = require('../../server/filters'),
i18n = require('../../server/i18n'),
_ = require('lodash'),
Promise = require('bluebird'),
helpers = require('../../server/helpers'),
filters = require('../../server/filters'),
i18n = require('../../server/i18n'),
// Stuff we are testing
AppProxy = require('../../server/apps/proxy'),
AppSandbox = require('../../server/apps/sandbox'),
AppProxy = require('../../server/apps/proxy'),
AppSandbox = require('../../server/apps/sandbox'),
AppDependencies = require('../../server/apps/dependencies'),
AppPermissions = require('../../server/apps/permissions');
AppPermissions = require('../../server/apps/permissions'),
sandbox = sinon.sandbox.create();
i18n.init();
describe('Apps', function () {
var sandbox,
fakeApi;
var fakeApi;
beforeEach(function () {
sandbox = sinon.sandbox.create();
fakeApi = {
posts: {
browse: sandbox.stub(),

View File

@ -351,9 +351,11 @@ describe('Auth Strategies', function () {
var ghostAuthAccessToken = '12345',
req = {body: {}},
ownerProfile = {email: 'test@example.com', id: '12345'},
owner = {id: 2, isActive: function () {
return true;
}};
owner = {
id: 2, isActive: function () {
return true;
}
};
userFindOneStub.returns(Promise.resolve(owner));
userEditStub.withArgs({
@ -383,9 +385,11 @@ describe('Auth Strategies', function () {
var ghostAuthAccessToken = '12345',
req = {body: {}},
ownerProfile = {email: 'test@example.com', id: '12345'},
owner = {id: 2, isActive: function () {
return false;
}};
owner = {
id: 2, isActive: function () {
return false;
}
};
userFindOneStub.returns(Promise.resolve(owner));
userEditStub.withArgs({

View File

@ -1,26 +1,24 @@
var sinon = require('sinon'),
should = require('should'),
passport = require('passport'),
rewire = require('rewire'),
errors = require('../../../server/errors'),
auth = rewire('../../../server/auth'),
logging = require('../../../server/logging'),
BearerStrategy = require('passport-http-bearer').Strategy,
ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy,
user = {id: 1},
info = {scope: '*'},
token = 'test_token',
testClient = 'test_client',
testSecret = 'not_available',
client = {
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
passport = require('passport'),
rewire = require('rewire'),
errors = require('../../../server/errors'),
auth = rewire('../../../server/auth'),
logging = require('../../../server/logging'),
BearerStrategy = require('passport-http-bearer').Strategy,
ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy,
user = {id: 1},
info = {scope: '*'},
token = 'test_token',
testClient = 'test_client',
testSecret = 'not_available',
client = {
id: 2,
type: 'ua'
},
sandbox = sinon.sandbox.create();
should.equal(true, true);
function registerSuccessfulBearerStrategy() {
// register fake BearerStrategy which always authenticates
passport.use(new BearerStrategy(

View File

@ -1,5 +1,5 @@
var sinon = require('sinon'),
should = require('should'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
passport = require('passport'),
testUtils = require('../../utils'),
@ -7,17 +7,18 @@ var sinon = require('sinon'),
authUtils = require('../../../server/auth/utils'),
spamPrevention = require('../../../server/middleware/api/spam-prevention'),
errors = require('../../../server/errors'),
models = require('../../../server/models');
models = require('../../../server/models'),
sandbox = sinon.sandbox.create();
describe('OAuth', function () {
var next, req, res, sandbox;
var next, req, res;
before(function () {
models.init();
});
beforeEach(function () {
sandbox = sinon.sandbox.create();
req = {};
res = {};
next = sandbox.spy();
@ -69,7 +70,8 @@ describe('OAuth', function () {
expires_in: Date.now() + 1000
}));
sandbox.stub(res, 'setHeader', function () {});
sandbox.stub(res, 'setHeader', function () {
});
sandbox.stub(res, 'end', function (json) {
try {
@ -185,7 +187,8 @@ describe('OAuth', function () {
expires_in: Date.now() + 1000
}));
sandbox.stub(res, 'setHeader', function () {});
sandbox.stub(res, 'setHeader', function () {
});
sandbox.stub(res, 'end', function (json) {
try {

View File

@ -1,16 +1,16 @@
var passport = require('passport'),
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
passport = require('passport'),
Promise = require('bluebird'),
rewire = require('rewire'),
should = require('should'),
sandbox = sinon.sandbox.create(),
testUtils = require('../../utils'),
GhostPassport = rewire('../../../server/auth/passport'),
models = require('../../../server/models'),
utils = require('../../../server/utils'),
errors = require('../../../server/errors');
errors = require('../../../server/errors'),
should.equal(true, true);
sandbox = sinon.sandbox.create();
describe('Ghost Passport', function () {
var client, events, registeredEvents = {};
@ -60,8 +60,10 @@ describe('Ghost Passport', function () {
});
FakeGhostOAuth2Strategy.prototype.setClient = sandbox.stub();
FakeGhostOAuth2Strategy.prototype.registerClient = function () {};
FakeGhostOAuth2Strategy.prototype.updateClient = function () {};
FakeGhostOAuth2Strategy.prototype.registerClient = function () {
};
FakeGhostOAuth2Strategy.prototype.updateClient = function () {
};
sandbox.stub(FakeGhostOAuth2Strategy.prototype, 'registerClient', function (options) {
return Promise.resolve({

View File

@ -3,6 +3,7 @@ var should = require('should'),
Promise = require('bluebird'),
auth = require('../../../server/auth'),
models = require('../../../server/models'),
sandbox = sinon.sandbox.create();
describe('UNIT: auth validation', function () {

View File

@ -1,12 +1,10 @@
// jscs:disable requireDotNotation
var should = require('should'),
var should = require('should'), // jshint ignore:line
path = require('path'),
rewire = require('rewire'),
_ = require('lodash'),
configUtils = require('../../utils/configUtils');
should.equal(true, true);
// jscs:disable requireDotNotation
describe('Config', function () {
before(function () {

View File

@ -1,7 +1,5 @@
var configUtils = require('../../../server/config/utils'),
should = require('should');
should.equal(true, true);
var should = require('should'), // jshint ignore:line
configUtils = require('../../../server/config/utils');
describe('UNIT: Config utils', function () {
describe('makePathsAbsolute', function () {

View File

@ -1,5 +1,5 @@
/*jshint expr:true*/
var should = require('should'),
var should = require('should'),
channelConfig = require('../../../../server/controllers/frontend/channel-config').get;
describe('Channel Config', function () {

View File

@ -1,11 +1,11 @@
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
// Stuff we are testing
channels = require('../../../../server/controllers/frontend/channels'),
api = require('../../../../server/api'),
api = require('../../../../server/api'),
themes = require('../../../../server/themes'),
sandbox = sinon.sandbox.create();

View File

@ -1,8 +1,8 @@
var should = require('should'),
_ = require('lodash'),
var should = require('should'),
_ = require('lodash'),
// Stuff we are testing
channelConfig = require('../../../../server/controllers/frontend/channel-config'),
channelConfig = require('../../../../server/controllers/frontend/channel-config'),
setResponseContext = require('../../../../server/controllers/frontend/context');
describe('Contexts', function () {

View File

@ -1,15 +1,12 @@
var should = require('should'),
sinon = require('sinon'),
errors = require('../../../../server/errors'),
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
errors = require('../../../../server/errors'),
// Stuff we are testing
handleError = require('../../../../server/controllers/frontend/error'),
sandbox = sinon.sandbox.create();
// To stop jshint complaining
should.equal(true, true);
describe('handleError', function () {
var next;
beforeEach(function () {
@ -27,7 +24,6 @@ describe('handleError', function () {
next.calledOnce.should.be.true();
next.firstCall.args.should.be.empty();
});
it('should call next with error for other errors', function () {
var otherError = new Error();
otherError.message = 'Something wasn\'t allowed';

View File

@ -1,8 +1,8 @@
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
// Stuff we are testing
api = require('../../../../server/api'),
api = require('../../../../server/api'),
themes = require('../../../../server/themes'),
fetchData = require('../../../../server/controllers/frontend/fetch-data'),
configUtils = require('../../../utils/configUtils'),

View File

@ -1,11 +1,8 @@
var should = require('should'),
var should = require('should'), // jshint ignore:line
// Stuff we are testing
formatResponse = require('../../../../server/controllers/frontend/format-response');
// To stop jshint complaining
should.equal(true, true);
describe('formatResponse', function () {
describe('single', function () {
it('should return the post object wrapped in a post key', function () {

View File

@ -1,9 +1,9 @@
var moment = require('moment'),
should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
api = require('../../../../server/api'),
var should = require('should'),
sinon = require('sinon'),
moment = require('moment'),
Promise = require('bluebird'),
_ = require('lodash'),
api = require('../../../../server/api'),
frontend = require('../../../../server/controllers/frontend'),
configUtils = require('../../../utils/configUtils'),
themes = require('../../../../server/themes'),
@ -61,56 +61,56 @@ describe('Frontend Controller', function () {
describe('single', function () {
var req, res, mockPosts = [{
posts: [{
status: 'published',
posts: [{
status: 'published',
id: 1,
title: 'Test static page',
slug: 'test-static-page',
markdown: 'Test static page content',
page: 1,
published_at: new Date('2013/12/30').getTime(),
author: {
id: 1,
title: 'Test static page',
slug: 'test-static-page',
markdown: 'Test static page content',
page: 1,
published_at: new Date('2013/12/30').getTime(),
author: {
id: 1,
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
},
url: '/test-static-page/'
}]
}, {
posts: [{
status: 'published',
id: 2,
title: 'Test normal post',
slug: 'test-normal-post',
markdown: 'The test normal post content',
page: 0,
published_at: new Date('2014/1/2').getTime(),
author: {
id: 1,
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
}
}]
}, {
posts: [{
status: 'published',
id: 3,
title: 'About',
slug: 'about',
markdown: 'This is the about page content',
page: 1,
published_at: new Date('2014/1/30').getTime(),
author: {
id: 1,
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
},
url: '/about/'
}]
}];
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
},
url: '/test-static-page/'
}]
}, {
posts: [{
status: 'published',
id: 2,
title: 'Test normal post',
slug: 'test-normal-post',
markdown: 'The test normal post content',
page: 0,
published_at: new Date('2014/1/2').getTime(),
author: {
id: 1,
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
}
}]
}, {
posts: [{
status: 'published',
id: 3,
title: 'About',
slug: 'about',
markdown: 'This is the about page content',
page: 1,
published_at: new Date('2014/1/30').getTime(),
author: {
id: 1,
name: 'Test User',
slug: 'test',
email: 'test@ghost.org'
},
url: '/about/'
}]
}];
beforeEach(function () {
sandbox.stub(api.posts, 'read', function (args) {

View File

@ -1,10 +1,10 @@
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
configUtils = require('../../../utils/configUtils'),
api = require('../../../../server/api'),
postLookup = require('../../../../server/controllers/frontend/post-lookup'),
settingsCache = require('../../../../server/settings/cache'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
configUtils = require('../../../utils/configUtils'),
api = require('../../../../server/api'),
postLookup = require('../../../../server/controllers/frontend/post-lookup'),
settingsCache = require('../../../../server/settings/cache'),
sandbox = sinon.sandbox.create();
describe('postLookup', function () {
@ -29,10 +29,12 @@ describe('postLookup', function () {
localSettingsCache.permalinks = '/:slug/';
postAPIStub.withArgs({slug: 'welcome-to-ghost', include: 'author,tags'})
.returns(new Promise.resolve({posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]}));
.returns(new Promise.resolve({
posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]
}));
});
it('can lookup absolute url: /:slug/', function (done) {
@ -85,10 +87,12 @@ describe('postLookup', function () {
localSettingsCache.permalinks = '/:year/:month/:day/:slug/';
postAPIStub.withArgs({slug: 'welcome-to-ghost', include: 'author,tags'})
.returns(new Promise.resolve({posts: [{
url: '/2016/01/01/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]}));
.returns(new Promise.resolve({
posts: [{
url: '/2016/01/01/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]
}));
});
it('cannot lookup absolute url: /:slug/', function (done) {
@ -141,10 +145,12 @@ describe('postLookup', function () {
localSettingsCache.permalinks = '/:slug/';
postAPIStub.withArgs({slug: 'welcome-to-ghost', include: 'author,tags'})
.returns(new Promise.resolve({posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]}));
.returns(new Promise.resolve({
posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]
}));
});
it('can lookup absolute url: /:slug/edit/', function (done) {
@ -201,10 +207,12 @@ describe('postLookup', function () {
localSettingsCache.permalinks = '/:slug/';
postAPIStub.withArgs({slug: 'welcome-to-ghost', include: 'author,tags'})
.returns(new Promise.resolve({posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]}));
.returns(new Promise.resolve({
posts: [{
url: '/welcome-to-ghost/',
published_at: new Date('2016-01-01').valueOf()
}]
}));
});
it('can lookup absolute url: /:slug/amp/', function (done) {

View File

@ -1,7 +1,8 @@
/*jshint expr:true*/
var should = require('should'),
rewire = require('rewire'),
sinon = require('sinon'),
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
rewire = require('rewire'),
channelConfig = require('../../../../server/controllers/frontend/channel-config').get,
// stuff being tested
@ -10,9 +11,6 @@ var should = require('should'),
sandbox = sinon.sandbox.create(),
originalFetchData;
// stop jshint complaining
should.equal(true, true);
describe('Render Channel', function () {
beforeEach(function () {
originalFetchData = renderChannel.__get__('fetchData');
@ -31,7 +29,10 @@ describe('Render Channel', function () {
},
promise = {
then: function () {
return {catch: function () {}};
return {
catch: function () {
}
};
}
};

View File

@ -1,6 +1,6 @@
var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
// Stuff we are testing
templates = rewire('../../../../server/controllers/frontend/templates'),
@ -35,17 +35,29 @@ describe('templates', function () {
});
it('should return channel-slug, channel, index if channel has name & slug + slugTemplate set', function () {
channelTemplateList({name: 'tag', slugTemplate: true, slugParam: 'test'}).should.eql(['tag-test', 'tag', 'index']);
channelTemplateList({
name: 'tag',
slugTemplate: true,
slugParam: 'test'
}).should.eql(['tag-test', 'tag', 'index']);
});
it('should return front, channel-slug, channel, index if name, slugParam+slugTemplate & frontPageTemplate+pageParam=1 is set', function () {
channelTemplateList({
name: 'tag', slugTemplate: true, slugParam: 'test', frontPageTemplate: 'front-tag', postOptions: {page: 1}
name: 'tag',
slugTemplate: true,
slugParam: 'test',
frontPageTemplate: 'front-tag',
postOptions: {page: 1}
}).should.eql(['front-tag', 'tag-test', 'tag', 'index']);
});
it('should return home, index for index channel if front is set and pageParam = 1', function () {
channelTemplateList({name: 'index', frontPageTemplate: 'home', postOptions: {page: 1}}).should.eql(['home', 'index']);
channelTemplateList({
name: 'index',
frontPageTemplate: 'home',
postOptions: {page: 1}
}).should.eql(['home', 'index']);
});
});

View File

@ -1,7 +1,5 @@
var errors = require('../../server/errors'),
should = require('should');
should.equal(true, true);
var should = require('should'), // jshint ignore:line
errors = require('../../server/errors');
describe('Errors', function () {
it('Ensure we inherit from Error', function () {

View File

@ -8,6 +8,7 @@ var should = require('should'),
schema = require('../../server/data/schema'),
models = require('../../server/models'),
schemaTables = Object.keys(schema.tables),
sandbox = sinon.sandbox.create();
describe('Exporter', function () {

View File

@ -1,17 +1,18 @@
var should = require('should'),
sinon = require('sinon'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
_ = require('lodash'),
// Stuff we are testing
Filters = require('../../server/filters').Filters;
Filters = require('../../server/filters').Filters,
sandbox = sinon.sandbox.create();
describe('Filters', function () {
var filters, sandbox;
var filters;
beforeEach(function () {
filters = new Filters();
sandbox = sinon.sandbox.create();
});
afterEach(function () {

View File

@ -1,10 +1,8 @@
var should = require('should'),
var should = require('should'), // jshint ignore:line
ghostUrl = require('../../shared/ghost-url'),
configUtils = require('../utils/configUtils'),
utils = require('../../server/utils');
should.equal(true, true);
// @TODO: ghostUrl.init was obviously written for this test, get rid of it! (write a route test instead)
describe('Ghost Ajax Helper', function () {
beforeEach(function () {

View File

@ -1,24 +1,24 @@
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
_ = require('lodash'),
testUtils = require('../utils'),
moment = require('moment'),
path = require('path'),
errors = require('../../server/errors'),
moment = require('moment'),
path = require('path'),
errors = require('../../server/errors'),
// Stuff we are testing
ImportManager = require('../../server/data/importer'),
JSONHandler = require('../../server/data/importer/handlers/json'),
ImageHandler = require('../../server/data/importer/handlers/image'),
ImportManager = require('../../server/data/importer'),
JSONHandler = require('../../server/data/importer/handlers/json'),
ImageHandler = require('../../server/data/importer/handlers/image'),
MarkdownHandler = require('../../server/data/importer/handlers/markdown'),
DataImporter = require('../../server/data/importer/importers/data'),
ImageImporter = require('../../server/data/importer/importers/image'),
DataImporter = require('../../server/data/importer/importers/data'),
ImageImporter = require('../../server/data/importer/importers/image'),
storage = require('../../server/storage'),
storage = require('../../server/storage'),
configUtils = require('../utils/configUtils'),
sandbox = sinon.sandbox.create();
configUtils = require('../utils/configUtils'),
sandbox = sinon.sandbox.create();
describe('Importer', function () {
afterEach(function () {
@ -445,18 +445,18 @@ describe('Importer', function () {
path: '/my/test/testing.png',
name: 'testing.png'
},
{
path: '/my/test/photo/kitten.jpg',
name: 'photo/kitten.jpg'
},
{
path: '/my/test/content/images/animated/bunny.gif',
name: 'content/images/animated/bunny.gif'
},
{
path: '/my/test/images/puppy.jpg',
name: 'images/puppy.jpg'
}],
{
path: '/my/test/photo/kitten.jpg',
name: 'photo/kitten.jpg'
},
{
path: '/my/test/content/images/animated/bunny.gif',
name: 'content/images/animated/bunny.gif'
},
{
path: '/my/test/images/puppy.jpg',
name: 'images/puppy.jpg'
}],
storeSpy = sandbox.spy(store, 'getUniqueFileName'),
storageSpy = sandbox.spy(storage, 'getStorage');
@ -587,15 +587,15 @@ describe('Importer', function () {
it('can import multiple files', function (done) {
var files = [{
path: testUtils.fixtures.getImportFixturePath('deleted-2014-12-19-test-1.md'),
name: 'deleted-2014-12-19-test-1.md'
}, {
path: testUtils.fixtures.getImportFixturePath('published-2014-12-19-test-1.md'),
name: 'published-2014-12-19-test-1.md'
}, {
path: testUtils.fixtures.getImportFixturePath('draft-2014-12-19-test-3.md'),
name: 'draft-2014-12-19-test-3.md'
}];
path: testUtils.fixtures.getImportFixturePath('deleted-2014-12-19-test-1.md'),
name: 'deleted-2014-12-19-test-1.md'
}, {
path: testUtils.fixtures.getImportFixturePath('published-2014-12-19-test-1.md'),
name: 'published-2014-12-19-test-1.md'
}, {
path: testUtils.fixtures.getImportFixturePath('draft-2014-12-19-test-3.md'),
name: 'draft-2014-12-19-test-3.md'
}];
MarkdownHandler.loadFile(files).then(function (result) {
// deleted-2014-12-19-test-1.md
@ -648,7 +648,7 @@ describe('Importer', function () {
it('does import the data correctly', function () {
var inputData = require('../utils/fixtures/import/import-data-1.json'),
importerSpy = sandbox.stub(importer, 'doImport').returns(Promise.resolve());
importerSpy = sandbox.stub(importer, 'doImport').returns(Promise.resolve());
DataImporter.doImport(inputData.data).then(function () {
importerSpy.calledOnce.should.be.true();
@ -698,7 +698,7 @@ describe('Importer', function () {
storageApi = {
save: sandbox.stub().returns(Promise.resolve())
},
storageSpy = sandbox.stub(storage, 'getStorage', function () {
storageSpy = sandbox.stub(storage, 'getStorage', function () {
return storageApi;
});

View File

@ -1,11 +1,11 @@
var should = require('should'),
Promise = require('bluebird'),
sinon = require('sinon'),
mail = require('../../../server/mail'),
settingsCache = require('../../../server/settings/cache'),
configUtils = require('../../utils/configUtils'),
i18n = require('../../../server/i18n'),
sandbox = sinon.sandbox.create(),
var should = require('should'),
sinon = require('sinon'),
Promise = require('bluebird'),
mail = require('../../../server/mail'),
settingsCache = require('../../../server/settings/cache'),
configUtils = require('../../utils/configUtils'),
i18n = require('../../../server/i18n'),
sandbox = sinon.sandbox.create(),
mailer,
// Mock SMTP config

View File

@ -1,4 +1,5 @@
var sinon = require('sinon'),
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
mail = require('../../../server/mail'),
sandbox = sinon.sandbox.create();

View File

@ -1,5 +1,5 @@
var should = require('should'),
getAmpUrl = require('../../../server/data/meta/amp_url');
var should = require('should'),
getAmpUrl = require('../../../server/data/meta/amp_url');
describe('getAmpUrl', function () {
it('should return amp url for post only', function () {

View File

@ -1,4 +1,5 @@
var getAssetUrl = require('../../../server/data/meta/asset_url'),
var should = require('should'), // jshint ignore:line
getAssetUrl = require('../../../server/data/meta/asset_url'),
config = require('../../../server/config');
describe('getAssetUrl', function () {

View File

@ -1,45 +1,45 @@
var getAuthorFacebookUrl = require('../../../server/data/meta/author_fb_url'),
should = require('should');
var should = require('should'),
getAuthorFacebookUrl = require('../../../server/data/meta/author_fb_url');
describe('getAuthorFacebookUrl', function () {
it('should return author facebook url if post and has url',
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['post'],
post: {
author: {
facebook: 'https://www.facebook.com/user'
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['post'],
post: {
author: {
facebook: 'https://www.facebook.com/user'
}
}
}
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
it('should return author facebook url if AMP post and has url',
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['amp', 'post'],
post: {
author: {
facebook: 'https://www.facebook.com/user'
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['amp', 'post'],
post: {
author: {
facebook: 'https://www.facebook.com/user'
}
}
}
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
it('should return null if context does not contain author facebook url and is a post',
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['post'],
post: {
author: {
facebook: ''
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['post'],
post: {
author: {
facebook: ''
}
}
}
});
should(facebookUrl).equal(null);
});
should(facebookUrl).equal(null);
});
it('should return null if context does not contain author and is a post', function () {
var facebookUrl = getAuthorFacebookUrl({
@ -50,26 +50,26 @@ describe('getAuthorFacebookUrl', function () {
});
it('should return author facebook url if author and has url',
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['author'],
author: {
facebook: 'https://www.facebook.com/user'
}
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['author'],
author: {
facebook: 'https://www.facebook.com/user'
}
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
facebookUrl.should.equal('https://www.facebook.com/user');
});
it('should return null if context does not contain author facebook url and is a author',
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['author'],
author: {
facebook: ''
}
function () {
var facebookUrl = getAuthorFacebookUrl({
context: ['author'],
author: {
facebook: ''
}
});
should(facebookUrl).equal(null);
});
should(facebookUrl).equal(null);
});
it('should return null if context is not a post', function () {
var facebookUrl = getAuthorFacebookUrl({

View File

@ -1,85 +1,85 @@
var getAuthorUrl = require('../../../server/data/meta/author_url'),
should = require('should');
var should = require('should'),
getAuthorUrl = require('../../../server/data/meta/author_url');
describe('getAuthorUrl', function () {
it('should return author url if context contains author',
function () {
var authorUrl = getAuthorUrl({
context: ['post'],
post: {
author: {
slug: 'test-author'
function () {
var authorUrl = getAuthorUrl({
context: ['post'],
post: {
author: {
slug: 'test-author'
}
}
}
});
authorUrl.should.equal('/author/test-author/');
});
authorUrl.should.equal('/author/test-author/');
});
it('should return absolute author url if context contains author',
function () {
var authorUrl = getAuthorUrl({
context: ['post'],
post: {
author: {
slug: 'test-author'
function () {
var authorUrl = getAuthorUrl({
context: ['post'],
post: {
author: {
slug: 'test-author'
}
}
}
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
it('should return author url for AMP if context contains author',
function () {
var authorUrl = getAuthorUrl({
context: ['amp', 'post'],
post: {
author: {
slug: 'test-author'
function () {
var authorUrl = getAuthorUrl({
context: ['amp', 'post'],
post: {
author: {
slug: 'test-author'
}
}
}
});
authorUrl.should.equal('/author/test-author/');
});
authorUrl.should.equal('/author/test-author/');
});
it('should return absolute author url for AMP if context contains author',
function () {
var authorUrl = getAuthorUrl({
context: ['amp', 'post'],
post: {
function () {
var authorUrl = getAuthorUrl({
context: ['amp', 'post'],
post: {
author: {
slug: 'test-author'
}
}
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
it('should return author url if data contains author',
function () {
var authorUrl = getAuthorUrl({
author: {
slug: 'test-author'
}
}
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
it('should return author url if data contains author',
function () {
var authorUrl = getAuthorUrl({
author: {
slug: 'test-author'
}
});
authorUrl.should.equal('/author/test-author/');
});
authorUrl.should.equal('/author/test-author/');
});
it('should return absolute author url if data contains author',
function () {
var authorUrl = getAuthorUrl({
author: {
slug: 'test-author'
}
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
function () {
var authorUrl = getAuthorUrl({
author: {
slug: 'test-author'
}
}, true);
authorUrl.should.not.equal('/author/test-author/');
authorUrl.should.match(/\/author\/test-author\/$/);
});
it('should return null if no author on data or context',
function () {
var authorUrl = getAuthorUrl({}, true);
should(authorUrl).equal(null);
});
function () {
var authorUrl = getAuthorUrl({}, true);
should(authorUrl).equal(null);
});
});

View File

@ -1,4 +1,5 @@
var getCanonicalUrl = require('../../../server/data/meta/canonical_url');
var should = require('should'), // jshint ignore:line
getCanonicalUrl = require('../../../server/data/meta/canonical_url');
describe('getCanonicalUrl', function () {
it('should return absolute canonical url for post', function () {

View File

@ -1,5 +1,5 @@
var should = require('should'),
sinon = require('sinon'),
var should = require('should'),
sinon = require('sinon'),
getContextObject = require('../../../server/data/meta/context_object.js'),
settingsCache = require('../../../server/settings/cache'),
sandbox = sinon.sandbox.create();

View File

@ -1,5 +1,5 @@
var getCoverImage = require('../../../server/data/meta/cover_image'),
should = require('should');
var should = require('should'),
getCoverImage = require('../../../server/data/meta/cover_image');
describe('getCoverImage', function () {
it('should return absolute cover image url for home', function () {

View File

@ -1,32 +1,32 @@
var getCreatorTwitterUrl = require('../../../server/data/meta/creator_url'),
should = require('should');
var should = require('should'),
getCreatorTwitterUrl = require('../../../server/data/meta/creator_url');
describe('getCreatorTwitterUrl', function () {
it('should return author twitter url if post and has url',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['post'],
post: {
author: {
twitter: 'https://twitter.com/user'
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['post'],
post: {
author: {
twitter: 'https://twitter.com/user'
}
}
}
});
twitterUrl.should.equal('https://twitter.com/user');
});
twitterUrl.should.equal('https://twitter.com/user');
});
it('should return null if context does not contain author twitter url and is a post',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['post'],
post: {
author: {
twitter: ''
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['post'],
post: {
author: {
twitter: ''
}
}
}
});
should(twitterUrl).equal(null);
});
should(twitterUrl).equal(null);
});
it('should return null if context does not contain author and is a post', function () {
var twitterUrl = getCreatorTwitterUrl({
@ -37,30 +37,30 @@ describe('getCreatorTwitterUrl', function () {
});
it('should return author twitter url if AMP post and has url',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['amp', 'post'],
post: {
author: {
twitter: 'https://twitter.com/user'
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['amp', 'post'],
post: {
author: {
twitter: 'https://twitter.com/user'
}
}
}
});
twitterUrl.should.equal('https://twitter.com/user');
});
twitterUrl.should.equal('https://twitter.com/user');
});
it('should return null if context does not contain author twitter url and is an AMP post',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['amp', 'post'],
post: {
author: {
twitter: ''
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['amp', 'post'],
post: {
author: {
twitter: ''
}
}
}
});
should(twitterUrl).equal(null);
});
should(twitterUrl).equal(null);
});
it('should return null if context does not contain author and is an AMP post', function () {
var twitterUrl = getCreatorTwitterUrl({
@ -71,26 +71,26 @@ describe('getCreatorTwitterUrl', function () {
});
it('should return author twitter url if author and has url',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['author'],
author: {
twitter: 'https://twitter.com/user'
}
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['author'],
author: {
twitter: 'https://twitter.com/user'
}
});
twitterUrl.should.equal('https://twitter.com/user');
});
twitterUrl.should.equal('https://twitter.com/user');
});
it('should return null if context does not contain author twitter url and is a author',
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['author'],
author: {
twitter: ''
}
function () {
var twitterUrl = getCreatorTwitterUrl({
context: ['author'],
author: {
twitter: ''
}
});
should(twitterUrl).equal(null);
});
should(twitterUrl).equal(null);
});
it('should return null if context is not a post', function () {
var twitterUrl = getCreatorTwitterUrl({

View File

@ -1,4 +1,5 @@
var getMetaDescription = require('../../../server/data/meta/description');
var should = require('should'), // jshint ignore:line
getMetaDescription = require('../../../server/data/meta/description');
describe('getMetaDescription', function () {
it('should return meta_description if on data root', function () {

Some files were not shown because too many files have changed in this diff Show More