2018-10-05 01:50:45 +03:00
|
|
|
const should = require('should');
|
2020-03-30 18:26:47 +03:00
|
|
|
const shared = require('../../../../core/server/api/shared');
|
2018-10-05 01:50:45 +03:00
|
|
|
|
|
|
|
describe('Unit: api/shared/headers', function () {
|
|
|
|
it('empty headers config', function () {
|
2019-07-05 14:40:43 +03:00
|
|
|
return shared.headers.get().then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('config.disposition', function () {
|
|
|
|
it('json', function () {
|
2018-12-17 14:47:19 +03:00
|
|
|
return shared.headers.get({}, {disposition: {type: 'json', value: 'value'}})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({
|
2019-01-14 21:05:16 +03:00
|
|
|
'Content-Disposition': 'Attachment; filename=\"value\"',
|
2018-12-17 14:47:19 +03:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Content-Length': 2
|
|
|
|
});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('csv', function () {
|
2018-12-17 14:47:19 +03:00
|
|
|
return shared.headers.get({}, {disposition: {type: 'csv', value: 'my.csv'}})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({
|
2019-01-14 21:05:16 +03:00
|
|
|
'Content-Disposition': 'Attachment; filename=\"my.csv\"',
|
2018-12-17 14:47:19 +03:00
|
|
|
'Content-Type': 'text/csv'
|
|
|
|
});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('yaml', function () {
|
2018-12-17 14:47:19 +03:00
|
|
|
return shared.headers.get('yaml file', {disposition: {type: 'yaml', value: 'my.yaml'}})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({
|
2019-01-14 21:05:16 +03:00
|
|
|
'Content-Disposition': 'Attachment; filename=\"my.yaml\"',
|
2018-12-17 14:47:19 +03:00
|
|
|
'Content-Type': 'application/yaml',
|
|
|
|
'Content-Length': 11
|
|
|
|
});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('config.cacheInvalidate', function () {
|
|
|
|
it('default', function () {
|
2018-12-17 14:47:19 +03:00
|
|
|
return shared.headers.get({}, {cacheInvalidate: true})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({
|
|
|
|
'X-Cache-Invalidate': '/*'
|
|
|
|
});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('custom value', function () {
|
2018-12-17 14:47:19 +03:00
|
|
|
return shared.headers.get({}, {cacheInvalidate: {value: 'value'}})
|
2019-07-05 14:40:43 +03:00
|
|
|
.then((result) => {
|
2018-12-17 14:47:19 +03:00
|
|
|
result.should.eql({
|
|
|
|
'X-Cache-Invalidate': 'value'
|
|
|
|
});
|
|
|
|
});
|
2018-10-05 01:50:45 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|