@unito/integration-cli
Version:
Integration CLI
55 lines (54 loc) • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
const template_1 = require("../../src/resources/template");
describe('template', function () {
const context = {
var: 'value',
'some.value': 'some',
some_value: 'value',
'Some%20Thing': 'Some%20Thing',
foo: 'bar',
hello: 'Hello World!',
bool: 'false',
toString: 'string',
chars: 'šö䟜ñꀣ¥‡ÑÒÓÔÕÖרÙÚàáâãäåæçÿü',
path: '/foo/bar',
surrogatepairs: '\uD834\uDF06',
};
it('empty string', function () {
strict_1.default.equal((0, template_1.expandTemplate)('', context, { urlEncodeVariables: true }), '');
});
describe('url encode', function () {
it('enabled', function () {
strict_1.default.equal((0, template_1.expandTemplate)('Hello World!/{+foo}{+path}/{+hello}', context, { urlEncodeVariables: true }), 'Hello World!/bar/foo/bar/Hello%20World!');
});
it('disabled', function () {
strict_1.default.equal((0, template_1.expandTemplate)('Hello World!/{+foo}{+path}/{+hello}', context, { urlEncodeVariables: false }), 'Hello World!/bar/foo/bar/Hello World!');
});
it('expand non-ASCII strings', function () {
strict_1.default.equal((0, template_1.expandTemplate)('{+chars}', context, { urlEncodeVariables: true }), '%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF%C3%BC');
});
it('reserved expansion of basic strings', function () {
strict_1.default.equal((0, template_1.expandTemplate)('{+var}', context, { urlEncodeVariables: true }), 'value');
strict_1.default.equal((0, template_1.expandTemplate)('{+hello}', context, { urlEncodeVariables: true }), 'Hello%20World!');
strict_1.default.equal((0, template_1.expandTemplate)('{+Some%20Thing}', context, { urlEncodeVariables: true }), 'Some%20Thing');
});
it('preserves paths', function () {
strict_1.default.equal((0, template_1.expandTemplate)('{+path}/here', context, { urlEncodeVariables: true }), '/foo/bar/here');
strict_1.default.equal((0, template_1.expandTemplate)('here?ref={+path}', context, { urlEncodeVariables: true }), 'here?ref=/foo/bar');
});
});
describe('base64', function () {
it('without variables', function () {
strict_1.default.equal((0, template_1.expandTemplate)('{!base64(foo bar)}', context, { urlEncodeVariables: true }), Buffer.from('foo bar').toString('base64'));
strict_1.default.equal((0, template_1.expandTemplate)('wow{!base64(foo bar)}socool!', context, { urlEncodeVariables: true }), `wow${Buffer.from('foo bar').toString('base64')}socool!`);
});
it('with variables', function () {
strict_1.default.equal((0, template_1.expandTemplate)('{+hello}{!base64({+hello}:{+path})}', context, { urlEncodeVariables: true }), `Hello%20World!${Buffer.from('Hello World!:/foo/bar').toString('base64')}`);
strict_1.default.equal((0, template_1.expandTemplate)('{!base64({+hello}:{+path})}', context, { urlEncodeVariables: false }), Buffer.from('Hello World!:/foo/bar').toString('base64'));
strict_1.default.equal((0, template_1.expandTemplate)('wow{!base64({+hello}:{+path})}socool!', context, { urlEncodeVariables: false }), `wow${Buffer.from('Hello World!:/foo/bar').toString('base64')}socool!`);
});
});
});