2018-10-05 01:50:45 +03:00
|
|
|
const should = require('should');
|
2022-08-11 17:39:37 +03:00
|
|
|
const shared = require('../');
|
2018-10-05 01:50:45 +03:00
|
|
|
|
2022-08-11 17:42:21 +03:00
|
|
|
describe('Frame', function () {
|
2018-10-05 01:50:45 +03:00
|
|
|
it('constructor', function () {
|
|
|
|
const frame = new shared.Frame();
|
|
|
|
Object.keys(frame).should.eql([
|
|
|
|
'original',
|
|
|
|
'options',
|
|
|
|
'data',
|
|
|
|
'user',
|
|
|
|
'file',
|
2019-02-13 18:59:10 +03:00
|
|
|
'files',
|
2022-08-21 18:31:41 +03:00
|
|
|
'apiType',
|
|
|
|
'docName',
|
|
|
|
'method',
|
|
|
|
'response'
|
2018-10-05 01:50:45 +03:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fn: configure', function () {
|
|
|
|
it('no transform', function () {
|
|
|
|
const original = {
|
|
|
|
context: {user: 'id'},
|
|
|
|
body: {posts: []},
|
|
|
|
params: {id: 'id'},
|
2022-05-16 13:35:02 +03:00
|
|
|
query: {include: 'tags', filter: 'type:post', soup: 'yumyum'}
|
2018-10-05 01:50:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-08-11 17:39:37 +03:00
|
|
|
it('transform with query', function () {
|
2018-10-05 01:50:45 +03:00
|
|
|
const original = {
|
|
|
|
context: {user: 'id'},
|
|
|
|
body: {posts: []},
|
|
|
|
params: {id: 'id'},
|
2022-05-16 13:35:02 +03:00
|
|
|
query: {include: 'tags', filter: 'type:post', soup: 'yumyum'}
|
2018-10-05 01:50:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-08-11 17:39:37 +03:00
|
|
|
it('transform with data', function () {
|
2018-10-05 01:50:45 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|