mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
f08a55c21f
refs: https://github.com/TryGhost/Team/issues/856 refs: https://github.com/TryGhost/Team/issues/756 - The .test.js extension is better than _spec.js as it's more obvious that it's an extension - It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test` - It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856) - Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
102 lines
2.8 KiB
JavaScript
102 lines
2.8 KiB
JavaScript
const should = require('should');
|
|
const shared = require('../../../../core/server/api/shared');
|
|
|
|
describe('Unit: api/shared/frame', function () {
|
|
it('constructor', function () {
|
|
const frame = new shared.Frame();
|
|
Object.keys(frame).should.eql([
|
|
'original',
|
|
'options',
|
|
'data',
|
|
'user',
|
|
'file',
|
|
'files',
|
|
'apiType'
|
|
]);
|
|
});
|
|
|
|
describe('fn: configure', function () {
|
|
it('no transform', function () {
|
|
const original = {
|
|
context: {user: 'id'},
|
|
body: {posts: []},
|
|
params: {id: 'id'},
|
|
query: {include: 'tags', filter: 'page:false', soup: 'yumyum'}
|
|
};
|
|
|
|
const frame = new shared.Frame(original);
|
|
|
|
frame.configure({});
|
|
|
|
should.exist(frame.options.context.user);
|
|
should.not.exist(frame.options.include);
|
|
should.not.exist(frame.options.filter);
|
|
should.not.exist(frame.options.id);
|
|
should.not.exist(frame.options.soup);
|
|
|
|
should.exist(frame.data.posts);
|
|
});
|
|
|
|
it('transform', function () {
|
|
const original = {
|
|
context: {user: 'id'},
|
|
body: {posts: []},
|
|
params: {id: 'id'},
|
|
query: {include: 'tags', filter: 'page:false', soup: 'yumyum'}
|
|
};
|
|
|
|
const frame = new shared.Frame(original);
|
|
|
|
frame.configure({
|
|
options: ['include', 'filter', 'id']
|
|
});
|
|
|
|
should.exist(frame.options.context.user);
|
|
should.exist(frame.options.include);
|
|
should.exist(frame.options.filter);
|
|
should.exist(frame.options.id);
|
|
should.not.exist(frame.options.soup);
|
|
|
|
should.exist(frame.data.posts);
|
|
});
|
|
|
|
it('transform', function () {
|
|
const original = {
|
|
context: {user: 'id'},
|
|
options: {
|
|
slug: 'slug'
|
|
}
|
|
};
|
|
|
|
const frame = new shared.Frame(original);
|
|
|
|
frame.configure({
|
|
options: ['include', 'filter', 'slug']
|
|
});
|
|
|
|
should.exist(frame.options.context.user);
|
|
should.exist(frame.options.slug);
|
|
});
|
|
|
|
it('transform', function () {
|
|
const original = {
|
|
context: {user: 'id'},
|
|
options: {
|
|
id: 'id'
|
|
},
|
|
body: {}
|
|
};
|
|
|
|
const frame = new shared.Frame(original);
|
|
|
|
frame.configure({
|
|
data: ['id']
|
|
});
|
|
|
|
should.exist(frame.options.context.user);
|
|
should.not.exist(frame.options.id);
|
|
should.exist(frame.data.id);
|
|
});
|
|
});
|
|
});
|