2022-11-09 06:56:07 +03:00
|
|
|
const testStatic = function (prefix, q, format, status, scale, type, query) {
|
2016-03-09 15:22:06 +03:00
|
|
|
if (scale) q += '@' + scale + 'x';
|
2022-09-28 21:41:55 +03:00
|
|
|
let path = '/styles/' + prefix + '/static/' + q + '.' + format;
|
2016-06-27 09:11:02 +03:00
|
|
|
if (query) {
|
|
|
|
path += query;
|
|
|
|
}
|
2022-11-09 06:56:07 +03:00
|
|
|
it(path + ' returns ' + status, function (done) {
|
2022-09-28 21:41:55 +03:00
|
|
|
const test = supertest(app).get(path);
|
2016-03-09 15:22:06 +03:00
|
|
|
if (status) test.expect(status);
|
|
|
|
if (type) test.expect('Content-Type', type);
|
|
|
|
test.end(done);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-09-28 21:41:55 +03:00
|
|
|
const prefix = 'test-style';
|
2016-07-27 07:32:53 +03:00
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('Static endpoints', function () {
|
|
|
|
describe('center-based', function () {
|
|
|
|
describe('valid requests', function () {
|
|
|
|
describe('various formats', function () {
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'0,0,0/256x256',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/png/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'0,0,0/256x256',
|
|
|
|
'jpg',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/jpeg/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'0,0,0/256x256',
|
|
|
|
'jpeg',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/jpeg/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'0,0,0/256x256',
|
|
|
|
'webp',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/webp/,
|
|
|
|
);
|
2016-03-09 19:25:53 +03:00
|
|
|
});
|
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('different parameters', function () {
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '0,0,0/300x300', 'png', 200, 2);
|
|
|
|
testStatic(prefix, '0,0,0/300x300', 'png', 200, 3);
|
|
|
|
|
2016-08-25 12:09:01 +03:00
|
|
|
testStatic(prefix, '0,0,1.5/256x256', 'png', 200);
|
|
|
|
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '80,40,20/600x300', 'png', 200, 3);
|
|
|
|
testStatic(prefix, '8.5,40.5,20/300x150', 'png', 200, 3);
|
|
|
|
testStatic(prefix, '-8.5,-40.5,20/300x150', 'png', 200, 3);
|
|
|
|
|
|
|
|
testStatic(prefix, '8,40,2@0,0/300x150', 'png', 200);
|
|
|
|
testStatic(prefix, '8,40,2@180,45/300x150', 'png', 200, 2);
|
|
|
|
testStatic(prefix, '8,40,2@10/300x150', 'png', 200, 3);
|
|
|
|
testStatic(prefix, '8,40,2@10.3,20.4/300x300', 'png', 200);
|
|
|
|
testStatic(prefix, '0,0,2@390,120/300x300', 'png', 200);
|
2016-03-09 19:25:53 +03:00
|
|
|
});
|
2016-03-09 15:22:06 +03:00
|
|
|
});
|
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('invalid requests return 4xx', function () {
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '190,0,0/256x256', 'png', 400);
|
|
|
|
testStatic(prefix, '0,86,0/256x256', 'png', 400);
|
|
|
|
testStatic(prefix, '80,40,20/0x0', 'png', 400);
|
|
|
|
testStatic(prefix, '0,0,0/256x256', 'gif', 400);
|
|
|
|
testStatic(prefix, '0,0,0/256x256', 'png', 404, 1);
|
|
|
|
|
|
|
|
testStatic(prefix, '0,0,-1/256x256', 'png', 404);
|
|
|
|
testStatic(prefix, '0,0,0/256.5x256.5', 'png', 404);
|
|
|
|
|
|
|
|
testStatic(prefix, '0,0,0,/256x256', 'png', 404);
|
|
|
|
testStatic(prefix, '0,0,0,0,/256x256', 'png', 404);
|
2016-03-09 15:22:06 +03:00
|
|
|
});
|
|
|
|
});
|
2016-03-09 19:25:53 +03:00
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('area-based', function () {
|
|
|
|
describe('valid requests', function () {
|
|
|
|
describe('various formats', function () {
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'-180,-80,180,80/10x10',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/png/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'-180,-80,180,80/10x10',
|
|
|
|
'jpg',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/jpeg/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'-180,-80,180,80/10x10',
|
|
|
|
'jpeg',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/jpeg/,
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'-180,-80,180,80/10x10',
|
|
|
|
'webp',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/webp/,
|
|
|
|
);
|
2016-03-09 19:25:53 +03:00
|
|
|
});
|
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('different parameters', function () {
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '-180,-90,180,90/20x20', 'png', 200, 2);
|
|
|
|
testStatic(prefix, '0,0,1,1/200x200', 'png', 200, 3);
|
2016-03-09 19:25:53 +03:00
|
|
|
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '-280,-80,0,80/280x160', 'png', 200);
|
2016-03-09 19:25:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('invalid requests return 4xx', function () {
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '0,87,1,88/5x2', 'png', 400);
|
2016-03-09 19:25:53 +03:00
|
|
|
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '0,0,1,1/1x1', 'gif', 400);
|
2016-03-09 19:25:53 +03:00
|
|
|
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, '-180,-80,180,80/0.5x2.6', 'png', 404);
|
2016-03-09 19:25:53 +03:00
|
|
|
});
|
|
|
|
});
|
2016-06-27 09:11:02 +03:00
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('autofit path', function () {
|
|
|
|
describe('valid requests', function () {
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/256x256',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
undefined,
|
|
|
|
/image\/png/,
|
|
|
|
'?path=10,10|20,20',
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('different parameters', function () {
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/20x20',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
2,
|
|
|
|
/image\/png/,
|
|
|
|
'?path=10,10|20,20',
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/200x200',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
3,
|
|
|
|
/image\/png/,
|
|
|
|
'?path=-10,-10|-20,-20',
|
|
|
|
);
|
2016-06-27 09:11:02 +03:00
|
|
|
});
|
2023-09-27 06:53:16 +03:00
|
|
|
|
|
|
|
describe('encoded path', function () {
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/20x20',
|
|
|
|
'png',
|
|
|
|
200,
|
|
|
|
2,
|
|
|
|
/image\/png/,
|
|
|
|
'?path=' + decodeURIComponent('enc:{{biGwvyGoUi@s_A|{@'),
|
|
|
|
);
|
|
|
|
});
|
2016-06-27 09:11:02 +03:00
|
|
|
});
|
|
|
|
|
2022-11-09 06:56:07 +03:00
|
|
|
describe('invalid requests return 4xx', function () {
|
2016-07-27 07:32:53 +03:00
|
|
|
testStatic(prefix, 'auto/256x256', 'png', 400);
|
2022-11-09 06:56:07 +03:00
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/256x256',
|
|
|
|
'png',
|
|
|
|
400,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'?path=invalid',
|
|
|
|
);
|
|
|
|
testStatic(
|
|
|
|
prefix,
|
|
|
|
'auto/2560x2560',
|
|
|
|
'png',
|
|
|
|
400,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
'?path=10,10|20,20',
|
|
|
|
);
|
2016-06-27 09:11:02 +03:00
|
|
|
});
|
|
|
|
});
|
2016-03-09 15:22:06 +03:00
|
|
|
});
|