insomnia/plugins/insomnia-plugin-base64/__tests__/index.test.js
2018-12-12 12:36:11 -05:00

31 lines
919 B
JavaScript

const tag = require('..').templateTags[0];
function assertTemplate(args, expected) {
return async function() {
const result = await tag.run(null, ...args);
expect(result).toBe(expected);
};
}
function assertTemplateFails(args, expected) {
return async function() {
try {
await tag.run(null, ...args);
fail(`Render should have thrown ${expected}`);
} catch (err) {
expect(err.message).toContain(expected);
}
};
}
describe('Base64EncodeExtension', () => {
it('encodes nothing', assertTemplate(['encode'], ''));
it('encodes something', assertTemplate(['encode', 'my string'], 'bXkgc3RyaW5n'));
it('decodes nothing', assertTemplate(['decode'], ''));
it('decodes something', assertTemplate(['decode', 'bXkgc3RyaW5n'], 'my string'));
it(
'fails on invalid op',
assertTemplateFails(['foo'], 'Unsupported operation "foo". Must be encode or decode.'),
);
});