mirror of
https://github.com/n8n-io/n8n.git
synced 2026-07-28 11:35:03 +02:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { evaluateJmespathQuery, JmespathQueryError } from '../src/jmespath-query';
|
|
|
|
describe('evaluateJmespathQuery', () => {
|
|
it('selects a nested field from an object', () => {
|
|
expect(evaluateJmespathQuery({ a: { b: 42 } }, 'a.b')).toBe(42);
|
|
});
|
|
|
|
it('selects across an array', () => {
|
|
const data = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
expect(evaluateJmespathQuery(data, '[*].id')).toEqual([1, 2, 3]);
|
|
});
|
|
|
|
it('returns null when nothing matches', () => {
|
|
expect(evaluateJmespathQuery({ a: 1 }, 'b.c')).toBeNull();
|
|
});
|
|
|
|
it.each(['__proto__', 'prototype', 'constructor'])(
|
|
'throws JmespathQueryError for unsafe token "%s"',
|
|
(token) => {
|
|
expect(() => evaluateJmespathQuery({}, `foo.${token}`)).toThrow(JmespathQueryError);
|
|
},
|
|
);
|
|
|
|
it('throws JmespathQueryError when the query contains a backslash', () => {
|
|
expect(() => evaluateJmespathQuery({}, 'foo\\bar')).toThrow(JmespathQueryError);
|
|
});
|
|
|
|
it('lets jmespath parser errors propagate unwrapped', () => {
|
|
expect(() => evaluateJmespathQuery({ a: 1 }, '[[[')).toThrow();
|
|
expect(() => evaluateJmespathQuery({ a: 1 }, '[[[')).not.toThrow(JmespathQueryError);
|
|
});
|
|
});
|