0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00
ghost/test/unit/api/v3/utils/serializers/input/pages.test.js
Hannah Wolfe f08a55c21f
Renamed tests to .test.js & updated commands
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
2021-07-06 20:45:01 +01:00

237 lines
7.3 KiB
JavaScript

const should = require('should');
const serializers = require('../../../../../../../core/server/api/v3/utils/serializers');
describe('Unit: v3/utils/serializers/input/pages', function () {
describe('browse', function () {
it('default', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('type:page');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'status:published+tag:eins',
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+type:page');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:false+tag:eins',
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false+tag:eins)+type:page');
});
it('combine filters', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:false',
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page');
});
it('remove mobiledoc option from formats', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
formats: ['html', 'mobiledoc', 'plaintext'],
context: {}
}
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.formats.should.not.containEql('mobiledoc');
frame.options.formats.should.containEql('html');
frame.options.formats.should.containEql('plaintext');
});
});
describe('read', function () {
it('content api default', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
context: {}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page');
});
it('content api default', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
context: {
user: 0,
api_key: {
id: 1,
type: 'content'
}
}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('type:page');
});
it('admin api default', function () {
const apiConfig = {};
const frame = {
apiType: 'admin',
options: {
context: {
user: 0,
api_key: {
id: 1,
type: 'admin'
}
}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]');
});
it('custom page filter', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:false',
context: {}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+type:page');
});
it('custom status filter', function () {
const apiConfig = {};
const frame = {
apiType: 'admin',
options: {
filter: 'status:draft',
context: {
user: 0,
api_key: {
id: 1,
type: 'admin'
}
}
},
data: {}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+type:page');
});
it('remove mobiledoc option from formats', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
formats: ['html', 'mobiledoc', 'plaintext'],
context: {}
},
data: {
status: 'all',
page: false
}
};
serializers.input.pages.read(apiConfig, frame);
frame.options.formats.should.not.containEql('mobiledoc');
frame.options.formats.should.containEql('html');
frame.options.formats.should.containEql('plaintext');
});
});
describe('Ensure relations format', function () {
it('relations is array of objects', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {},
data: {
pages: [
{
id: 'id1',
authors: [{id: 'id'}],
tags: [{slug: 'slug1', name: 'hey'}, {slug: 'slug2'}]
}
]
}
};
serializers.input.pages.edit(apiConfig, frame);
frame.data.pages[0].authors.should.eql([{id: 'id'}]);
frame.data.pages[0].tags.should.eql([{slug: 'slug1', name: 'hey'}, {slug: 'slug2'}]);
});
it('authors is array of strings', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {},
data: {
pages: [
{
id: 'id1',
authors: ['email1', 'email2'],
tags: ['name1', 'name2']
}
]
}
};
serializers.input.pages.edit(apiConfig, frame);
frame.data.pages[0].authors.should.eql([{email: 'email1'}, {email: 'email2'}]);
frame.data.pages[0].tags.should.eql([{name: 'name1'}, {name: 'name2'}]);
});
});
});