Refactored expected API properties

no issue

- we need to maintain the expected properties per API version
- each API version can return a different result
- move the expected properties to the local utility and call global test helper
This commit is contained in:
kirrg001 2018-12-17 16:14:36 +01:00 committed by Katharina Irrgang
parent 0f32209e65
commit 254a460462
30 changed files with 483 additions and 387 deletions

View File

@ -331,7 +331,7 @@ describe('Authentication API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
const newUser = jsonResponse.users[0];
newUser.id.should.equal(testUtils.DataGenerator.Content.users[0].id);

View File

@ -52,8 +52,8 @@ describe('Invites API', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(2);
testUtils.API.checkResponse(jsonResponse, 'invites');
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse, 'invites');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
jsonResponse.invites[0].status.should.eql('sent');
jsonResponse.invites[0].email.should.eql('test1@ghost.org');
@ -88,7 +88,7 @@ describe('Invites API', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
mailService.GhostMailer.prototype.send.called.should.be.false();
@ -118,7 +118,7 @@ describe('Invites API', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
jsonResponse.invites[0].role_id.should.eql(testUtils.existingData.roles[1].id);
mailService.GhostMailer.prototype.send.called.should.be.true();

View File

@ -47,7 +47,7 @@ describe('Notifications API', function () {
should.exist(jsonResponse.notifications);
testUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
jsonResponse.notifications[0].type.should.equal(newNotification.type);
jsonResponse.notifications[0].message.should.equal(newNotification.message);
@ -182,7 +182,7 @@ describe('Notifications API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.notifications);
testUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
jsonResponse.notifications[0].type.should.equal(newNotification.type);
jsonResponse.notifications[0].message.should.equal(newNotification.message);

View File

@ -72,10 +72,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -104,10 +104,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc'], ['html']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc'], ['html']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -129,10 +129,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(3);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -157,10 +157,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['plaintext'], ['html']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -182,10 +182,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -207,10 +207,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(
localUtils.API.checkResponse(
jsonResponse.posts[0],
'post',
null,
@ -218,7 +218,7 @@ describe('Post API', function () {
['mobiledoc', 'id', 'title', 'html']
);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
@ -238,9 +238,9 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(
localUtils.API.checkResponse(
jsonResponse.posts[0],
'post',
null,
@ -248,7 +248,7 @@ describe('Post API', function () {
['mobiledoc', 'id', 'title', 'html', 'authors']
);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
@ -268,10 +268,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(15);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -290,10 +290,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -312,10 +312,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(2);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts[0].slug.should.equal('ghostly-kitchen-sink');
done();
});
@ -335,10 +335,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts[0].slug.should.equal('not-so-short-bit-complex');
done();
});
@ -358,10 +358,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(2);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts[0].slug.should.equal('ghostly-kitchen-sink');
done();
});
@ -381,10 +381,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts[0].slug.should.equal('not-so-short-bit-complex');
done();
});
@ -404,10 +404,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.length.should.eql(2);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
const featured = _.map(jsonResponse.posts, 'featured');
featured.should.matchEach(true);
@ -430,10 +430,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.each(jsonResponse.posts, (post) => {
post.status.should.eql('draft');
@ -457,10 +457,10 @@ describe('Post API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -483,7 +483,7 @@ describe('Post API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
jsonResponse.posts[0].page.should.not.be.ok();
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -515,7 +515,7 @@ describe('Post API', function () {
jsonResponse.posts.should.have.length(1);
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
done();
});
@ -536,7 +536,7 @@ describe('Post API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].slug.should.equal('welcome');
jsonResponse.posts[0].page.should.not.be.ok();
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -564,13 +564,13 @@ describe('Post API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', 'tags');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', 'tags');
jsonResponse.posts[0].page.should.not.be.ok();
jsonResponse.posts[0].author.should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].author, 'user');
localUtils.API.checkResponse(jsonResponse.posts[0].author, 'user');
jsonResponse.posts[0].tags[0].should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag');
done();
});
});
@ -591,16 +591,16 @@ describe('Post API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['tags', 'authors']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['tags', 'authors']);
jsonResponse.posts[0].author.should.be.a.String();
jsonResponse.posts[0].page.should.not.be.ok();
jsonResponse.posts[0].authors[0].should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].authors[0], 'user');
localUtils.API.checkResponse(jsonResponse.posts[0].authors[0], 'user');
jsonResponse.posts[0].tags[0].should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag');
done();
});
});
@ -620,7 +620,7 @@ describe('Post API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].page.should.be.ok();
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
done();
@ -735,12 +735,12 @@ describe('Post API', function () {
draftPost.posts.length.should.be.above(0);
draftPost.posts[0].title.should.eql(newTitle);
draftPost.posts[0].status = publishedState;
testUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
localUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
should.exist(draftPost.posts[0].tags);
draftPost.posts[0].tags.length.should.be.above(0);
draftPost.posts[0].tags[0].name.should.eql(newTagName);
testUtils.API.checkResponse(draftPost.posts[0].tags[0], 'tag');
localUtils.API.checkResponse(draftPost.posts[0].tags[0], 'tag');
request.put(localUtils.API.getApiQuery('posts/' + draftPost.posts[0].id + '/?include=tags'))
.set('Authorization', 'Bearer ' + ownerAccessToken)
@ -762,12 +762,12 @@ describe('Post API', function () {
publishedPost.posts.length.should.be.above(0);
publishedPost.posts[0].title.should.eql(newTitle);
publishedPost.posts[0].status.should.eql(publishedState);
testUtils.API.checkResponse(publishedPost.posts[0], 'post', 'tags');
localUtils.API.checkResponse(publishedPost.posts[0], 'post', 'tags');
should.exist(publishedPost.posts[0].tags);
publishedPost.posts[0].tags.length.should.be.above(0);
publishedPost.posts[0].tags[0].name.should.eql(newTagName);
testUtils.API.checkResponse(publishedPost.posts[0].tags[0], 'tag');
localUtils.API.checkResponse(publishedPost.posts[0].tags[0], 'tag');
request.put(localUtils.API.getApiQuery('posts/' + publishedPost.posts[0].id + '/?include=tags'))
.set('Authorization', 'Bearer ' + ownerAccessToken)
@ -790,12 +790,12 @@ describe('Post API', function () {
updatedPost.posts[0].title.should.eql(newTitle);
testUtils.API.isISO8601(updatedPost.posts[0].created_at).should.be.true();
testUtils.API.isISO8601(updatedPost.posts[0].updated_at).should.be.true();
testUtils.API.checkResponse(updatedPost.posts[0], 'post', 'tags');
localUtils.API.checkResponse(updatedPost.posts[0], 'post', 'tags');
should.exist(updatedPost.posts[0].tags);
updatedPost.posts[0].tags.length.should.be.above(0);
updatedPost.posts[0].tags[0].name.should.eql(newTagName);
testUtils.API.checkResponse(updatedPost.posts[0].tags[0], 'tag');
localUtils.API.checkResponse(updatedPost.posts[0].tags[0], 'tag');
done();
});
@ -839,7 +839,7 @@ describe('Post API', function () {
response.posts[0].updated_by.should.not.eql(newPost.updated_by);
response.posts[0].created_by.should.not.eql(newPost.created_by);
testUtils.API.checkResponse(response.posts[0], 'post');
localUtils.API.checkResponse(response.posts[0], 'post');
done();
});
});
@ -886,7 +886,7 @@ describe('Post API', function () {
putBody.posts[0].status.should.eql('published');
putBody.posts[0].custom_template.should.eql('custom-about');
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});
@ -921,7 +921,7 @@ describe('Post API', function () {
should.exist(draftPost.posts);
draftPost.posts.length.should.be.above(0);
draftPost.posts[0].title.should.eql(newTitle);
testUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
localUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
draftPost.posts[0].title = 'Vote for Casper in red';
@ -973,7 +973,7 @@ describe('Post API', function () {
should.exist(draftPost.posts);
draftPost.posts.length.should.be.above(0);
draftPost.posts[0].title.should.eql(newTitle);
testUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
localUtils.API.checkResponse(draftPost.posts[0], 'post', 'tags');
draftPost.posts[0].title = 'Vote for Casper in red';
draftPost.posts[0].status = draftState;
@ -1028,7 +1028,7 @@ describe('Post API', function () {
should.exist(putBody);
putBody.posts[0].page.should.be.ok();
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});
@ -1066,7 +1066,7 @@ describe('Post API', function () {
res.headers['x-cache-invalidate'].should.eql('/*');
should.exist(putBody);
putBody.posts[0].page.should.not.be.ok();
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});
@ -1201,7 +1201,7 @@ describe('Post API', function () {
should.fail('null', 'valid date', 'publish_at should not be empty');
done();
}
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});
@ -1326,7 +1326,7 @@ describe('Post API', function () {
res.headers['x-cache-invalidate'].should.eql('/p/' + postBody.posts[0].uuid + '/');
should.exist(postBody);
testUtils.API.checkResponse(postBody.posts[0], 'post');
localUtils.API.checkResponse(postBody.posts[0], 'post');
done();
});
});
@ -1383,7 +1383,7 @@ describe('Post API', function () {
putBody.posts[0].title.should.eql(changedTitle);
putBody.posts[0].slug.should.eql(changedSlug);
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});
@ -1443,7 +1443,7 @@ describe('Post API', function () {
res.headers['x-cache-invalidate'].should.eql('/p/' + postBody.posts[0].uuid + '/');
should.exist(postBody);
testUtils.API.checkResponse(postBody.posts[0], 'post');
localUtils.API.checkResponse(postBody.posts[0], 'post');
done();
});
});
@ -1502,7 +1502,7 @@ describe('Post API', function () {
putBody.posts[0].title.should.eql(changedTitle);
putBody.posts[0].slug.should.eql(changedSlug);
testUtils.API.checkResponse(putBody.posts[0], 'post');
localUtils.API.checkResponse(putBody.posts[0], 'post');
done();
});
});

View File

@ -47,10 +47,10 @@ describe('Public API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -91,8 +91,8 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
// should content filtered data and order
jsonResponse.posts.should.have.length(4);
@ -146,8 +146,8 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.have.length(2);
@ -175,8 +175,8 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
// 2. The data part of the response should be correct
// We should have 2 matching items
@ -205,8 +205,8 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.be.an.Array().with.lengthOf(1);
@ -313,7 +313,7 @@ describe('Public API', function () {
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url']);
res.body.posts[0].url.should.eql('/welcome/');
done();
});
@ -333,7 +333,7 @@ describe('Public API', function () {
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url','tags']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url','tags']);
jsonResponse.posts[0].url.should.eql('http://127.0.0.1:2369/welcome/');
jsonResponse.posts[0].tags[0].url.should.eql('http://127.0.0.1:2369/tag/getting-started/');
done();
@ -429,10 +429,10 @@ describe('Public API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
done();
@ -475,10 +475,10 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
done();
@ -499,10 +499,10 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(15);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -520,10 +520,10 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(56);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -542,10 +542,10 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -717,11 +717,11 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(7);
// We don't expose the email address, status and other attrs.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
// Public api returns all users, but no status! Locked/Inactive users can still have written articles.
models.User.findPage(Object.assign({status: 'all'}, testUtils.context.internal))
@ -746,11 +746,11 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
done();
});
});
@ -792,7 +792,7 @@ describe('Public API', function () {
jsonResponse.users.should.have.length(1);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
done();
});
});
@ -815,7 +815,7 @@ describe('Public API', function () {
jsonResponse.users.should.have.length(1);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
done();
});
});
@ -838,7 +838,7 @@ describe('Public API', function () {
jsonResponse.users.should.have.length(1);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
done();
});
});
@ -860,7 +860,7 @@ describe('Public API', function () {
jsonResponse.users.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
// Each user should have the correct count
_.find(jsonResponse.users, {slug:'joe-bloggs'}).count.posts.should.eql(4);
@ -921,7 +921,7 @@ describe('Public API', function () {
should.exist(jsonResponse.users);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
done();
});
});
@ -940,11 +940,11 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['count'], null, null, {public: true});
done();
});
});
@ -963,11 +963,11 @@ describe('Public API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.users[0], 'user', null, null, null, {public: true});
done();
});
});

View File

@ -39,14 +39,14 @@ describe('Roles API', function () {
const response = res.body;
should.exist(response);
should.exist(response.roles);
testUtils.API.checkResponse(response, 'roles');
localUtils.API.checkResponse(response, 'roles');
response.roles.should.have.length(6);
testUtils.API.checkResponse(response.roles[0], 'role');
testUtils.API.checkResponse(response.roles[1], 'role');
testUtils.API.checkResponse(response.roles[2], 'role');
testUtils.API.checkResponse(response.roles[3], 'role');
testUtils.API.checkResponse(response.roles[4], 'role');
testUtils.API.checkResponse(response.roles[5], 'role');
localUtils.API.checkResponse(response.roles[0], 'role');
localUtils.API.checkResponse(response.roles[1], 'role');
localUtils.API.checkResponse(response.roles[2], 'role');
localUtils.API.checkResponse(response.roles[3], 'role');
localUtils.API.checkResponse(response.roles[4], 'role');
localUtils.API.checkResponse(response.roles[5], 'role');
done();
});
@ -66,12 +66,12 @@ describe('Roles API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const response = res.body;
should.exist(response.roles);
testUtils.API.checkResponse(response, 'roles');
localUtils.API.checkResponse(response, 'roles');
response.roles.should.have.length(4);
testUtils.API.checkResponse(response.roles[0], 'role');
testUtils.API.checkResponse(response.roles[1], 'role');
testUtils.API.checkResponse(response.roles[2], 'role');
testUtils.API.checkResponse(response.roles[3], 'role');
localUtils.API.checkResponse(response.roles[0], 'role');
localUtils.API.checkResponse(response.roles[1], 'role');
localUtils.API.checkResponse(response.roles[2], 'role');
localUtils.API.checkResponse(response.roles[3], 'role');
response.roles[0].name.should.equal('Administrator');
response.roles[1].name.should.equal('Editor');
response.roles[2].name.should.equal('Author');

View File

@ -45,7 +45,7 @@ describe('Settings API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
testUtils.API.checkResponse(jsonResponse, 'settings');
localUtils.API.checkResponse(jsonResponse, 'settings');
JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).isActive.should.eql(true);
JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(true);
@ -158,7 +158,7 @@ describe('Settings API', function () {
res.headers['x-cache-invalidate'].should.eql('/*');
should.exist(putBody);
putBody.settings[0].value.should.eql(JSON.stringify(changedValue));
testUtils.API.checkResponse(putBody, 'settings');
localUtils.API.checkResponse(putBody, 'settings');
done();
});
});

View File

@ -39,7 +39,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('a-post-title');
done();
@ -62,7 +62,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('atag');
done();
@ -85,7 +85,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('user-name');
done();
@ -108,7 +108,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('cool-app');
done();

View File

@ -49,7 +49,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
testUtils.API.isISO8601(jsonResponse.subscribers[0].created_at).should.be.true();
jsonResponse.subscribers[0].created_at.should.be.an.instanceof(String);
@ -76,7 +76,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
});
});
@ -99,7 +99,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
// testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber'); // TODO: modify checked schema
// localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber'); // TODO: modify checked schema
jsonResponse.subscribers[0].name.should.equal(subscriber.name);
jsonResponse.subscribers[0].email.should.equal(subscriber.email);
});
@ -148,7 +148,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
jsonResponse.subscribers[0].name.should.equal(subscriberChanged.name);
jsonResponse.subscribers[0].email.should.equal(subscriberChanged.email);
});

View File

@ -36,7 +36,7 @@ describe('Tag API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(6);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', 'count');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', 'count');
testUtils.API.isISO8601(jsonResponse.tags[0].created_at).should.be.true();
jsonResponse.tags[0].created_at.should.be.an.instanceof(String);
@ -65,7 +65,7 @@ describe('Tag API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', 'count');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', 'count');
should.exist(jsonResponse.tags[0].count.posts);
});
});
@ -89,7 +89,7 @@ describe('Tag API', function () {
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
// @TODO: model layer has no defaults for these properties
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', null, [
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', null, [
'feature_image',
'meta_description',
'meta_title',
@ -140,7 +140,7 @@ describe('Tag API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag');
jsonResponse.tags[0].description.should.eql('hey ho ab ins klo');
});
});

View File

@ -80,30 +80,30 @@ describe('Themes API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(5);
testUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
jsonResponse.themes[0].name.should.eql('broken-theme');
jsonResponse.themes[0].package.should.be.an.Object().with.properties('name', 'version');
jsonResponse.themes[0].active.should.be.false();
testUtils.API.checkResponse(jsonResponse.themes[1], 'theme', 'templates');
localUtils.API.checkResponse(jsonResponse.themes[1], 'theme', 'templates');
jsonResponse.themes[1].name.should.eql('casper');
jsonResponse.themes[1].package.should.be.an.Object().with.properties('name', 'version');
jsonResponse.themes[1].active.should.be.true();
testUtils.API.checkResponse(jsonResponse.themes[2], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[2], 'theme');
jsonResponse.themes[2].name.should.eql('casper-1.4');
jsonResponse.themes[2].package.should.be.an.Object().with.properties('name', 'version');
jsonResponse.themes[2].active.should.be.false();
testUtils.API.checkResponse(jsonResponse.themes[3], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[3], 'theme');
jsonResponse.themes[3].name.should.eql('test-theme');
jsonResponse.themes[3].package.should.be.false;
jsonResponse.themes[3].active.should.be.false();
testUtils.API.checkResponse(jsonResponse.themes[4], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[4], 'theme');
jsonResponse.themes[4].name.should.eql('test-theme-channels');
jsonResponse.themes[4].package.should.be.false;
jsonResponse.themes[4].active.should.be.false();
@ -139,9 +139,9 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(1);
testUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
jsonResponse.themes[0].name.should.eql('valid');
jsonResponse.themes[0].active.should.be.false();
@ -155,9 +155,9 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(1);
testUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
localUtils.API.checkResponse(jsonResponse.themes[0], 'theme');
jsonResponse.themes[0].name.should.eql('valid');
jsonResponse.themes[0].active.should.be.false();
@ -196,19 +196,19 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(6);
// Casper should be present and still active
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
should.exist(casperTheme);
testUtils.API.checkResponse(casperTheme, 'theme', 'templates');
localUtils.API.checkResponse(casperTheme, 'theme', 'templates');
casperTheme.active.should.be.true();
// The added theme should be here
addedTheme = _.find(jsonResponse.themes, {name: 'valid'});
should.exist(addedTheme);
testUtils.API.checkResponse(addedTheme, 'theme');
localUtils.API.checkResponse(addedTheme, 'theme');
addedTheme.active.should.be.false();
done();
@ -268,13 +268,13 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(5);
// Casper should be present and still active
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
should.exist(casperTheme);
testUtils.API.checkResponse(casperTheme, 'theme', 'templates');
localUtils.API.checkResponse(casperTheme, 'theme', 'templates');
casperTheme.active.should.be.true();
// The deleted theme should not be here
@ -298,9 +298,9 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(1);
testUtils.API.checkResponse(jsonResponse.themes[0], 'theme', ['warnings']);
localUtils.API.checkResponse(jsonResponse.themes[0], 'theme', ['warnings']);
jsonResponse.themes[0].name.should.eql('warnings');
jsonResponse.themes[0].active.should.be.false();
jsonResponse.themes[0].warnings.should.be.an.Array();
@ -333,17 +333,17 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(5);
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
should.exist(casperTheme);
testUtils.API.checkResponse(casperTheme, 'theme', 'templates');
localUtils.API.checkResponse(casperTheme, 'theme', 'templates');
casperTheme.active.should.be.true();
testTheme = _.find(jsonResponse.themes, {name: 'test-theme'});
should.exist(testTheme);
testUtils.API.checkResponse(testTheme, 'theme');
localUtils.API.checkResponse(testTheme, 'theme');
testTheme.active.should.be.false();
// Finally activate the new theme
@ -358,7 +358,7 @@ describe('Themes API', function () {
jsonResponse = res.body;
should.exist(jsonResponse.themes);
testUtils.API.checkResponse(jsonResponse, 'themes');
localUtils.API.checkResponse(jsonResponse, 'themes');
jsonResponse.themes.length.should.eql(1);
casperTheme = _.find(jsonResponse.themes, {name: 'casper'});
@ -366,7 +366,7 @@ describe('Themes API', function () {
testTheme = _.find(jsonResponse.themes, {name: 'test-theme'});
should.exist(testTheme);
testUtils.API.checkResponse(testTheme, 'theme', ['warnings', 'templates']);
localUtils.API.checkResponse(testTheme, 'theme', ['warnings', 'templates']);
testTheme.active.should.be.true();
testTheme.warnings.should.be.an.Array();
@ -490,7 +490,7 @@ describe('Themes API', function () {
testTheme = _.find(jsonResponse.themes, {name: 'test-theme'});
should.exist(testTheme);
testUtils.API.checkResponse(testTheme, 'theme', ['warnings', 'templates']);
localUtils.API.checkResponse(testTheme, 'theme', ['warnings', 'templates']);
testTheme.active.should.be.true();
testTheme.warnings.should.be.an.Array();

View File

@ -98,13 +98,13 @@ describe('User API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
// owner use + ghost-author user when Ghost starts
// and two extra users, see createUser in before
jsonResponse.users.should.have.length(6);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
testUtils.API.isISO8601(jsonResponse.users[5].last_seen).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[5].created_at).should.be.true();
testUtils.API.isISO8601(jsonResponse.users[5].updated_at).should.be.true();
@ -136,10 +136,10 @@ describe('User API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(6);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', 'roles');
localUtils.API.checkResponse(jsonResponse.users[0], 'user', 'roles');
done();
});
});
@ -163,7 +163,7 @@ describe('User API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
done();
});
});
@ -185,7 +185,7 @@ describe('User API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
done();
});
});
@ -207,7 +207,7 @@ describe('User API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
done();
});
});
@ -229,7 +229,7 @@ describe('User API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user');
localUtils.API.checkResponse(jsonResponse.users[0], 'user');
done();
});
});
@ -251,8 +251,8 @@ describe('User API', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'count']);
testUtils.API.checkResponse(jsonResponse.users[0].roles[0], 'role', ['permissions']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'count']);
localUtils.API.checkResponse(jsonResponse.users[0].roles[0], 'role', ['permissions']);
done();
});
});
@ -323,7 +323,7 @@ describe('User API', function () {
should.exist(putBody.users[0]);
putBody.users[0].website.should.eql('http://joe-bloggs.ghost.org');
putBody.users[0].email.should.eql('jbloggs@example.com');
testUtils.API.checkResponse(putBody.users[0], 'user');
localUtils.API.checkResponse(putBody.users[0], 'user');
should.not.exist(putBody.users[0].password);

View File

@ -1,12 +1,98 @@
const url = require('url');
const _ = require('lodash');
const testUtils = require('../../../utils');
const schema = require('../../../../server/data/schema').tables;
const API_URL = '/ghost/api/v0.1/';
const expectedProperties = {
// API top level
posts: ['posts', 'meta'],
tags: ['tags', 'meta'],
users: ['users', 'meta'],
authors: ['authors', 'meta'],
settings: ['settings', 'meta'],
subscribers: ['subscribers', 'meta'],
roles: ['roles'],
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
slugs: ['slugs'],
slug: ['slug'],
post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author
.without('author_id').concat('author', 'url', 'primary_tag', 'primary_author')
.value(),
user: {
default: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),
public: _(schema.users)
.keys()
.without(
'password',
'email',
'ghost_auth_access_token',
'ghost_auth_id',
'created_at',
'created_by',
'updated_at',
'updated_by',
'last_seen',
'status'
)
.value()
},
author: _(schema.users)
.keys()
.without(
'password',
'email',
'ghost_auth_access_token',
'ghost_auth_id',
'created_at',
'created_by',
'updated_at',
'updated_by',
'last_seen',
'status'
)
.value()
,
// Tag API swaps parent_id to parent
tag: _(schema.tags).keys().without('parent_id').concat('parent').value(),
setting: _.keys(schema.settings),
subscriber: _.keys(schema.subscribers),
accesstoken: _.keys(schema.accesstokens),
role: _.keys(schema.roles),
permission: _.keys(schema.permissions),
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
theme: ['name', 'package', 'active'],
themes: ['themes'],
invites: ['invites', 'meta'],
invite: _(schema.invites).keys().without('token').value(),
webhook: {
default: _(schema.webhooks)
.keys()
.without(
'name',
'last_triggered_at',
'last_triggered_error',
'last_triggered_status',
'secret',
'integration_id'
)
.value()
}
};
module.exports = {
API: {
getApiQuery(route) {
return url.resolve(API_URL, route);
},
checkResponse(...args) {
this.expectedProperties = expectedProperties;
return testUtils.API.checkResponse.call(this, ...args);
}
},

View File

@ -47,7 +47,7 @@ describe('Webhooks API', function () {
should.exist(jsonResponse.webhooks);
testUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
localUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
jsonResponse.webhooks[0].event.should.equal(newWebhook.event);
jsonResponse.webhooks[0].target_url.should.equal(newWebhook.target_url);
@ -80,7 +80,7 @@ describe('Webhooks API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.webhooks);
testUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
localUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
jsonResponse.webhooks[0].event.should.equal(newWebhook.event);
jsonResponse.webhooks[0].target_url.should.equal(newWebhook.target_url);

View File

@ -52,8 +52,8 @@ describe('Invites API V2', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(2);
testUtils.API.checkResponse(jsonResponse, 'invites');
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse, 'invites');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
jsonResponse.invites[0].status.should.eql('sent');
jsonResponse.invites[0].email.should.eql('test1@ghost.org');
@ -88,7 +88,7 @@ describe('Invites API V2', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
mailService.GhostMailer.prototype.send.called.should.be.false();
@ -119,7 +119,7 @@ describe('Invites API V2', function () {
should.exist(jsonResponse.invites);
jsonResponse.invites.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
localUtils.API.checkResponse(jsonResponse.invites[0], 'invite');
jsonResponse.invites[0].role_id.should.eql(testUtils.existingData.roles[1].id);
mailService.GhostMailer.prototype.send.called.should.be.true();

View File

@ -44,7 +44,7 @@ describe('Notifications API V2', function () {
should.exist(jsonResponse.notifications);
testUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
jsonResponse.notifications[0].type.should.equal(newNotification.type);
jsonResponse.notifications[0].message.should.equal(newNotification.message);
@ -178,7 +178,7 @@ describe('Notifications API V2', function () {
const jsonResponse = res.body;
should.exist(jsonResponse.notifications);
testUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
localUtils.API.checkResponse(jsonResponse.notifications[0], 'notification');
jsonResponse.notifications.length.should.eql(1);
jsonResponse.notifications[0].type.should.equal(newNotification.type);

View File

@ -44,10 +44,10 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -77,10 +77,10 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(3);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -105,10 +105,10 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(
localUtils.API.checkResponse(
jsonResponse.posts[0],
'post',
null,
@ -116,7 +116,7 @@ describe('Posts API V2', function () {
['mobiledoc', 'id', 'title', 'html']
);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
@ -136,15 +136,15 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(
localUtils.API.checkResponse(
jsonResponse.posts[0],
'post',
['tags', 'authors']
);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts[0].tags.length.should.eql(1);
jsonResponse.posts[0].authors.length.should.eql(1);
@ -169,9 +169,9 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(
localUtils.API.checkResponse(
jsonResponse.posts[0],
'post',
null,
@ -179,7 +179,7 @@ describe('Posts API V2', function () {
['mobiledoc', 'id', 'title', 'html', 'authors']
);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
@ -199,10 +199,10 @@ describe('Posts API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(15);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -241,7 +241,7 @@ describe('Posts API V2', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
jsonResponse.posts[0].page.should.not.be.ok();
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -273,7 +273,7 @@ describe('Posts API V2', function () {
jsonResponse.posts.should.have.length(1);
jsonResponse.posts[0].id.should.equal(testUtils.DataGenerator.Content.posts[0].id);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['mobiledoc', 'plaintext'], ['html']);
done();
});
@ -294,7 +294,7 @@ describe('Posts API V2', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].slug.should.equal('welcome');
jsonResponse.posts[0].page.should.not.be.ok();
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
@ -324,16 +324,16 @@ describe('Posts API V2', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['tags', 'authors']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', ['tags', 'authors']);
jsonResponse.posts[0].author.should.be.a.String();
jsonResponse.posts[0].page.should.not.be.ok();
jsonResponse.posts[0].authors[0].should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].authors[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.posts[0].authors[0], 'user', ['url']);
jsonResponse.posts[0].tags[0].should.be.an.Object();
testUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag', ['url']);
localUtils.API.checkResponse(jsonResponse.posts[0].tags[0], 'tag', ['url']);
done();
});
});
@ -381,7 +381,7 @@ describe('Posts API V2', function () {
.expect(201)
.then((res) => {
res.body.posts.length.should.eql(1);
testUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post');
should.not.exist(res.headers['x-cache-invalidate']);
res.body.posts[0].title.should.eql(post.title);
@ -412,7 +412,7 @@ describe('Posts API V2', function () {
.expect(201)
.then((res) => {
res.body.posts.length.should.eql(1);
testUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post');
res.body.posts[0].status.should.eql('published');
res.headers['x-cache-invalidate'].should.eql('/*');
@ -440,7 +440,7 @@ describe('Posts API V2', function () {
.expect(200)
.then((res) => {
res.headers['x-cache-invalidate'].should.eql('/*');
testUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post');
res.body.posts[0].title.should.eql(post.title);
res.body.posts[0].author.should.eql(post.author);
@ -466,7 +466,7 @@ describe('Posts API V2', function () {
.expect(200)
.then((res) => {
res.headers['x-cache-invalidate'].should.eql('/*');
testUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post');
// We expect that the changed properties aren't changed, they are still the same than before.
res.body.posts[0].created_by.should.not.eql(post.created_by);
@ -526,7 +526,7 @@ describe('Posts API V2', function () {
res.headers['x-cache-invalidate'].should.eql('/*');
should.exist(res.body.posts);
should.exist(res.body.posts[0].published_at);
testUtils.API.checkResponse(res.body.posts[0], 'post');
localUtils.API.checkResponse(res.body.posts[0], 'post');
});
});
});

View File

@ -35,14 +35,14 @@ describe('Roles API', function () {
const response = res.body;
should.exist(response);
should.exist(response.roles);
testUtils.API.checkResponse(response, 'roles');
localUtils.API.checkResponse(response, 'roles');
response.roles.should.have.length(6);
testUtils.API.checkResponse(response.roles[0], 'role');
testUtils.API.checkResponse(response.roles[1], 'role');
testUtils.API.checkResponse(response.roles[2], 'role');
testUtils.API.checkResponse(response.roles[3], 'role');
testUtils.API.checkResponse(response.roles[4], 'role');
testUtils.API.checkResponse(response.roles[5], 'role');
localUtils.API.checkResponse(response.roles[0], 'role');
localUtils.API.checkResponse(response.roles[1], 'role');
localUtils.API.checkResponse(response.roles[2], 'role');
localUtils.API.checkResponse(response.roles[3], 'role');
localUtils.API.checkResponse(response.roles[4], 'role');
localUtils.API.checkResponse(response.roles[5], 'role');
done();
});
@ -62,12 +62,12 @@ describe('Roles API', function () {
should.not.exist(res.headers['x-cache-invalidate']);
const response = res.body;
should.exist(response.roles);
testUtils.API.checkResponse(response, 'roles');
localUtils.API.checkResponse(response, 'roles');
response.roles.should.have.length(4);
testUtils.API.checkResponse(response.roles[0], 'role');
testUtils.API.checkResponse(response.roles[1], 'role');
testUtils.API.checkResponse(response.roles[2], 'role');
testUtils.API.checkResponse(response.roles[3], 'role');
localUtils.API.checkResponse(response.roles[0], 'role');
localUtils.API.checkResponse(response.roles[1], 'role');
localUtils.API.checkResponse(response.roles[2], 'role');
localUtils.API.checkResponse(response.roles[3], 'role');
response.roles[0].name.should.equal('Administrator');
response.roles[1].name.should.equal('Editor');
response.roles[2].name.should.equal('Author');

View File

@ -42,7 +42,7 @@ describe('Settings API V2', function () {
var jsonResponse = res.body;
should.exist(jsonResponse);
testUtils.API.checkResponse(jsonResponse, 'settings');
localUtils.API.checkResponse(jsonResponse, 'settings');
JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).isActive.should.eql(true);
JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(true);
@ -164,7 +164,7 @@ describe('Settings API V2', function () {
res.headers['x-cache-invalidate'].should.eql('/*');
should.exist(putBody);
putBody.settings[0].value.should.eql(JSON.stringify(changedValue));
testUtils.API.checkResponse(putBody, 'settings');
localUtils.API.checkResponse(putBody, 'settings');
done();
});
});

View File

@ -36,7 +36,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('a-post-title');
done();
@ -59,7 +59,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('atag');
done();
@ -82,7 +82,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('user-name');
done();
@ -105,7 +105,7 @@ describe('Slug API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.slugs);
jsonResponse.slugs.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
localUtils.API.checkResponse(jsonResponse.slugs[0], 'slug');
jsonResponse.slugs[0].slug.should.equal('cool-app');
done();

View File

@ -43,7 +43,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
testUtils.API.isISO8601(jsonResponse.subscribers[0].created_at).should.be.true();
jsonResponse.subscribers[0].created_at.should.be.an.instanceof(String);
@ -70,7 +70,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
});
});
@ -93,7 +93,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
// testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber'); // TODO: modify checked schema
// localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber'); // TODO: modify checked schema
jsonResponse.subscribers[0].name.should.equal(subscriber.name);
jsonResponse.subscribers[0].email.should.equal(subscriber.email);
});
@ -142,7 +142,7 @@ describe('Subscribers API', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.subscribers);
jsonResponse.subscribers.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
localUtils.API.checkResponse(jsonResponse.subscribers[0], 'subscriber');
jsonResponse.subscribers[0].name.should.equal(subscriberChanged.name);
jsonResponse.subscribers[0].email.should.equal(subscriberChanged.email);
});

View File

@ -33,7 +33,7 @@ describe('Tag API V2', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(6);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['count', 'url']);
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['count', 'url']);
testUtils.API.isISO8601(jsonResponse.tags[0].created_at).should.be.true();
jsonResponse.tags[0].created_at.should.be.an.instanceof(String);
@ -76,7 +76,7 @@ describe('Tag API V2', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['count', 'url']);
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['count', 'url']);
should.exist(jsonResponse.tags[0].count.posts);
jsonResponse.tags[0].url.should.eql(`${config.get('url')}/tag/getting-started/`);
@ -102,7 +102,7 @@ describe('Tag API V2', function () {
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
// @TODO: model layer has no defaults for these properties
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url'], [
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url'], [
'feature_image',
'meta_description',
'meta_title',
@ -153,7 +153,7 @@ describe('Tag API V2', function () {
should.exist(jsonResponse);
should.exist(jsonResponse.tags);
jsonResponse.tags.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
jsonResponse.tags[0].description.should.eql('hey ho ab ins klo');
});
});

View File

@ -62,13 +62,13 @@ describe('User API V2', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
// owner use + ghost-author user when Ghost starts
// and two extra users, see createUser in before
jsonResponse.users.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
jsonResponse.users[0].email.should.eql(admin.email);
jsonResponse.users[0].status.should.eql(admin.status);
@ -106,10 +106,10 @@ describe('User API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.users);
testUtils.API.checkResponse(jsonResponse, 'users');
localUtils.API.checkResponse(jsonResponse, 'users');
jsonResponse.users.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'url']);
done();
});
});
@ -150,7 +150,7 @@ describe('User API V2', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
done();
});
});
@ -172,7 +172,7 @@ describe('User API V2', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
done();
});
});
@ -194,7 +194,7 @@ describe('User API V2', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
done();
});
});
@ -216,7 +216,7 @@ describe('User API V2', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['url']);
done();
});
});
@ -238,8 +238,8 @@ describe('User API V2', function () {
should.not.exist(jsonResponse.meta);
jsonResponse.users.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'count', 'url']);
testUtils.API.checkResponse(jsonResponse.users[0].roles[0], 'role', ['permissions']);
localUtils.API.checkResponse(jsonResponse.users[0], 'user', ['roles', 'count', 'url']);
localUtils.API.checkResponse(jsonResponse.users[0].roles[0], 'role', ['permissions']);
done();
});
});
@ -310,7 +310,7 @@ describe('User API V2', function () {
should.exist(putBody.users[0]);
putBody.users[0].website.should.eql('http://joe-bloggs.ghost.org');
putBody.users[0].email.should.eql('jbloggs@example.com');
testUtils.API.checkResponse(putBody.users[0], 'user', ['url']);
localUtils.API.checkResponse(putBody.users[0], 'user', ['url']);
should.not.exist(putBody.users[0].password);

View File

@ -1,12 +1,62 @@
const url = require('url');
const _ = require('lodash');
const testUtils = require('../../../../utils');
const schema = require('../../../../../server/data/schema').tables;
const API_URL = '/ghost/api/v2/admin/';
const expectedProperties = {
// API top level
posts: ['posts', 'meta'],
tags: ['tags', 'meta'],
users: ['users', 'meta'],
settings: ['settings', 'meta'],
subscribers: ['subscribers', 'meta'],
roles: ['roles'],
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
slugs: ['slugs'],
slug: ['slug'],
post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author
.without('author_id').concat('author', 'url', 'primary_tag', 'primary_author')
.value(),
user: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),
// Tag API swaps parent_id to parent
tag: _(schema.tags).keys().without('parent_id').concat('parent').value(),
setting: _.keys(schema.settings),
subscriber: _.keys(schema.subscribers),
accesstoken: _.keys(schema.accesstokens),
role: _.keys(schema.roles),
permission: _.keys(schema.permissions),
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
theme: ['name', 'package', 'active'],
themes: ['themes'],
invites: ['invites', 'meta'],
invite: _(schema.invites).keys().without('token').value(),
webhook: _(schema.webhooks)
.keys()
.without(
'name',
'last_triggered_at',
'last_triggered_error',
'last_triggered_status',
'secret',
'integration_id'
)
.value()
};
module.exports = {
API: {
getApiQuery(route) {
return url.resolve(API_URL, route);
},
checkResponse(...args) {
this.expectedProperties = expectedProperties;
return testUtils.API.checkResponse.call(this, ...args);
}
},

View File

@ -45,7 +45,7 @@ describe('Webhooks API', function () {
should.exist(jsonResponse.webhooks);
testUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
localUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
jsonResponse.webhooks[0].event.should.equal(newWebhook.event);
jsonResponse.webhooks[0].target_url.should.equal(newWebhook.target_url);
@ -77,7 +77,7 @@ describe('Webhooks API', function () {
should.exist(jsonResponse.webhooks);
testUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook', ['name', 'secret']);
localUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook', ['name', 'secret']);
jsonResponse.webhooks[0].event.should.equal(webhookData.event);
jsonResponse.webhooks[0].target_url.should.equal(webhookData.target_url);
@ -176,7 +176,7 @@ describe('Webhooks API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.webhooks);
testUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
localUtils.API.checkResponse(jsonResponse.webhooks[0], 'webhook');
jsonResponse.webhooks[0].event.should.equal(newWebhook.event);
jsonResponse.webhooks[0].target_url.should.equal(newWebhook.target_url);

View File

@ -44,11 +44,11 @@ describe('Authors Content API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.authors);
testUtils.API.checkResponse(jsonResponse, 'authors');
localUtils.API.checkResponse(jsonResponse, 'authors');
jsonResponse.authors.should.have.length(7);
// We don't expose the email address, status and other attrs.
testUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['url'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['url'], null, null);
should.exist(res.body.authors[0].url);
should.exist(url.parse(res.body.authors[0].url).protocol);
@ -97,7 +97,7 @@ describe('Authors Content API V2', function () {
jsonResponse.authors.should.have.length(1);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null);
done();
});
});
@ -120,7 +120,7 @@ describe('Authors Content API V2', function () {
jsonResponse.authors.should.have.length(1);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null);
done();
});
});
@ -142,7 +142,7 @@ describe('Authors Content API V2', function () {
jsonResponse.authors.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null);
// Each user should have the correct count
_.find(jsonResponse.authors, {slug:'joe-bloggs'}).count.posts.should.eql(4);
@ -184,11 +184,11 @@ describe('Authors Content API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.authors);
testUtils.API.checkResponse(jsonResponse, 'authors');
localUtils.API.checkResponse(jsonResponse, 'authors');
jsonResponse.authors.should.have.length(7);
// We don't expose the email address.
testUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null, {public: true});
localUtils.API.checkResponse(jsonResponse.authors[0], 'author', ['count', 'url'], null, null);
done();
});
});

View File

@ -46,10 +46,10 @@ describe('Posts', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
@ -112,8 +112,8 @@ describe('Posts', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
// should content filtered data and order
jsonResponse.posts.should.have.length(4);
@ -166,8 +166,8 @@ describe('Posts', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.have.length(0);
done();
@ -187,8 +187,8 @@ describe('Posts', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
jsonResponse.posts.should.have.length(11);
jsonResponse.posts.forEach((post) => {
@ -213,8 +213,8 @@ describe('Posts', function () {
should.not.exist(res.headers['x-cache-invalidate']);
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
// 2. The data part of the response should be correct
// We should have 2 matching items
@ -297,7 +297,7 @@ describe('Posts', function () {
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url']);
res.body.posts[0].url.should.eql('http://127.0.0.1:2369/welcome/');
done();
});
@ -317,7 +317,7 @@ describe('Posts', function () {
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url','tags']);
localUtils.API.checkResponse(jsonResponse.posts[0], 'post', false, false, ['url','tags']);
jsonResponse.posts[0].url.should.eql('http://127.0.0.1:2369/welcome/');
jsonResponse.posts[0].tags[0].url.should.eql('http://127.0.0.1:2369/tag/getting-started/');
done();
@ -381,10 +381,10 @@ describe('Posts', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
done();
@ -427,10 +427,10 @@ describe('Posts', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.posts);
testUtils.API.checkResponse(jsonResponse, 'posts');
localUtils.API.checkResponse(jsonResponse, 'posts');
jsonResponse.posts.should.have.length(11);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
_.isBoolean(jsonResponse.posts[0].page).should.eql(true);
done();
@ -523,7 +523,7 @@ describe('Posts', function () {
should.exist(jsonResponse.posts);
should.not.exist(jsonResponse.meta);
jsonResponse.posts.should.have.length(1);
testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
jsonResponse.posts[0].page.should.eql(false);
});
});

View File

@ -44,10 +44,10 @@ describe('Tags Content API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(15);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
should.exist(res.body.tags[0].url);
should.exist(url.parse(res.body.tags[0].url).protocol);
@ -70,10 +70,10 @@ describe('Tags Content API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(56);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});
@ -92,10 +92,10 @@ describe('Tags Content API V2', function () {
should.not.exist(res.headers['x-cache-invalidate']);
var jsonResponse = res.body;
should.exist(jsonResponse.tags);
testUtils.API.checkResponse(jsonResponse, 'tags');
localUtils.API.checkResponse(jsonResponse, 'tags');
jsonResponse.tags.should.have.length(4);
testUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
testUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
localUtils.API.checkResponse(jsonResponse.tags[0], 'tag', ['url']);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
done();
});
});

View File

@ -1,11 +1,51 @@
const url = require('url');
const _ = require('lodash');
const testUtils = require('../../../../utils');
const schema = require('../../../../../server/data/schema').tables;
const API_URL = '/ghost/api/v2/content/';
const expectedProperties = {
// API top level
posts: ['posts', 'meta'],
tags: ['tags', 'meta'],
authors: ['authors', 'meta'],
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author
.without('author_id').concat('author', 'url', 'primary_tag', 'primary_author')
.value(),
author: _(schema.users)
.keys()
.without(
'password',
'email',
'ghost_auth_access_token',
'ghost_auth_id',
'created_at',
'created_by',
'updated_at',
'updated_by',
'last_seen',
'status'
)
.value()
,
// Tag API swaps parent_id to parent
tag: _(schema.tags).keys().without('parent_id').concat('parent').value()
};
module.exports = {
API: {
getApiQuery(route) {
return url.resolve(API_URL, route);
},
checkResponse(...args) {
this.expectedProperties = expectedProperties;
return testUtils.API.checkResponse.call(this, ...args);
}
},
getValidKey() {

View File

@ -1,93 +1,13 @@
var _ = require('lodash'),
url = require('url'),
moment = require('moment'),
DataGenerator = require('./fixtures/data-generator'),
config = require('../../server/config'),
common = require('../../server/lib/common'),
sequence = require('../../server/lib/promise/sequence'),
schema = require('../../server/data/schema').tables,
host = config.get('server').host,
port = config.get('server').port,
protocol = 'http://',
expectedProperties = {
// API top level
posts: ['posts', 'meta'],
tags: ['tags', 'meta'],
users: ['users', 'meta'],
authors: ['authors', 'meta'],
settings: ['settings', 'meta'],
subscribers: ['subscribers', 'meta'],
roles: ['roles'],
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
slugs: ['slugs'],
slug: ['slug'],
post: _(schema.posts)
.keys()
// by default we only return html
.without('mobiledoc', 'plaintext')
// swaps author_id to author, and always returns computed properties: url, comment_id, primary_tag, primary_author
.without('author_id').concat('author', 'url', 'primary_tag', 'primary_author')
.value(),
user: {
default: _(schema.users).keys().without('password').without('ghost_auth_access_token').value(),
public: _(schema.users)
.keys()
.without(
'password',
'email',
'ghost_auth_access_token',
'ghost_auth_id',
'created_at',
'created_by',
'updated_at',
'updated_by',
'last_seen',
'status'
)
.value()
},
author: _(schema.users)
.keys()
.without(
'password',
'email',
'ghost_auth_access_token',
'ghost_auth_id',
'created_at',
'created_by',
'updated_at',
'updated_by',
'last_seen',
'status'
)
.value()
,
// Tag API swaps parent_id to parent
tag: _(schema.tags).keys().without('parent_id').concat('parent').value(),
setting: _.keys(schema.settings),
subscriber: _.keys(schema.subscribers),
accesstoken: _.keys(schema.accesstokens),
role: _.keys(schema.roles),
permission: _.keys(schema.permissions),
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
theme: ['name', 'package', 'active'],
themes: ['themes'],
invites: ['invites', 'meta'],
invite: _(schema.invites).keys().without('token').value(),
webhook: {
default: _(schema.webhooks)
.keys()
.without(
'name',
'last_triggered_at',
'last_triggered_error',
'last_triggered_status',
'secret',
'integration_id'
)
.value()
}
};
const _ = require('lodash');
const url = require('url');
const moment = require('moment');
const DataGenerator = require('./fixtures/data-generator');
const config = require('../../server/config');
const common = require('../../server/lib/common');
const sequence = require('../../server/lib/promise/sequence');
const host = config.get('server').host;
const port = config.get('server').port;
const protocol = 'http://';
function getURL() {
return protocol + host;
@ -126,7 +46,7 @@ function checkResponseValue(jsonResponse, expectedProperties) {
function checkResponse(jsonResponse, objectType, additionalProperties, missingProperties, onlyProperties, options) {
options = options || {};
var checkProperties = options.public ? (expectedProperties[objectType].public || expectedProperties[objectType]) : (expectedProperties[objectType].default || expectedProperties[objectType]);
let checkProperties = options.public ? (this.expectedProperties[objectType].public || this.expectedProperties[objectType]) : (this.expectedProperties[objectType].default || this.expectedProperties[objectType]);
checkProperties = onlyProperties ? onlyProperties : checkProperties;
checkProperties = additionalProperties ? checkProperties.concat(additionalProperties) : checkProperties;