0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Update mocha to version 3.0.2 🚀 (#7165)

* chore(package): update mocha to version 3.0.2

https://greenkeeper.io/

* fix duplicate done/promise handling
This commit is contained in:
Greenkeeper 2016-08-11 09:51:19 +02:00 committed by Hannah Wolfe
parent a0288303f6
commit dd5775c018
6 changed files with 168 additions and 289 deletions

View file

@ -15,7 +15,7 @@ describe('DB API', function () {
should.exist(dbAPI);
it('delete all content (owner)', function (done) {
it('delete all content (owner)', function () {
return dbAPI.deleteAllContent(testUtils.context.owner).then(function (result) {
should.exist(result.db);
result.db.should.be.instanceof(Array);
@ -29,12 +29,11 @@ describe('DB API', function () {
return ModelPost.Post.findAll(testUtils.context.owner).then(function (results) {
should.exist(results);
results.length.should.equal(0);
done();
});
}).catch(done);
});
});
it('delete all content (admin)', function (done) {
it('delete all content (admin)', function () {
return dbAPI.deleteAllContent(testUtils.context.admin).then(function (result) {
should.exist(result.db);
result.db.should.be.instanceof(Array);
@ -48,50 +47,47 @@ describe('DB API', function () {
return ModelPost.Post.findAll(testUtils.context.admin).then(function (results) {
should.exist(results);
results.length.should.equal(0);
done();
});
}).catch(done);
});
});
it('delete all content is denied (editor, author & without authentication)', function (done) {
it('delete all content is denied (editor, author & without authentication)', function () {
return dbAPI.deleteAllContent(testUtils.context.editor).then(function () {
done(new Error('Delete all content is not denied for editor.'));
throw new Error('Delete all content is not denied for editor.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.deleteAllContent(testUtils.context.author);
}).then(function () {
done(new Error('Delete all content is not denied for author.'));
throw new Error('Delete all content is not denied for author.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.deleteAllContent();
}).then(function () {
done(new Error('Delete all content is not denied without authentication.'));
throw new Error('Delete all content is not denied without authentication.');
}).catch(function (error) {
error.errorType.should.eql('NoPermissionError');
done();
}).catch(done);
});
});
it('export content is denied (editor, author & without authentication)', function (done) {
it('export content is denied (editor, author & without authentication)', function () {
return dbAPI.exportContent(testUtils.context.editor).then(function () {
done(new Error('Export content is not denied for editor.'));
throw new Error('Export content is not denied for editor.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.exportContent(testUtils.context.author);
}).then(function () {
done(new Error('Export content is not denied for author.'));
throw new Error('Export content is not denied for author.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.exportContent();
}).then(function () {
done(new Error('Export content is not denied without authentication.'));
throw new Error('Export content is not denied without authentication.');
}).catch(function (error) {
error.errorType.should.eql('NoPermissionError');
done();
}).catch(done);
});
});
it('import content is denied (editor, author & without authentication)', function (done) {
it('import content is denied (editor, author & without authentication)', function () {
var file = {
originalname: 'myFile.json',
path: '/my/path/myFile.json',
@ -99,26 +95,25 @@ describe('DB API', function () {
};
return dbAPI.importContent(_.extend(testUtils.context.editor, file)).then(function () {
done(new Error('Import content is not denied for editor.'));
throw new Error('Import content is not denied for editor.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.importContent(_.extend(testUtils.context.author, file));
}).then(function () {
done(new Error('Import content is not denied for author.'));
throw new Error('Import content is not denied for author.');
}, function (error) {
error.errorType.should.eql('NoPermissionError');
return dbAPI.importContent(file);
}).then(function () {
done(new Error('Import content is not denied without authentication.'));
throw new Error('Import content is not denied without authentication.');
}).catch(function (error) {
error.errorType.should.eql('NoPermissionError');
done();
}).catch(done);
});
});
it('import content should fail without file & with unsupported file', function (done) {
it('import content should fail without file & with unsupported file', function () {
return dbAPI.importContent(testUtils.context.admin).then(function () {
done(new Error('Import content is not failed without file.'));
throw new Error('Import content is not failed without file.');
}, function (error) {
error.errorType.should.eql('ValidationError');
@ -128,10 +123,9 @@ describe('DB API', function () {
return dbAPI.importContent(context);
}).then(function () {
done(new Error('Import content is not failed with unsupported.'));
throw new Error('Import content is not failed with unsupported.');
}, function (error) {
error.errorType.should.eql('UnsupportedMediaTypeError');
done();
}).catch(done);
});
});
});

View file

@ -27,27 +27,22 @@ describe('Settings API', function () {
return SettingsAPI[method].apply({}, args.slice(2));
};
getErrorDetails = function (done) {
return function (err) {
if (err instanceof Error) {
return done(err);
}
getErrorDetails = function (err) {
if (err instanceof Error) {
throw err;
}
done(new Error(err.message));
};
throw new Error(err.message);
};
it('uses Date objects for dateTime fields', function (done) {
it('uses Date objects for dateTime fields', function () {
return callApiWithContext(defaultContext, 'browse', {}).then(function (results) {
should.exist(results);
results.settings[0].created_at.should.be.an.instanceof(Date);
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('can browse', function (done) {
it('can browse', function () {
return callApiWithContext(defaultContext, 'browse', {}).then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'settings');
@ -56,12 +51,10 @@ describe('Settings API', function () {
// Check for a core setting
should.not.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('can browse by type', function (done) {
it('can browse by type', function () {
return callApiWithContext(defaultContext, 'browse', {type: 'blog'}).then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'settings');
@ -70,12 +63,10 @@ describe('Settings API', function () {
// Check for a core setting
should.not.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('returns core settings for internal requests when browsing', function (done) {
it('returns core settings for internal requests when browsing', function () {
return callApiWithContext(internalContext, 'browse', {}).then(function (results) {
should.exist(results);
testUtils.API.checkResponse(results, 'settings');
@ -84,145 +75,121 @@ describe('Settings API', function () {
// Check for a core setting
should.exist(_.find(results.settings, function (setting) { return setting.type === 'core'; }));
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('can read blog settings by string', function (done) {
it('can read blog settings by string', function () {
return SettingsAPI.read('title').then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('cannot read core settings if not an internal request', function (done) {
it('cannot read core settings if not an internal request', function () {
return callApiWithContext(defaultContext, 'read', {key: 'databaseVersion'}).then(function () {
done(new Error('Allowed to read databaseVersion with external request'));
throw new Error('Allowed to read databaseVersion with external request');
}).catch(function (error) {
should.exist(error);
error.errorType.should.eql('NoPermissionError');
done();
}).catch(done);
});
});
it('can read core settings if an internal request', function (done) {
it('can read core settings if an internal request', function () {
return callApiWithContext(internalContext, 'read', {key: 'databaseVersion'}).then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('can read by object key', function (done) {
it('can read by object key', function () {
return callApiWithContext(defaultContext, 'read', {key: 'title'}).then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
done();
}).catch(getErrorDetails(done));
}).catch(getErrorDetails);
});
it('can edit', function (done) {
it('can edit', function () {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'title', value: 'UpdatedGhost'}]}, {})
.then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
done();
}).catch(done);
});
});
it('cannot edit a core setting if not an internal request', function (done) {
it('cannot edit a core setting if not an internal request', function () {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'databaseVersion', value: '999'}]}, {})
.then(function () {
done(new Error('Allowed to edit a core setting as external request'));
throw new Error('Allowed to edit a core setting as external request');
}).catch(function (err) {
should.exist(err);
err.errorType.should.eql('NoPermissionError');
done();
}).catch(done);
});
});
it('can edit a core setting with an internal request', function (done) {
it('can edit a core setting with an internal request', function () {
return callApiWithContext(internalContext, 'edit', {settings: [{key: 'databaseVersion', value: '999'}]}, {})
.then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
done();
}).catch(done);
});
});
it('ensures values are stringified before saving to database', function (done) {
it('ensures values are stringified before saving to database', function () {
return callApiWithContext(defaultContext, 'edit', 'title', []).then(function (response) {
should.exist(response);
testUtils.API.checkResponse(response, 'settings');
response.settings.length.should.equal(1);
testUtils.API.checkResponse(response.settings[0], 'setting');
response.settings[0].value.should.equal('[]');
done();
}).catch(done);
});
});
it('does not allow an active theme which is not installed', function (done) {
it('does not allow an active theme which is not installed', function () {
return callApiWithContext(defaultContext, 'edit', 'activeTheme', {
settings: [{key: 'activeTheme', value: 'rasper'}]
}).then(function () {
done(new Error('Allowed to set an active theme which is not installed'));
throw new Error('Allowed to set an active theme which is not installed');
}).catch(function (err) {
should.exist(err);
err.errorType.should.eql('ValidationError');
done();
}).catch(done);
});
});
it('set activeTimezone: unknown timezone', function (done) {
it('set activeTimezone: unknown timezone', function () {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'activeTimezone', value: 'MFG'}]}, {})
.then(function () {
done(new Error('We expect that the activeTimezone cannot be stored'));
throw new Error('We expect that the activeTimezone cannot be stored');
}).catch(function (errors) {
should.exist(errors);
errors.length.should.eql(1);
errors[0].errorType.should.eql('ValidationError');
done();
}).catch(done);
});
});
it('set activeTimezone: unknown timezone', function (done) {
it('set activeTimezone: unknown timezone', function () {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'activeTimezone', value: 'MFG'}]}, {})
.then(function () {
done(new Error('We expect that the activeTimezone cannot be stored'));
throw new Error('We expect that the activeTimezone cannot be stored');
}).catch(function (errors) {
should.exist(errors);
errors.length.should.eql(1);
errors[0].errorType.should.eql('ValidationError');
done();
}).catch(done);
});
});
it('set activeTimezone: known timezone', function (done) {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'activeTimezone', value: 'Etc/UTC'}]}, {})
.then(function () {
done();
}).catch(done);
it('set activeTimezone: known timezone', function () {
return callApiWithContext(defaultContext, 'edit', {settings: [{key: 'activeTimezone', value: 'Etc/UTC'}]}, {});
});
});

View file

@ -1367,7 +1367,7 @@ describe('Post Model', function () {
editOptions,
createTag = testUtils.DataGenerator.forKnex.createTag;
beforeEach(function (done) {
beforeEach(function () {
tagJSON = [];
var post = _.cloneDeep(testUtils.DataGenerator.forModel.posts[0]),
@ -1399,7 +1399,6 @@ describe('Post Model', function () {
// reset the eventSpy here
sandbox.restore();
done();
});
});
@ -1424,7 +1423,7 @@ describe('Post Model', function () {
});
describe('Adding brand new tags', function () {
it('can add a single tag to the end of the tags array', function (done) {
it('can add a single tag to the end of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single tag to the end of the array
@ -1448,12 +1447,10 @@ describe('Post Model', function () {
id: postJSON.tags[2].id
});
updatedPost.tags.should.have.enumerable(3).with.property('name', 'tag4');
done();
}).catch(done);
});
});
it('can add a single tag to the beginning of the tags array', function (done) {
it('can add a single tag to the beginning of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single tag to the beginning of the array
@ -1477,14 +1474,12 @@ describe('Post Model', function () {
name: 'tag3',
id: postJSON.tags[2].id
});
done();
}).catch(done);
});
});
});
describe('Adding pre-existing tags', function () {
it('can add a single tag to the end of the tags array', function (done) {
it('can add a single tag to the end of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single pre-existing tag to the end of the array
@ -1511,12 +1506,10 @@ describe('Post Model', function () {
name: 'existing tag a',
id: tagJSON[0].id
});
done();
}).catch(done);
});
});
it('can add a single tag to the beginning of the tags array', function (done) {
it('can add a single tag to the beginning of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Add an existing tag to the beginning of the array
@ -1543,12 +1536,10 @@ describe('Post Model', function () {
name: 'tag3',
id: postJSON.tags[2].id
});
done();
}).catch(done);
});
});
it('can add a single tag to the middle of the tags array', function (done) {
it('can add a single tag to the middle of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single pre-existing tag to the middle of the array
@ -1575,14 +1566,12 @@ describe('Post Model', function () {
name: 'tag3',
id: postJSON.tags[2].id
});
done();
}).catch(done);
});
});
});
describe('Removing tags', function () {
it('can remove a single tag from the end of the tags array', function (done) {
it('can remove a single tag from the end of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Remove a single tag from the end of the array
@ -1601,12 +1590,10 @@ describe('Post Model', function () {
name: 'tag2',
id: postJSON.tags[1].id
});
done();
}).catch(done);
});
});
it('can remove a single tag from the beginning of the tags array', function (done) {
it('can remove a single tag from the beginning of the tags array', function () {
var newJSON = _.cloneDeep(postJSON);
// Remove a single tag from the beginning of the array
@ -1625,12 +1612,10 @@ describe('Post Model', function () {
name: 'tag3',
id: postJSON.tags[2].id
});
done();
}).catch(done);
});
});
it('can remove all tags', function (done) {
it('can remove all tags', function () {
var newJSON = _.cloneDeep(postJSON);
// Remove all the tags
@ -1641,14 +1626,12 @@ describe('Post Model', function () {
updatedPost = updatedPost.toJSON({include: ['tags']});
updatedPost.tags.should.have.lengthOf(0);
done();
}).catch(done);
});
});
});
describe('Reordering tags', function () {
it('can reorder the first tag to be the last', function (done) {
it('can reorder the first tag to be the last', function () {
var newJSON = _.cloneDeep(postJSON),
firstTag = [postJSON.tags[0]];
@ -1672,12 +1655,10 @@ describe('Post Model', function () {
name: 'tag1',
id: postJSON.tags[0].id
});
done();
}).catch(done);
});
});
it('can reorder the last tag to be the first', function (done) {
it('can reorder the last tag to be the first', function () {
var newJSON = _.cloneDeep(postJSON),
lastTag = [postJSON.tags[2]];
@ -1701,15 +1682,13 @@ describe('Post Model', function () {
name: 'tag2',
id: postJSON.tags[1].id
});
done();
}).catch(done);
});
});
});
describe('Edit post', function () {
// These tests are for #6920
it('can edit a post SAFELY when tags are not included', function (done) {
it('can edit a post SAFELY when tags are not included', function () {
var postId = postJSON.id,
toJSONOpts = {include: ['tags']},
startTags;
@ -1739,19 +1718,17 @@ describe('Post Model', function () {
var post = results.toJSON(toJSONOpts);
post.tags.should.have.lengthOf(3);
post.tags.should.eql(startTags);
done();
});
}).catch(done);
});
});
it('can edit a post SAFELY when tags is undefined', function (done) {
it('can edit a post SAFELY when tags is undefined', function () {
var postId = postJSON.id,
toJSONOpts = {include: ['tags']},
startTags;
// Step 1, fetch a post with its tags, just to see what tags we have
PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
return PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
var post = results.toJSON(toJSONOpts);
should.exist(results);
post.title.should.not.equal('new title');
@ -1775,19 +1752,17 @@ describe('Post Model', function () {
var post = results.toJSON(toJSONOpts);
post.tags.should.have.lengthOf(3);
post.tags.should.eql(startTags);
done();
});
}).catch(done);
});
});
it('can edit a post SAFELY when tags is null', function (done) {
it('can edit a post SAFELY when tags is null', function () {
var postId = postJSON.id,
toJSONOpts = {include: ['tags']},
startTags;
// Step 1, fetch a post with its tags, just to see what tags we have
PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
return PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
var post = results.toJSON(toJSONOpts);
should.exist(results);
post.title.should.not.equal('new title');
@ -1811,18 +1786,16 @@ describe('Post Model', function () {
var post = results.toJSON(toJSONOpts);
post.tags.should.have.lengthOf(3);
post.tags.should.eql(startTags);
done();
});
}).catch(done);
});
});
it('can remove all tags when sent an empty array', function (done) {
it('can remove all tags when sent an empty array', function () {
var postId = postJSON.id,
toJSONOpts = {include: ['tags']};
// Step 1, fetch a post with its tags, just to see what tags we have
PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
return PostModel.findOne({id: postId}, {withRelated: ['tags']}).then(function (results) {
var post = results.toJSON(toJSONOpts);
should.exist(results);
post.title.should.not.equal('new title');
@ -1843,15 +1816,13 @@ describe('Post Model', function () {
var post = results.toJSON(toJSONOpts);
// Tags should be gone
post.tags.should.eql([]);
done();
});
}).catch(done);
});
});
});
describe('Combination updates', function () {
it('can add a combination of new and pre-existing tags', function (done) {
it('can add a combination of new and pre-existing tags', function () {
var newJSON = _.cloneDeep(postJSON);
// Push a bunch of new and existing tags to the end of the array
@ -1894,12 +1865,10 @@ describe('Post Model', function () {
name: 'existing_tag_c',
id: tagJSON[2].id
});
done();
}).catch(done);
});
});
it('can reorder the first tag to be the last and add a tag to the beginning', function (done) {
it('can reorder the first tag to be the last and add a tag to the beginning', function () {
var newJSON = _.cloneDeep(postJSON),
firstTag = [postJSON.tags[0]];
@ -1927,12 +1896,10 @@ describe('Post Model', function () {
name: 'tag1',
id: postJSON.tags[0].id
});
done();
}).catch(done);
});
});
it('can reorder the first tag to be the last, remove the original last tag & add a tag to the beginning', function (done) {
it('can reorder the first tag to be the last, remove the original last tag & add a tag to the beginning', function () {
var newJSON = _.cloneDeep(postJSON),
firstTag = [newJSON.tags[0]];
@ -1956,12 +1923,10 @@ describe('Post Model', function () {
name: 'tag1',
id: postJSON.tags[0].id
});
done();
}).catch(done);
});
});
it('can reorder original tags, remove one, and add new and existing tags', function (done) {
it('can reorder original tags, remove one, and add new and existing tags', function () {
var newJSON = _.cloneDeep(postJSON),
firstTag = [newJSON.tags[0]];
@ -2006,9 +1971,7 @@ describe('Post Model', function () {
name: 'existing tag a',
id: tagJSON[0].id
});
done();
}).catch(done);
});
});
});
});
@ -2019,7 +1982,7 @@ describe('Post Model', function () {
editOptions,
createTag = testUtils.DataGenerator.forKnex.createTag;
beforeEach(function (done) {
beforeEach(function () {
tagJSON = [];
var post = _.cloneDeep(testUtils.DataGenerator.forModel.posts[0]),
@ -2038,9 +2001,7 @@ describe('Post Model', function () {
tagJSON.push(result.tag2.toJSON());
tagJSON.push(result.tag3.toJSON());
editOptions = _.extend({}, context, {id: postJSON.id, withRelated: ['tags']});
done();
}).catch(done);
});
});
it('should create the test data correctly', function () {
@ -2058,7 +2019,7 @@ describe('Post Model', function () {
});
describe('Adding brand new tags', function () {
it('can add a single tag', function (done) {
it('can add a single tag', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single tag to the end of the array
@ -2070,12 +2031,10 @@ describe('Post Model', function () {
updatedPost.tags.should.have.lengthOf(1);
updatedPost.tags.should.have.enumerable(0).with.property('name', 'tag1');
done();
}).catch(done);
});
});
it('can add multiple tags', function (done) {
it('can add multiple tags', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a bunch of tags to the end of the array
@ -2095,12 +2054,10 @@ describe('Post Model', function () {
updatedPost.tags.should.have.enumerable(2).with.property('name', 'tag3');
updatedPost.tags.should.have.enumerable(3).with.property('name', 'tag4');
updatedPost.tags.should.have.enumerable(4).with.property('name', 'tag5');
done();
}).catch(done);
});
});
it('can add multiple tags with conflicting slugs', function (done) {
it('can add multiple tags with conflicting slugs', function () {
var newJSON = _.cloneDeep(postJSON);
// Add conflicting tags to the end of the array
@ -2116,14 +2073,12 @@ describe('Post Model', function () {
updatedPost.tags.should.have.enumerable(0).with.properties({name: 'C', slug: 'c'});
updatedPost.tags.should.have.enumerable(1).with.properties({name: 'C++', slug: 'c-2'});
updatedPost.tags.should.have.enumerable(2).with.properties({name: 'C#', slug: 'c-3'});
done();
}).catch(done);
});
});
});
describe('Adding pre-existing tags', function () {
it('can add a single tag', function (done) {
it('can add a single tag', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a single pre-existing tag
@ -2138,12 +2093,10 @@ describe('Post Model', function () {
name: 'existing tag a',
id: tagJSON[0].id
});
done();
}).catch(done);
});
});
it('can add multiple tags', function (done) {
it('can add multiple tags', function () {
var newJSON = _.cloneDeep(postJSON);
// Add many preexisting tags
@ -2168,12 +2121,10 @@ describe('Post Model', function () {
name: 'existing_tag_c',
id: tagJSON[2].id
});
done();
}).catch(done);
});
});
it('can add multiple tags in wrong order', function (done) {
it('can add multiple tags in wrong order', function () {
var newJSON = _.cloneDeep(postJSON);
// Add tags to the array
@ -2198,14 +2149,12 @@ describe('Post Model', function () {
name: 'existing-tag-b',
id: tagJSON[1].id
});
done();
}).catch(done);
});
});
});
describe('Adding combinations', function () {
it('can add a combination of new and pre-existing tags', function (done) {
it('can add a combination of new and pre-existing tags', function () {
var newJSON = _.cloneDeep(postJSON);
// Add a bunch of new and existing tags to the array
@ -2236,9 +2185,7 @@ describe('Post Model', function () {
name: 'existing_tag_c',
id: tagJSON[2].id
});
done();
}).catch(done);
});
});
});
});

View file

@ -266,7 +266,7 @@ describe('User Model', function run() {
}).catch(done);
});
it('can findPage with limit all', function (done) {
it('can findPage with limit all', function () {
return testUtils.fixtures.createExtraUsers().then(function () {
return UserModel.findPage({limit: 'all'});
}).then(function (results) {
@ -274,9 +274,7 @@ describe('User Model', function run() {
results.meta.pagination.limit.should.equal('all');
results.meta.pagination.pages.should.equal(1);
results.users.length.should.equal(7);
done();
}).catch(done);
});
});
it('can NOT findPage for a page that overflows the datatype', function (done) {
@ -307,7 +305,7 @@ describe('User Model', function run() {
}).catch(done);
});
it('can findOne by role name', function (done) {
it('can findOne by role name', function () {
return testUtils.fixtures.createExtraUsers().then(function () {
return Promise.join(UserModel.findOne({role: 'Owner'}), UserModel.findOne({role: 'Editor'}));
}).then(function (results) {
@ -325,9 +323,7 @@ describe('User Model', function run() {
owner.roles[0].name.should.equal('Owner');
editor.roles[0].name.should.equal('Editor');
done();
}).catch(done);
});
});
it('can invite user', function (done) {

View file

@ -22,63 +22,46 @@ describe('Pipeline', function () {
sandbox.restore();
});
it('should execute tasks in order', function (done) {
return pipeline([createTask('b'), createTask('c'), createTask('d')], 'a').then(
function (result) {
result.should.eql('abcd');
done();
}
);
it('should execute tasks in order', function () {
return pipeline([createTask('b'), createTask('c'), createTask('d')], 'a').then(function (result) {
result.should.eql('abcd');
});
});
it('should resolve to initial args when no tasks supplied', function (done) {
return pipeline([], 'a', 'b').then(
function (result) {
result.should.eql(['a', 'b']);
done();
}
);
it('should resolve to initial args when no tasks supplied', function () {
return pipeline([], 'a', 'b').then(function (result) {
result.should.eql(['a', 'b']);
});
});
it('should resolve to empty array when no tasks and no args supplied', function (done) {
return pipeline([]).then(
function (result) {
result.should.eql([]);
done();
}
);
it('should resolve to empty array when no tasks and no args supplied', function () {
return pipeline([]).then(function (result) {
result.should.eql([]);
});
});
it('should pass args to initial task', function (done) {
it('should pass args to initial task', function () {
var expected = [1, 2, 3],
tasks = [sandbox.spy()];
return pipeline(tasks, 1, 2, 3).then(
function () {
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
done();
}
);
return pipeline(tasks, 1, 2, 3).then(function () {
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
});
});
it('should allow initial args to be promises', function (done) {
it('should allow initial args to be promises', function () {
var expected = [1, 2, 3],
tasks = [sandbox.spy()],
Resolver = Promise.resolve;
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(
function () {
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
done();
}
);
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(function () {
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
});
});
it('should allow tasks to be promises', function (done) {
it('should allow tasks to be promises', function () {
var expected = [1, 2, 3],
tasks = [
sandbox.stub().returns(new Promise.resolve(4)),
@ -86,22 +69,18 @@ describe('Pipeline', function () {
sandbox.stub().returns(new Promise.resolve(6))
];
return pipeline(tasks, 1, 2, 3).then(
function (result) {
result.should.eql(6);
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
tasks[1].calledOnce.should.be.true();
tasks[1].firstCall.calledWith(4).should.be.true();
tasks[2].calledOnce.should.be.true();
tasks[2].firstCall.calledWith(5).should.be.true();
done();
}
);
return pipeline(tasks, 1, 2, 3).then(function (result) {
result.should.eql(6);
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
tasks[1].calledOnce.should.be.true();
tasks[1].firstCall.calledWith(4).should.be.true();
tasks[2].calledOnce.should.be.true();
tasks[2].firstCall.calledWith(5).should.be.true();
});
});
it('should allow tasks and args to be promises', function (done) {
it('should allow tasks and args to be promises', function () {
var expected = [1, 2, 3],
tasks = [
sandbox.stub().returns(new Promise.resolve(4)),
@ -110,18 +89,14 @@ describe('Pipeline', function () {
],
Resolver = Promise.resolve;
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(
function (result) {
result.should.eql(6);
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
tasks[1].calledOnce.should.be.true();
tasks[1].firstCall.calledWith(4).should.be.true();
tasks[2].calledOnce.should.be.true();
tasks[2].firstCall.calledWith(5).should.be.true();
done();
}
);
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(function (result) {
result.should.eql(6);
tasks[0].calledOnce.should.be.true();
tasks[0].firstCall.args.should.eql(expected);
tasks[1].calledOnce.should.be.true();
tasks[1].firstCall.calledWith(4).should.be.true();
tasks[2].calledOnce.should.be.true();
tasks[2].firstCall.calledWith(5).should.be.true();
});
});
});

View file

@ -97,7 +97,7 @@
"grunt-update-submodules": "0.4.1",
"istanbul": "0.4.4",
"matchdep": "1.0.1",
"mocha": "2.5.3",
"mocha": "3.0.2",
"nock": "8.0.0",
"rewire": "2.5.2",
"should": "11.0.0",