2017-11-26 20:45:40 +00:00
|
|
|
const tag = require('..').templateTags[0];
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function assertTemplate(args, expected) {
|
|
|
|
return async function() {
|
2017-11-26 20:45:40 +00:00
|
|
|
const result = await tag.run(null, ...args);
|
|
|
|
expect(result).toBe(expected);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function assertTemplateFails(args, expected) {
|
|
|
|
return async function() {
|
2017-11-26 20:45:40 +00:00
|
|
|
try {
|
|
|
|
await tag.run(null, ...args);
|
|
|
|
fail(`Render should have thrown ${expected}`);
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.message).toContain(expected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Base64EncodeExtension', () => {
|
2019-03-13 17:07:52 +00:00
|
|
|
it('encodes nothing', assertTemplate(['encode', 'normal', ''], ''));
|
|
|
|
it('encodes something', assertTemplate(['encode', 'normal', 'my string'], 'bXkgc3RyaW5n'));
|
|
|
|
it('urlencodes nothing', assertTemplate(['encode', 'url', ''], ''));
|
|
|
|
it('urlencodes something', assertTemplate(['encode', 'url', 'hello world'], 'aGVsbG8gd29ybGQ'));
|
|
|
|
it('decodes nothing', assertTemplate(['decode', 'normal', ''], ''));
|
|
|
|
it('decodes something', assertTemplate(['decode', 'normal', 'bXkgc3RyaW5n'], 'my string'));
|
|
|
|
it('urldecodes nothing', assertTemplate(['decode', 'url', ''], ''));
|
|
|
|
it('urldecodes something', assertTemplate(['decode', 'url', 'aGVsbG8gd29ybGQ'], 'hello world'));
|
2018-06-25 17:42:50 +00:00
|
|
|
it(
|
2019-03-13 17:07:52 +00:00
|
|
|
'fails on invalid action',
|
|
|
|
assertTemplateFails(
|
|
|
|
['foo', 'normal', ''],
|
|
|
|
'Unsupported operation "foo". Must be encode or decode.',
|
|
|
|
),
|
2018-06-25 17:42:50 +00:00
|
|
|
);
|
2017-11-26 20:45:40 +00:00
|
|
|
});
|