Merge pull request #1098 from lowdefy/operator-tests

Fix operator tests
This commit is contained in:
Gerrie van Wyk 2022-02-09 20:18:44 +02:00 committed by GitHub
commit 0165c103aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 740 additions and 890 deletions

View File

@ -47,7 +47,7 @@ const input = {
};
test('location calls getFromObject', async () => {
const lowdefyOperators = import('@lowdefy/operators');
const lowdefyOperators = await import('@lowdefy/operators');
location(input);
expect(lowdefyOperators.getFromObject.mock.calls).toEqual([
[

View File

@ -16,6 +16,7 @@
/* eslint-disable max-classes-per-file */
import { WebParser } from '@lowdefy/operators';
import _menu from './menu.js';
const arrayIndices = [1];
@ -24,7 +25,17 @@ const context = {
lowdefy: {
inputs: { id: true },
lowdefyGlobal: { global: true },
menus: [{ menus: true }],
menus: [
{
menuId: 'default',
},
{
menuId: 'm_1',
},
{
menuId: 'm_2',
},
],
urlQuery: { urlQuery: true },
user: { user: true },
},
@ -35,11 +46,15 @@ const context = {
state: { state: true },
};
const operators = {
_menu,
};
console.error = () => {};
test('_menu using string menuId', async () => {
const input = { a: { _menu: 'default' } };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
@ -52,7 +67,7 @@ test('_menu using string menuId', async () => {
test('_menu using index', async () => {
const input = { a: { _menu: 1 } };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
@ -65,7 +80,7 @@ test('_menu using index', async () => {
test('_menu in object', async () => {
const input = { a: { _menu: 'default' } };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
@ -78,7 +93,7 @@ test('_menu in object', async () => {
test('_menu full menus', async () => {
const input = { _menu: true };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual([
@ -97,7 +112,7 @@ test('_menu full menus', async () => {
test('_menu null', async () => {
const input = { _menu: null };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
@ -114,7 +129,7 @@ test('_menu param object value', async () => {
value: 'm_2',
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({ menuId: 'm_2' });
@ -127,7 +142,7 @@ test('_menu param object index', async () => {
index: 2,
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({ menuId: 'm_2' });
@ -140,7 +155,7 @@ test('_menu params object value not string', async () => {
value: 1,
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
@ -157,7 +172,7 @@ test('_menu params object index not number', async () => {
index: 'a',
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
@ -174,7 +189,7 @@ test('_menu param object all', async () => {
all: true,
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual([
@ -198,7 +213,7 @@ test('_menu param object all and value', async () => {
value: 'default',
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual([
@ -221,7 +236,7 @@ test('_menu param object invalid', async () => {
other: true,
},
};
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);

View File

@ -15,6 +15,11 @@
*/
import { WebParser } from '@lowdefy/operators';
import _request from './request.js';
const operators = {
_request,
};
const arrayIndices = [1];
@ -30,7 +35,23 @@ const context = {
},
eventLog: [{ eventLog: true }],
id: 'id',
requests: [{ requests: true }],
requests: {
arr: {
response: [{ a: 'request a1' }, { a: 'request a2' }],
loading: false,
error: [],
},
number: {
response: 500,
loading: false,
error: [],
},
string: {
response: 'request String',
loading: false,
error: [],
},
},
state: { state: true },
};
@ -38,7 +59,7 @@ console.error = () => {};
test('_request by id', async () => {
const input = { a: { _request: 'string' } };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
@ -49,7 +70,7 @@ test('_request by id', async () => {
test('_request true gives null', async () => {
const input = { _request: true };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
@ -62,7 +83,7 @@ test('_request true gives null', async () => {
test('_request return full array', async () => {
const input = { _request: 'arr' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual([{ a: 'request a1' }, { a: 'request a2' }]);
@ -71,7 +92,7 @@ test('_request return full array', async () => {
test('_request return number', async () => {
const input = { _request: 'number' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(500);
@ -80,7 +101,7 @@ test('_request return number', async () => {
test('_request null', async () => {
const input = { _request: null };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
@ -93,7 +114,7 @@ test('_request null', async () => {
test('_request loading true', async () => {
const input = { _request: 'not_loaded' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
@ -102,7 +123,7 @@ test('_request loading true', async () => {
test('_request dot notation', async () => {
const input = { _request: 'arr.0.a' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual('request a1');
@ -111,7 +132,7 @@ test('_request dot notation', async () => {
test('_request dot notation with arrayindices', async () => {
const input = { _request: 'arr.$.a' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual('request a2');
@ -120,7 +141,7 @@ test('_request dot notation with arrayindices', async () => {
test('_request dot notation returns null if ', async () => {
const input = { _request: 'returnsNull.key' };
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);

View File

@ -13,34 +13,69 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { NodeParser, WebParser } from '@lowdefy/operators';
import _and from './and.js';
import and from './and.js';
const operators = {
_and,
};
const location = 'location';
test('_and false', () => {
expect(and({ params: [0, 0], location })).toEqual(false);
expect(and({ params: [0, 1], location })).toEqual(false);
expect(and({ params: [1, 2, 3, 0], location })).toEqual(false);
expect(and({ params: [false, false], location })).toEqual(false);
expect(and({ params: [false, true], location })).toEqual(false);
expect(_and({ params: [0, 0], location })).toEqual(false);
expect(_and({ params: [0, 1], location })).toEqual(false);
expect(_and({ params: [1, 2, 3, 0], location })).toEqual(false);
expect(_and({ params: [false, false], location })).toEqual(false);
expect(_and({ params: [false, true], location })).toEqual(false);
});
test('_and true', () => {
expect(and({ params: [1, 2], location })).toEqual(true);
expect(and({ params: [1, 2, 3], location })).toEqual(true);
expect(and({ params: [true, true], location })).toEqual(true);
expect(_and({ params: [1, 2], location })).toEqual(true);
expect(_and({ params: [1, 2, 3], location })).toEqual(true);
expect(_and({ params: [true, true], location })).toEqual(true);
});
test('_and errors', () => {
expect(() => and({ params: 'hello', location })).toThrow(
expect(() => _and({ params: 'hello', location })).toThrow(
'Operator Error: _and takes an array type. Received: "hello" at location.'
);
expect(() => and({ params: null, location })).toThrow(
expect(() => _and({ params: null, location })).toThrow(
'Operator Error: _and takes an array type. Received: null at location.'
);
expect(() => and({ params: true, location })).toThrow(
expect(() => _and({ params: true, location })).toThrow(
'Operator Error: _and takes an array type. Received: true at location.'
);
expect(() => and({ params: false, location })).toThrow(
expect(() => _and({ params: false, location })).toThrow(
'Operator Error: _and takes an array type. Received: false at location.'
);
});
test('_and evaluated in NodeParser', async () => {
const input = { a: { _and: [true, true] } };
const parser = new NodeParser({ operators, payload: {}, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: true });
});
test('_and evaluated in WebParser', async () => {
const context = {
_internal: {
lowdefy: {
inputs: { id: true },
lowdefyGlobal: { global: true },
menus: [{ menus: true }],
urlQuery: { urlQuery: true },
user: { user: true },
},
},
eventLog: [{ eventLog: true }],
id: 'id',
requests: [{ requests: true }],
state: { state: true },
};
const input = { a: { _and: [true, true] } };
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: true });
});

View File

@ -16,7 +16,7 @@
import date from './date.js';
const location = 'locationId';
const location = 'location';
test('_date now', () => {
const RealDate = Date;
@ -57,19 +57,19 @@ test('_date negative int', () => {
test('_date null', () => {
expect(() => date({ params: null, location })).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _date.__default accepts one of the following types: number, string.
Received: {\\"_date.__default\\":null} at locationId."
Received: {\\"_date.__default\\":null} at location."
`);
});
test('_date invalid operator type', () => {
expect(() => date({ params: {}, location })).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _date.__default accepts one of the following types: number, string.
Received: {\\"_date.__default\\":{}} at locationId."
Received: {\\"_date.__default\\":{}} at location."
`);
});
test('_date invalid string', () => {
expect(() => date({ params: 'abc', location })).toThrowErrorMatchingInlineSnapshot(
`"Operator Error: _date.__default - abc could not resolve as a valid javascript date. Received: {\\"_date.__default\\":\\"abc\\"} at locationId."`
`"Operator Error: _date.__default - abc could not resolve as a valid javascript date. Received: {\\"_date.__default\\":\\"abc\\"} at location."`
);
});

View File

@ -16,6 +16,8 @@
import eq from './eq.js';
const location = 'location';
test('_eq false', () => {
expect(eq({ params: [1, 2], location })).toEqual(false);
expect(eq({ params: [0, 1], location })).toEqual(false);
@ -41,4 +43,7 @@ test('_eq errors', () => {
expect(() => eq({ params: false, location })).toThrow(
'Operator Error: _eq takes an array type as input. Received: false at location.'
);
expect(() => eq({ params: [1, 2, 3], location })).toThrow(
'Operator Error: _eq takes an array of length 2 as input. Received: [1,2,3] at location.'
);
});

View File

@ -15,12 +15,15 @@
*/
import { NodeParser, WebParser } from '@lowdefy/operators';
import _function from './function.js';
import _args from './args.js';
import _payload from '../server/payload.js';
import _state from '../client/state.js';
const operators = {
_test: jest.fn(() => 'test'),
_error: jest.fn(() => {
throw new Error('Test error.');
}),
_args,
_function,
_payload,
_state,
};
const state = {
@ -37,25 +40,34 @@ const payload = {
const location = 'location';
const context = {
lowdefy: { inputs: {} },
_internal: {
lowdefy: {
inputs: { id: true },
lowdefyGlobal: { global: true },
menus: [{ menus: true }],
urlQuery: { urlQuery: true },
user: { user: true },
},
},
eventLog: [{ eventLog: true }],
id: 'id',
requests: [{ requests: true }],
state,
operators,
};
console.error = () => {};
test('NodeParser, _function that gets from payload', async () => {
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const params = { __payload: 'string' };
const fn = _function({ location, params, parser });
expect(fn).toBeInstanceOf(Function);
expect(fn()).toEqual('Some String');
expect(fn()).toEqual('Some String');
});
test('NodeParser, _function gives args as an array', async () => {
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const params = { __args: true };
const fn = _function({ location, params, parser });
@ -64,7 +76,7 @@ test('NodeParser, _function gives args as an array', async () => {
});
test('NodeParser, _function throws on parser errors', async () => {
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const params = { __payload: [] };
const fn = _function({ location, params, parser });
@ -74,7 +86,7 @@ test('NodeParser, _function throws on parser errors', async () => {
});
test('WebParser, _function that gets from state', async () => {
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const params = { __state: 'string' };
const fn = _function({ location, params, parser });
@ -84,7 +96,7 @@ test('WebParser, _function that gets from state', async () => {
});
test('WebParser, _function gives args as an array', async () => {
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const params = { __args: true };
const fn = _function({ location, params, parser });
@ -93,7 +105,7 @@ test('WebParser, _function gives args as an array', async () => {
});
test('WebParser, _function throws on parser errors', async () => {
const parser = new WebParser({ context });
const parser = new WebParser({ context, operators });
await parser.init();
const params = { __state: [] };
const fn = _function({ location, params, parser });

View File

@ -13,122 +13,33 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { NodeParser } from '@lowdefy/operators';
// import { NodeParser } from '@lowdefy/operators';
import _if from './if.js';
const location = 'location';
console.error = () => {};
test('_if', async () => {
const parser = new NodeParser();
await parser.init();
let res = parser.parse({
input: {
_if: {
test: true,
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(1);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({
input: {
_if: {
test: false,
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(2);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({
input: {
_if: {
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _if takes a boolean type for parameter test. Received: {"then":1,"else":2} at locationId.],
]
`);
res = parser.parse({
input: {
_if: {
test: false,
then: 1,
},
},
location: 'locationId',
});
expect(res.output).toBe(undefined);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({
input: {
_if: {
test: true,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(undefined);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({
input: {
_if: {
test: {
a: [1, 3],
},
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _if takes a boolean type for parameter test. Received: {"test":{"a":[1,3]},"then":1,"else":2} at locationId.],
]
`);
res = parser.parse({
input: {
_if: {
test: 'True',
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _if takes a boolean type for parameter test. Received: {"test":"True","then":1,"else":2} at locationId.],
]
`);
res = parser.parse({
input: {
_if: {
test: 1,
then: 1,
else: 2,
},
},
location: 'locationId',
});
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _if takes a boolean type for parameter test. Received: {"test":1,"then":1,"else":2} at locationId.],
]
`);
test('_if then', () => {
expect(_if({ params: { test: true, then: 1, else: 2 }, location })).toEqual(1);
expect(_if({ params: { test: true, else: 2 }, location })).toEqual(undefined);
});
test('_if else', () => {
expect(_if({ params: { test: false, then: 1, else: 2 }, location })).toEqual(2);
expect(_if({ params: { test: false, then: 1 }, location })).toEqual(undefined);
});
test('_if errors', () => {
expect(() => _if({ params: { then: 1, else: 2 }, location })).toThrow(
'Operator Error: _if takes a boolean type for parameter test. Received: {"then":1,"else":2} at location.'
);
expect(() => _if({ params: { test: { a: [1, 3] }, then: 1, else: 2 }, location })).toThrow(
'Operator Error: _if takes a boolean type for parameter test. Received: {"test":{"a":[1,3]},"then":1,"else":2} at location.'
);
expect(() => _if({ params: { test: 'True', then: 1, else: 2 }, location })).toThrow(
'Operator Error: _if takes a boolean type for parameter test. Received: {"test":"True","then":1,"else":2} at location.'
);
expect(() => _if({ params: { test: 1, then: 1, else: 2 }, location })).toThrow(
'Operator Error: _if takes a boolean type for parameter test. Received: {"test":1,"then":1,"else":2} at location.'
);
});

View File

@ -15,7 +15,9 @@
*/
/* eslint-disable max-classes-per-file */
import { NodeParser } from '@lowdefy/operators';
import _log from './log.js';
const location = 'location';
const logger = console.log;
const mockLogger = jest.fn();
@ -27,91 +29,36 @@ afterAll(() => {
console.log = logger;
});
test('_log a string', async () => {
const input = { a: { _log: 'value' } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: 'value',
});
test('_log a string', () => {
expect(_log({ params: 'value', location })).toEqual('value');
expect(mockLogger).toHaveBeenCalledWith('value');
});
test('_log a number', async () => {
const input = { a: { _log: 1 } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: 1,
});
test('_log a number', () => {
expect(_log({ params: 1, location })).toEqual(1);
expect(mockLogger).toHaveBeenCalledWith(1);
});
test('_log a null', async () => {
const input = { a: { _log: null } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: null,
});
test('_log a null', () => {
expect(_log({ params: null, location })).toEqual(null);
expect(mockLogger).toHaveBeenCalledWith(null);
});
// TODO: Confirm if this is expected behaviour??
test('_log a undefined', async () => {
const input = { a: { _log: undefined } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: {},
});
expect(mockLogger).not.toHaveBeenCalled();
test('_log an undefined', () => {
expect(_log({ params: undefined, location })).toEqual(undefined);
expect(mockLogger).toHaveBeenCalledWith(undefined);
});
test('_log a 0', async () => {
const input = { a: { _log: 0 } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: 0,
});
test('_log a 0', () => {
expect(_log({ params: 0, location })).toEqual(0);
expect(mockLogger).toHaveBeenCalledWith(0);
});
test('_log a false', async () => {
const input = { a: { _log: false } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: false,
});
test('_log a false', () => {
expect(_log({ params: false, location })).toEqual(false);
expect(mockLogger).toHaveBeenCalledWith(false);
});
test('_log a object', async () => {
const input = { a: { _log: { b: 1 } } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: { b: 1 },
});
test('_log an object', () => {
expect(_log({ params: { b: 1 }, location })).toEqual({ b: 1 });
expect(mockLogger).toHaveBeenCalledWith({ b: 1 });
});
test('_log a array', async () => {
const input = { a: { _log: [{ b: 1 }] } };
const parser = new NodeParser();
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual({
a: [{ b: 1 }],
});
test('_log an array', () => {
expect(_log({ params: [{ b: 1 }], location })).toEqual([{ b: 1 }]);
expect(mockLogger).toHaveBeenCalledWith([{ b: 1 }]);
});

View File

@ -13,48 +13,20 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { NodeParser } from '@lowdefy/operators';
import _not from './not.js';
const arr0 = [0, 0];
const arr1 = [0, 1];
const arr2 = [1, 2];
const arr3 = [1, 2, 3];
const arr30 = [1, 2, 3, 0];
const string = 'hello';
const Null = null;
const True = true;
const False = false;
const location = 'location';
console.error = () => {};
test('_not', async () => {
const parser = new NodeParser();
await parser.init();
let res = parser.parse({ input: { _not: arr0 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: arr1 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: arr2 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: arr3 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: arr30 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: string }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: Null }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: True }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _not: False }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_not returns true', () => {
expect(_not({ params: 0, location })).toEqual(true);
expect(_not({ params: null, location })).toEqual(true);
expect(_not({ params: false, location })).toEqual(true);
});
test('_not returns false', () => {
expect(_not({ params: 1, location })).toEqual(false);
expect(_not({ params: true, location })).toEqual(false);
expect(_not({ params: [0, 0], location })).toEqual(false);
expect(_not({ params: 'string', location })).toEqual(false);
});

View File

@ -56,7 +56,7 @@ test('_number valid functions', () => {
);
expect(
_number({ methodName: 'toLocaleString', params: [123456.789, 'de-DE'], location: 'locationId' })
).toBe('123,456.789');
).toBe('123.456,789');
expect(
_number({ methodName: 'toPrecision', params: [5.123456, 2], location: 'locationId' })
).toBe('5.1');

View File

@ -15,6 +15,25 @@
*/
import { NodeParser } from '@lowdefy/operators';
import _args from './args.js';
import _function from './function.js';
import _json from './json.js';
import _not from './not.js';
import _payload from '../server/payload.js';
import _operator from './operator.js';
import _state from '../client/state.js';
const operators = {
_args,
_function,
_json,
_not,
_payload,
_operator,
_state,
};
const location = 'location';
const payload = {
string: 'Some String',
@ -26,9 +45,9 @@ console.error = () => {};
test('_operator, _payload', async () => {
const input = { a: { _operator: { name: '_payload', params: 'string' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({
a: 'Some String',
});
@ -37,83 +56,83 @@ test('_operator, _payload', async () => {
test('_operator.name invalid', async () => {
const input = { a: { _operator: { name: '_a' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _operator - Invalid operator name. Received: {"name":"_a"} at locationId.],
[Error: Operator Error: _operator - Invalid operator name. Received: {"name":"_a"} at location.],
]
`);
});
test('_operator.name not allowed to include "experimental"', async () => {
const input = { a: { _operator: { name: '_experimental_op' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: Experimental operators cannot be used with _operator. Received: {"name":"_experimental_op"} at locationId.],
[Error: Operator Error: Experimental operators cannot be used with _operator. Received: {"name":"_experimental_op"} at location.],
]
`);
});
test('_operator.name not a string', async () => {
const input = { a: { _operator: { name: 1 } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _operator.name must be a valid operator name as string. Received: {"name":1} at locationId.],
[Error: Operator Error: _operator.name must be a valid operator name as string. Received: {"name":1} at location.],
]
`);
});
test('_operator with value not a object', async () => {
const input = { a: { _operator: 'a' } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _operator.name must be a valid operator name as string. Received: "a" at locationId.],
[Error: Operator Error: _operator.name must be a valid operator name as string. Received: "a" at location.],
]
`);
});
test('_operator cannot be set to _operator', async () => {
const input = { a: { _operator: { name: '_operator' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: {"name":"_operator"} at locationId.],
[Error: Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: {"name":"_operator"} at location.],
]
`);
});
test('_operator, _not with no params', async () => {
const input = { a: { _operator: { name: '_not' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: true });
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_operator, _json.parse with params', async () => {
const input = { a: { _operator: { name: '_json.parse', params: '[{ "a": "a1"}]' } } };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
const res = parser.parse({ input, location });
expect(res.output).toEqual({
a: [{ a: 'a1' }],
});

View File

@ -13,64 +13,69 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { NodeParser } from '@lowdefy/operators';
import { NodeParser, WebParser } from '@lowdefy/operators';
import _or from './or.js';
const arr0 = [0, 0];
const arr1 = [0, 1];
const arr2 = [1, 2];
const arr3 = [1, 2, 3];
const arr30 = [1, 2, 3, 0];
const string = 'hello';
const Null = null;
const True = true;
const False = false;
const operators = {
_or,
};
console.error = () => {};
const location = 'location';
test('_or', async () => {
const parser = new NodeParser();
await parser.init();
let res = parser.parse({ input: { _or: arr0 }, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _or: arr1 }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _or: arr2 }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _or: arr3 }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _or: arr30 }, location: 'locationId' });
expect(res.output).toEqual(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
res = parser.parse({ input: { _or: string }, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _or takes an array type. Received: "hello" at locationId.],
]
`);
res = parser.parse({ input: { _or: Null }, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _or takes an array type. Received: null at locationId.],
]
`);
res = parser.parse({ input: { _or: True }, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _or takes an array type. Received: true at locationId.],
]
`);
res = parser.parse({ input: { _or: False }, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _or takes an array type. Received: false at locationId.],
]
`);
test('_or false', () => {
expect(_or({ params: [0, 0], location })).toEqual(false);
expect(_or({ params: [false, false], location })).toEqual(false);
});
test('_or true', () => {
expect(_or({ params: [0, 1], location })).toEqual(true);
expect(_or({ params: [1, 2], location })).toEqual(true);
expect(_or({ params: [1, 2, 3], location })).toEqual(true);
expect(_or({ params: [1, 2, 3, 0], location })).toEqual(true);
expect(_or({ params: [true, true], location })).toEqual(true);
expect(_or({ params: [false, true], location })).toEqual(true);
});
test('_or errors', () => {
expect(() => _or({ params: 'hello', location })).toThrow(
'Operator Error: _or takes an array type. Received: "hello" at location.'
);
expect(() => _or({ params: null, location })).toThrow(
'Operator Error: _or takes an array type. Received: null at location.'
);
expect(() => _or({ params: true, location })).toThrow(
'Operator Error: _or takes an array type. Received: true at location.'
);
expect(() => _or({ params: false, location })).toThrow(
'Operator Error: _or takes an array type. Received: false at location.'
);
});
test('_or evaluated in NodeParser', async () => {
const input = { a: { _or: [true, false] } };
const parser = new NodeParser({ operators, payload: {}, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: true });
});
test('_or evaluated in WebParser', async () => {
const context = {
_internal: {
lowdefy: {
inputs: { id: true },
lowdefyGlobal: { global: true },
menus: [{ menus: true }],
urlQuery: { urlQuery: true },
user: { user: true },
},
},
eventLog: [{ eventLog: true }],
id: 'id',
requests: [{ requests: true }],
state: { state: true },
};
const input = { a: { _or: [true, false] } };
const parser = new WebParser({ context, operators });
await parser.init();
const res = parser.parse({ input, location });
expect(res.output).toEqual({ a: true });
});

View File

@ -13,129 +13,77 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import _regex from './regex.js';
import { NodeParser } from '@lowdefy/operators';
const state = {
string: 'Some String',
number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }],
};
const location = 'location';
console.error = () => {};
test('_regex with on, pass', async () => {
const input = { _regex: { pattern: '^a$', on: 'a' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_regex with on, pass', () => {
expect(_regex({ params: { on: 'a', pattern: '^a$' }, location })).toEqual(true);
});
test('_regex with on, fail', async () => {
const input = { _regex: { pattern: '^a$', on: 'b' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_regex with on, fail', () => {
expect(_regex({ params: { on: 'b', pattern: '^a$' }, location })).toEqual(false);
});
// NOTE: key not supported by NodeParser
// test('_regex with key, pass', async () => {
// const input = { _regex: { pattern: '^Some String$', key: 'string' } };
// const parser = new NodeParser({ state });
// await parser.init();
// const res = parser.parse({ input, location: 'locationId' });
// expect(res.output).toBe(true);
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
// test('_regex with key, fail', async () => {
// const input = { _regex: { pattern: '^a$', key: 'string' } };
// const parser = new NodeParser({ state });
// await parser.init();
// const res = parser.parse({ input, location: 'locationId' });
// expect(res.output).toBe(false);
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
test('_regex with null on', async () => {
const input = { _regex: { pattern: '^a$', on: null } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_regex with null on', () => {
expect(_regex({ params: { on: null, pattern: '^a$' }, location })).toEqual(false);
});
test('_regex with nonexistent key', async () => {
const input = { _regex: { pattern: '^a$', key: 'notThere' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_regex with on, pass', () => {
expect(_regex({ params: { on: 'a', pattern: '^a$' }, location })).toEqual(true);
});
test('_regex with nonexistent key', async () => {
const input = { _regex: { pattern: '^a$', key: null } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _regex.key must be a string. Received: {"pattern":"^a$","key":null} at locationId.],
]
`);
test('_regex with key, pass', () => {
expect(
_regex({
params: { key: 'string', pattern: '^Some String$' },
location,
state: { string: 'Some String' },
})
).toEqual(true);
});
test('_regex null', async () => {
const input = { _regex: null };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _regex.pattern must be a string. Received: null at locationId.],
]
`);
test('_regex with key, fail', () => {
expect(
_regex({
params: { key: 'string', pattern: '^a$' },
location,
state: { string: 'Some String' },
})
).toEqual(false);
});
test('_regex with non-string on', async () => {
const input = { _regex: { pattern: '^a$', on: 5 } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _regex.on must be a string. Received: {"pattern":"^a$","on":5} at locationId.],
]
`);
test('_regex with nonexistent', () => {
expect(
_regex({
params: { key: 'notThere', pattern: '^a$' },
location,
state: { string: 'Some String' },
})
).toEqual(false);
});
test('_regex flags', async () => {
const input = { _regex: { pattern: 'a', on: 'A', flags: 'i' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_regex with null key', () => {
expect(() =>
_regex({
params: { key: null, pattern: '^a$' },
location,
state: { string: 'Some String' },
})
).toThrow(
'Operator Error: _regex.key must be a string. Received: {"key":null,"pattern":"^a$"} at location.'
);
});
test('_regex invalid flags', async () => {
const input = { _regex: { pattern: 'a', on: 'a', flags: 1 } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _regex failed to execute RegExp.test. Received: {"pattern":"a","on":"a","flags":1} at locationId.],
]
`);
test('_regex null', () => {
expect(() => _regex({ params: null, location })).toThrow(
'Operator Error: _regex.pattern must be a string. Received: null at location.'
);
});
test('_regex with non-string on', () => {
expect(() => _regex({ params: { pattern: '^a$', on: 5 }, location })).toThrow(
'Operator Error: _regex.on must be a string. Received: {"pattern":"^a$","on":5} at location.'
);
});
test('_regex flags', () => {
expect(_regex({ params: { on: 'A', pattern: '^a$', flags: 'i' }, location })).toEqual(true);
});
test('_regex invalid flags', () => {
expect(() => _regex({ params: { pattern: '^a$', on: 'A', flags: 1 }, location })).toThrow(
'Operator Error: _regex failed to execute RegExp.test. Received: {"pattern":"^a$","on":"A","flags":1} at location.'
);
});

View File

@ -15,7 +15,7 @@
*/
import string from './string.js';
const location = 'locationId';
const location = 'location';
describe('_string.charAt', () => {
const methodName = 'charAt';
@ -51,7 +51,7 @@ describe('_string.charAt', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.charAt must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.charAt\\":[1,2]} at locationId."
Received: {\\"_string.charAt\\":[1,2]} at location."
`);
expect(() =>
string({
@ -61,7 +61,7 @@ describe('_string.charAt', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.charAt must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.charAt\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.charAt\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -71,7 +71,7 @@ describe('_string.charAt', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.charAt accepts one of the following types: array, object.
Received: {\\"_string.charAt\\":null} at locationId."
Received: {\\"_string.charAt\\":null} at location."
`);
});
});
@ -124,7 +124,7 @@ describe('_string.concat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.concat must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.concat\\":[1,2]} at locationId."
Received: {\\"_string.concat\\":[1,2]} at location."
`);
expect(() =>
string({
@ -134,7 +134,7 @@ describe('_string.concat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.concat accepts one of the following types: array.
Received: {\\"_string.concat\\":\\"abc\\"} at locationId."
Received: {\\"_string.concat\\":\\"abc\\"} at location."
`);
expect(() =>
string({
@ -144,7 +144,7 @@ describe('_string.concat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.concat accepts one of the following types: array.
Received: {\\"_string.concat\\":null} at locationId."
Received: {\\"_string.concat\\":null} at location."
`);
});
});
@ -190,7 +190,7 @@ describe('_string.endsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.endsWith must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.endsWith\\":[1,2]} at locationId."
Received: {\\"_string.endsWith\\":[1,2]} at location."
`);
expect(() =>
string({
@ -200,7 +200,7 @@ describe('_string.endsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.endsWith must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.endsWith\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.endsWith\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -210,7 +210,7 @@ describe('_string.endsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.endsWith accepts one of the following types: array, object.
Received: {\\"_string.endsWith\\":null} at locationId."
Received: {\\"_string.endsWith\\":null} at location."
`);
});
});
@ -256,7 +256,7 @@ describe('_string.includes', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.includes must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.includes\\":[1,2]} at locationId."
Received: {\\"_string.includes\\":[1,2]} at location."
`);
expect(() =>
string({
@ -266,7 +266,7 @@ describe('_string.includes', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.includes must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.includes\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.includes\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -276,7 +276,7 @@ describe('_string.includes', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.includes accepts one of the following types: array, object.
Received: {\\"_string.includes\\":null} at locationId."
Received: {\\"_string.includes\\":null} at location."
`);
});
});
@ -329,7 +329,7 @@ describe('_string.indexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.indexOf must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.indexOf\\":[1,2]} at locationId."
Received: {\\"_string.indexOf\\":[1,2]} at location."
`);
expect(() =>
string({
@ -339,7 +339,7 @@ describe('_string.indexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.indexOf must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.indexOf\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.indexOf\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -349,7 +349,7 @@ describe('_string.indexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.indexOf accepts one of the following types: array, object.
Received: {\\"_string.indexOf\\":null} at locationId."
Received: {\\"_string.indexOf\\":null} at location."
`);
});
});
@ -395,7 +395,7 @@ describe('_string.lastIndexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.lastIndexOf must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.lastIndexOf\\":[1,2]} at locationId."
Received: {\\"_string.lastIndexOf\\":[1,2]} at location."
`);
expect(() =>
string({
@ -405,7 +405,7 @@ describe('_string.lastIndexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.lastIndexOf must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.lastIndexOf\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.lastIndexOf\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -415,7 +415,7 @@ describe('_string.lastIndexOf', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.lastIndexOf accepts one of the following types: array, object.
Received: {\\"_string.lastIndexOf\\":null} at locationId."
Received: {\\"_string.lastIndexOf\\":null} at location."
`);
});
});
@ -485,7 +485,7 @@ describe('_string.match', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.match must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.match\\":[1,2]} at locationId."
Received: {\\"_string.match\\":[1,2]} at location."
`);
expect(() =>
string({
@ -495,7 +495,7 @@ describe('_string.match', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.match must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.match\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.match\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -505,7 +505,7 @@ describe('_string.match', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.match accepts one of the following types: array, object.
Received: {\\"_string.match\\":null} at locationId."
Received: {\\"_string.match\\":null} at location."
`);
});
});
@ -536,7 +536,7 @@ describe('_string.normalize', () => {
location,
})
).toThrowErrorMatchingInlineSnapshot(
`"Operator Error: _string.normalize - The normalization form should be one of NFC, NFD, NFKC, NFKD. Received: {\\"_string.normalize\\":[\\"Amélie\\",2]} at locationId."`
`"Operator Error: _string.normalize - The normalization form should be one of NFC, NFD, NFKC, NFKD. Received: {\\"_string.normalize\\":[\\"Amélie\\",2]} at location."`
);
expect(() =>
string({
@ -546,7 +546,7 @@ describe('_string.normalize', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.normalize must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.normalize\\":[1,2]} at locationId."
Received: {\\"_string.normalize\\":[1,2]} at location."
`);
expect(() =>
string({
@ -556,7 +556,7 @@ describe('_string.normalize', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.normalize must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.normalize\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.normalize\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -566,7 +566,7 @@ describe('_string.normalize', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.normalize accepts one of the following types: array, object.
Received: {\\"_string.normalize\\":null} at locationId."
Received: {\\"_string.normalize\\":null} at location."
`);
});
});
@ -605,7 +605,7 @@ describe('_string.padEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padEnd must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.padEnd\\":[1,2]} at locationId."
Received: {\\"_string.padEnd\\":[1,2]} at location."
`);
expect(() =>
string({
@ -615,7 +615,7 @@ describe('_string.padEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padEnd must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.padEnd\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.padEnd\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -625,7 +625,7 @@ describe('_string.padEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padEnd accepts one of the following types: array, object.
Received: {\\"_string.padEnd\\":null} at locationId."
Received: {\\"_string.padEnd\\":null} at location."
`);
});
});
@ -664,7 +664,7 @@ describe('_string.padStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padStart must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.padStart\\":[1,2]} at locationId."
Received: {\\"_string.padStart\\":[1,2]} at location."
`);
expect(() =>
string({
@ -674,7 +674,7 @@ describe('_string.padStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padStart must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.padStart\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.padStart\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -684,7 +684,7 @@ describe('_string.padStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.padStart accepts one of the following types: array, object.
Received: {\\"_string.padStart\\":null} at locationId."
Received: {\\"_string.padStart\\":null} at location."
`);
});
});
@ -716,7 +716,7 @@ describe('_string.repeat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.repeat must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.repeat\\":[1,2]} at locationId."
Received: {\\"_string.repeat\\":[1,2]} at location."
`);
expect(() =>
string({
@ -726,7 +726,7 @@ describe('_string.repeat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.repeat must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.repeat\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.repeat\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -736,7 +736,7 @@ describe('_string.repeat', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.repeat accepts one of the following types: array, object.
Received: {\\"_string.repeat\\":null} at locationId."
Received: {\\"_string.repeat\\":null} at location."
`);
});
});
@ -775,7 +775,7 @@ describe('_string.replace', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.replace must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.replace\\":[1,2]} at locationId."
Received: {\\"_string.replace\\":[1,2]} at location."
`);
expect(() =>
string({
@ -785,7 +785,7 @@ describe('_string.replace', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.replace must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.replace\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.replace\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -795,7 +795,7 @@ describe('_string.replace', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.replace accepts one of the following types: array, object.
Received: {\\"_string.replace\\":null} at locationId."
Received: {\\"_string.replace\\":null} at location."
`);
});
});
@ -841,7 +841,7 @@ describe('_string.search', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.search must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.search\\":[1,2]} at locationId."
Received: {\\"_string.search\\":[1,2]} at location."
`);
expect(() =>
string({
@ -851,7 +851,7 @@ describe('_string.search', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.search must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.search\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.search\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -861,7 +861,7 @@ describe('_string.search', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.search accepts one of the following types: array, object.
Received: {\\"_string.search\\":null} at locationId."
Received: {\\"_string.search\\":null} at location."
`);
});
});
@ -907,7 +907,7 @@ describe('_string.slice', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.slice must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.slice\\":[1,2]} at locationId."
Received: {\\"_string.slice\\":[1,2]} at location."
`);
expect(() =>
string({
@ -917,7 +917,7 @@ describe('_string.slice', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.slice must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.slice\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.slice\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -927,7 +927,7 @@ describe('_string.slice', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.slice accepts one of the following types: array, object.
Received: {\\"_string.slice\\":null} at locationId."
Received: {\\"_string.slice\\":null} at location."
`);
});
});
@ -966,7 +966,7 @@ describe('_string.split', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.split must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.split\\":[1,2]} at locationId."
Received: {\\"_string.split\\":[1,2]} at location."
`);
expect(() =>
string({
@ -976,7 +976,7 @@ describe('_string.split', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.split must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.split\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.split\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -986,7 +986,7 @@ describe('_string.split', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.split accepts one of the following types: array, object.
Received: {\\"_string.split\\":null} at locationId."
Received: {\\"_string.split\\":null} at location."
`);
});
});
@ -1032,7 +1032,7 @@ describe('_string.startsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.startsWith must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.startsWith\\":[1,2]} at locationId."
Received: {\\"_string.startsWith\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1042,7 +1042,7 @@ describe('_string.startsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.startsWith must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.startsWith\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.startsWith\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -1052,7 +1052,7 @@ describe('_string.startsWith', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.startsWith accepts one of the following types: array, object.
Received: {\\"_string.startsWith\\":null} at locationId."
Received: {\\"_string.startsWith\\":null} at location."
`);
});
});
@ -1098,7 +1098,7 @@ describe('_string.substring', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.substring must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.substring\\":[1,2]} at locationId."
Received: {\\"_string.substring\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1108,7 +1108,7 @@ describe('_string.substring', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.substring must be evaluated on an string instance. For named args provide an string instance to the \\"on\\" property, for listed args provide and string instance as the first element in the operator argument array.
Received: {\\"_string.substring\\":{\\"on\\":true}} at locationId."
Received: {\\"_string.substring\\":{\\"on\\":true}} at location."
`);
expect(() =>
string({
@ -1118,7 +1118,7 @@ describe('_string.substring', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.substring accepts one of the following types: array, object.
Received: {\\"_string.substring\\":null} at locationId."
Received: {\\"_string.substring\\":null} at location."
`);
});
});
@ -1143,7 +1143,7 @@ describe('_string.toLowerCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toLowerCase accepts one of the following types: string.
Received: {\\"_string.toLowerCase\\":[1,2]} at locationId."
Received: {\\"_string.toLowerCase\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1153,7 +1153,7 @@ describe('_string.toLowerCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toLowerCase accepts one of the following types: string.
Received: {\\"_string.toLowerCase\\":[\\"abc\\"]} at locationId."
Received: {\\"_string.toLowerCase\\":[\\"abc\\"]} at location."
`);
expect(() =>
string({
@ -1163,7 +1163,7 @@ describe('_string.toLowerCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toLowerCase accepts one of the following types: string.
Received: {\\"_string.toLowerCase\\":{\\"on\\":\\"abc\\"}} at locationId."
Received: {\\"_string.toLowerCase\\":{\\"on\\":\\"abc\\"}} at location."
`);
expect(() =>
string({
@ -1173,7 +1173,7 @@ describe('_string.toLowerCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toLowerCase accepts one of the following types: string.
Received: {\\"_string.toLowerCase\\":null} at locationId."
Received: {\\"_string.toLowerCase\\":null} at location."
`);
});
});
@ -1198,7 +1198,7 @@ describe('_string.toUpperCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toUpperCase accepts one of the following types: string.
Received: {\\"_string.toUpperCase\\":[1,2]} at locationId."
Received: {\\"_string.toUpperCase\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1208,7 +1208,7 @@ describe('_string.toUpperCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toUpperCase accepts one of the following types: string.
Received: {\\"_string.toUpperCase\\":[\\"abc\\"]} at locationId."
Received: {\\"_string.toUpperCase\\":[\\"abc\\"]} at location."
`);
expect(() =>
string({
@ -1218,7 +1218,7 @@ describe('_string.toUpperCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toUpperCase accepts one of the following types: string.
Received: {\\"_string.toUpperCase\\":{\\"on\\":\\"abc\\"}} at locationId."
Received: {\\"_string.toUpperCase\\":{\\"on\\":\\"abc\\"}} at location."
`);
expect(() =>
string({
@ -1228,7 +1228,7 @@ describe('_string.toUpperCase', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.toUpperCase accepts one of the following types: string.
Received: {\\"_string.toUpperCase\\":null} at locationId."
Received: {\\"_string.toUpperCase\\":null} at location."
`);
});
});
@ -1253,7 +1253,7 @@ describe('_string.trim', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trim accepts one of the following types: string.
Received: {\\"_string.trim\\":[1,2]} at locationId."
Received: {\\"_string.trim\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1263,7 +1263,7 @@ describe('_string.trim', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trim accepts one of the following types: string.
Received: {\\"_string.trim\\":[\\"abc\\"]} at locationId."
Received: {\\"_string.trim\\":[\\"abc\\"]} at location."
`);
expect(() =>
string({
@ -1273,7 +1273,7 @@ describe('_string.trim', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trim accepts one of the following types: string.
Received: {\\"_string.trim\\":{\\"on\\":\\"abc\\"}} at locationId."
Received: {\\"_string.trim\\":{\\"on\\":\\"abc\\"}} at location."
`);
expect(() =>
string({
@ -1283,7 +1283,7 @@ describe('_string.trim', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trim accepts one of the following types: string.
Received: {\\"_string.trim\\":null} at locationId."
Received: {\\"_string.trim\\":null} at location."
`);
});
});
@ -1308,7 +1308,7 @@ describe('_string.trimEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimEnd accepts one of the following types: string.
Received: {\\"_string.trimEnd\\":[1,2]} at locationId."
Received: {\\"_string.trimEnd\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1318,7 +1318,7 @@ describe('_string.trimEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimEnd accepts one of the following types: string.
Received: {\\"_string.trimEnd\\":[\\"abc\\"]} at locationId."
Received: {\\"_string.trimEnd\\":[\\"abc\\"]} at location."
`);
expect(() =>
string({
@ -1328,7 +1328,7 @@ describe('_string.trimEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimEnd accepts one of the following types: string.
Received: {\\"_string.trimEnd\\":{\\"on\\":\\"abc\\"}} at locationId."
Received: {\\"_string.trimEnd\\":{\\"on\\":\\"abc\\"}} at location."
`);
expect(() =>
string({
@ -1338,7 +1338,7 @@ describe('_string.trimEnd', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimEnd accepts one of the following types: string.
Received: {\\"_string.trimEnd\\":null} at locationId."
Received: {\\"_string.trimEnd\\":null} at location."
`);
});
});
@ -1363,7 +1363,7 @@ describe('_string.trimStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimStart accepts one of the following types: string.
Received: {\\"_string.trimStart\\":[1,2]} at locationId."
Received: {\\"_string.trimStart\\":[1,2]} at location."
`);
expect(() =>
string({
@ -1373,7 +1373,7 @@ describe('_string.trimStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimStart accepts one of the following types: string.
Received: {\\"_string.trimStart\\":[\\"abc\\"]} at locationId."
Received: {\\"_string.trimStart\\":[\\"abc\\"]} at location."
`);
expect(() =>
string({
@ -1383,7 +1383,7 @@ describe('_string.trimStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimStart accepts one of the following types: string.
Received: {\\"_string.trimStart\\":{\\"on\\":\\"abc\\"}} at locationId."
Received: {\\"_string.trimStart\\":{\\"on\\":\\"abc\\"}} at location."
`);
expect(() =>
string({
@ -1393,7 +1393,7 @@ describe('_string.trimStart', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.trimStart accepts one of the following types: string.
Received: {\\"_string.trimStart\\":null} at locationId."
Received: {\\"_string.trimStart\\":null} at location."
`);
});
});
@ -1418,7 +1418,7 @@ describe('_string.length', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.length accepts one of the following types: string.
Received: {\\"_string.length\\":{\\"on\\":\\"231\\"}} at locationId."
Received: {\\"_string.length\\":{\\"on\\":\\"231\\"}} at location."
`);
expect(() =>
string({
@ -1428,7 +1428,7 @@ describe('_string.length', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.length accepts one of the following types: string.
Received: {\\"_string.length\\":[\\"1\\"]} at locationId."
Received: {\\"_string.length\\":[\\"1\\"]} at location."
`);
expect(() =>
string({
@ -1438,22 +1438,22 @@ describe('_string.length', () => {
})
).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.length accepts one of the following types: string.
Received: {\\"_string.length\\":null} at locationId."
Received: {\\"_string.length\\":null} at location."
`);
});
});
test('_string called with no method or params', () => {
expect(() => string({ location: 'locationId' })).toThrowErrorMatchingInlineSnapshot(`
expect(() => string({ location: 'location' })).toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.undefined is not supported, use one of the following: charAt, concat, endsWith, includes, indexOf, lastIndexOf, match, normalize, padEnd, padStart, repeat, replace, search, slice, split, startsWith, substring, toLowerCase, toUpperCase, trim, trimEnd, trimStart, length.
Received: {\\"_string.undefined\\":undefined} at locationId."
Received: {\\"_string.undefined\\":undefined} at location."
`);
});
test('_string invalid method', () => {
expect(() => string({ params: ['a'], methodName: 'X', location: 'locationId' }))
expect(() => string({ params: ['a'], methodName: 'X', location: 'location' }))
.toThrowErrorMatchingInlineSnapshot(`
"Operator Error: _string.X is not supported, use one of the following: charAt, concat, endsWith, includes, indexOf, lastIndexOf, match, normalize, padEnd, padStart, repeat, replace, search, slice, split, startsWith, substring, toLowerCase, toUpperCase, trim, trimEnd, trimStart, length.
Received: {\\"_string.X\\":[\\"a\\"]} at locationId."
Received: {\\"_string.X\\":[\\"a\\"]} at location."
`);
});

View File

@ -15,6 +15,15 @@
*/
import { NodeParser } from '@lowdefy/operators';
import _type from './type.js';
import _date from './date.js';
const operators = {
_date,
_type,
};
const location = 'location';
const state = {
string: 'Some String',
@ -25,136 +34,79 @@ const state = {
console.error = () => {};
test('_type with on, pass', async () => {
const input = { _type: { type: 'string', on: 'a' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_type with on, pass', () => {
expect(_type({ params: { type: 'string', on: 'a' }, location })).toEqual(true);
});
test('_type with on, fail', () => {
expect(_type({ params: { type: 'number', on: 'a' }, location })).toEqual(false);
});
test('_type with key, pass', () => {
expect(_type({ params: { type: 'string', key: 'string' }, location, state })).toEqual(true);
});
test('_type with key, fail', () => {
expect(_type({ params: { type: 'string', key: 'number' }, location, state })).toEqual(false);
});
test('_type with null on, pass', () => {
expect(_type({ params: { type: 'null', on: null }, location })).toEqual(true);
});
test('_type with null on, fail', () => {
expect(_type({ params: { type: 'boolean', on: null }, location })).toEqual(false);
});
test('_type with nonexistent key', () => {
expect(_type({ params: { type: 'boolean', key: 'notThere' }, location, state })).toEqual(false);
});
test('_type with null key', () => {
expect(_type({ params: { type: 'boolean', key: null }, location, state })).toEqual(false);
});
test('_type null', () => {
expect(() => _type({ params: null, location })).toThrow(
'Operator Error: _type.type must be a string. Received: null at location.'
);
});
test('_type with non-string on', () => {
expect(_type({ params: { type: 'number', on: 5 }, location })).toEqual(true);
});
test('_type with unknown type', () => {
expect(() => _type({ params: { type: 'strings' }, location })).toThrow(
'Operator Error: "strings" is not a valid _type test. Received: {"type":"strings"} at location.'
);
});
test('_type date on string date fail', () => {
expect(_type({ params: { type: 'date', on: '2019-11-28T08:10:09.844Z' }, location })).toEqual(
false
);
});
test('_type date on date object pass', () => {
expect(_type({ params: { type: 'date', on: new Date() }, location })).toEqual(true);
});
test('_type with on, fail', async () => {
const input = { _type: { type: 'number', on: 'b' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
test('_type array', () => {
expect(_type({ params: { type: 'array', key: 'arr' }, location, state })).toEqual(true);
});
test('_type object', () => {
expect(_type({ params: { type: 'object', on: { key: 'value' } }, location, state })).toEqual(
true
);
});
test('_type primitive', () => {
expect(_type({ params: { type: 'primitive', on: 'Primitive string' }, location, state })).toEqual(
true
);
});
test('_type integer', () => {
expect(_type({ params: { type: 'integer', on: 42 }, location, state })).toEqual(true);
});
test('_type undefined', () => {
expect(_type({ params: { type: 'undefined', on: undefined }, location, state })).toEqual(true);
});
test('_type none', () => {
expect(_type({ params: { type: 'none' }, location, state })).toEqual(true);
});
// NOTE: key not supported by NodeParser
// test('_type with key, pass', async () => {
// const input = { _type: { type: 'string', key: 'string' } };
// const parser = new NodeParser({ state });
// await parser.init();
// const res = parser.parse({ input, location: 'locationId' });
// expect(res.output).toBe(true);
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
// test('_type with key, fail', async () => {
// const input = { _type: { type: 'number', key: 'string' } };
// const parser = new NodeParser({ state });
// await parser.init();
// const res = parser.parse({ input, location: 'locationId' });
// expect(res.output).toBe(false);
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
test('_type with null on pass', async () => {
const input = { _type: { type: 'null', on: null } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type with null on fail', async () => {
const input = { _type: { type: 'boolean', on: null } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type with nonexistent key', async () => {
const input = { _type: { type: 'string', key: 'notThere' } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type with nonexistent key', async () => {
const input = { _type: { type: 'string', key: null } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type null', async () => {
const input = { _type: null };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _type.type must be a string. Received: null at locationId.],
]
`);
});
test('_type with non-string on', async () => {
const input = { _type: { type: 'number', on: 5 } };
const parser = new NodeParser({ state });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type with unknown type', async () => {
const input = { _type: 'strings' };
const parser = new NodeParser({ state, arrayIndices: [] });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: "strings" is not a valid _type test. Received: "strings" at locationId.],
]
`);
});
test('_type date with on packed date pass', async () => {
test('_type date with on packed date pass and calls NodeParser', async () => {
const input = { _type: { type: 'date', on: { _date: Date.now() } } };
const parser = new NodeParser({ state, arrayIndices: [] });
const parser = new NodeParser({ operators, payload: {}, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type date on string date fail', async () => {
const input = { _type: { type: 'date', on: '2019-11-28T08:10:09.844Z' } };
const parser = new NodeParser({ state, arrayIndices: [] });
await parser.init();
const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_type date on date object pass', async () => {
const input = { _type: { type: 'date', on: new Date() } };
const parser = new NodeParser({ state, arrayIndices: [] });
await parser.init();
const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
const res = parser.parse({ input, location });
expect(res.output).toEqual(true);
});

View File

@ -14,24 +14,11 @@
limitations under the License.
*/
import { NodeParser, WebParser } from '@lowdefy/operators';
import { NodeParser } from '@lowdefy/operators';
import _nunjucks from './nunjucks.js';
const arrayIndices = [1];
const context = {
_internal: {
lowdefy: {
inputs: { id: true },
lowdefyGlobal: { global: true },
menus: [{ menus: true }],
urlQuery: { urlQuery: true },
user: { user: true },
},
},
eventLog: [{ eventLog: true }],
id: 'id',
requests: [{ requests: true }],
state: { state: true },
const operators = {
_nunjucks,
};
const payload = {
@ -44,7 +31,7 @@ console.error = () => {};
test('_nunjucks string template', async () => {
const input = { _nunjucks: 'String with {{ string }} embedded' };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual('String with Some String embedded');
@ -53,7 +40,7 @@ test('_nunjucks string template', async () => {
test('_nunjucks null', async () => {
const input = { _nunjucks: null };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
@ -64,7 +51,7 @@ test('_nunjucks { template: , on: }', async () => {
const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: { string: 'test' } },
};
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toEqual('String with test embedded');
@ -73,7 +60,7 @@ test('_nunjucks { template: , on: }', async () => {
test('_nunjucks template not a string', async () => {
const input = { _nunjucks: ['String with {{ string }} embedded'] };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
@ -84,7 +71,7 @@ test('_nunjucks params on template not a string', async () => {
const input = {
_nunjucks: { template: ['String with {{ string }} embedded'], on: { string: 'test' } },
};
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);
@ -95,7 +82,7 @@ test('_nunjucks on not a object', async () => {
const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: [{ string: 'test' }] },
};
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe('String with embedded');
@ -106,7 +93,7 @@ test('_nunjucks on null', async () => {
const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: null },
};
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe('String with embedded');
@ -115,7 +102,7 @@ test('_nunjucks on null', async () => {
test('_nunjucks invalid template', async () => {
const input = { _nunjucks: 'String with {{ string embedded' };
const parser = new NodeParser({ payload });
const parser = new NodeParser({ operators, payload, secrets: {}, user: {} });
await parser.init();
const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null);