Merge pull request #48 from lowdefy/cleanup-engine

Clean up engine and operators
This commit is contained in:
Gervwyk 2020-10-15 11:22:16 +02:00 committed by GitHub
commit 5492a287b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
87 changed files with 148 additions and 1673 deletions

View File

@ -22,39 +22,9 @@ import type from '@lowdefy/type';
import get from '@lowdefy/get'; import get from '@lowdefy/get';
import set from '@lowdefy/set'; import set from '@lowdefy/set';
import serializer from '@lowdefy/serializer'; import serializer from '@lowdefy/serializer';
import gql from 'graphql-tag';
import makeContextId from './makeContextId'; import makeContextId from './makeContextId';
const UPDATE_USER_PROFILE = gql`
mutation updateUserProfile($updateUserProfileInput: UpdateUserProfileInput!) {
updateUserProfile(updateUserProfileInput: $updateUserProfileInput) {
success
}
}
`;
const REFRESH_USER = gql`
query refreshUser {
user {
id
email
phone_number
given_name
family_name
name
nickname
picture
preferred_username
attributes
groupIds
roles
adminGroupIds
allPageIds
}
}
`;
class Actions { class Actions {
constructor(context) { constructor(context) {
this.context = context; this.context = context;
@ -62,35 +32,25 @@ class Actions {
this.build = this.build.bind(this); this.build = this.build.bind(this);
this.callMethod = this.callMethod.bind(this); this.callMethod = this.callMethod.bind(this);
this.fetch = this.fetch.bind(this); this.fetch = this.fetch.bind(this);
this.getCliToken = this.getCliToken.bind(this);
this.link = this.link.bind(this); this.link = this.link.bind(this);
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.message = this.message.bind(this); this.message = this.message.bind(this);
this.mutate = this.mutate.bind(this); this.mutate = this.mutate.bind(this);
this.notification = this.notification.bind(this);
this.reset = this.reset.bind(this); this.reset = this.reset.bind(this);
this.scrollTo = this.scrollTo.bind(this); this.scrollTo = this.scrollTo.bind(this);
this.setGlobal = this.setGlobal.bind(this); this.setGlobal = this.setGlobal.bind(this);
this.setState = this.setState.bind(this); this.setState = this.setState.bind(this);
this.updateProfile = this.updateProfile.bind(this);
this.validate = this.validate.bind(this); this.validate = this.validate.bind(this);
this.actions = { this.actions = {
CallMethod: this.callMethod, CallMethod: this.callMethod,
Fetch: this.fetch, Fetch: this.fetch,
GetCliToken: this.getCliToken,
Link: this.link, Link: this.link,
Login: this.login,
Logout: this.logout,
Message: this.message, Message: this.message,
Mutate: this.mutate, Mutate: this.mutate,
Notification: this.notification,
Reset: this.reset, Reset: this.reset,
ScrollTo: this.scrollTo, ScrollTo: this.scrollTo,
SetGlobal: this.setGlobal, SetGlobal: this.setGlobal,
SetState: this.setState, SetState: this.setState,
UpdateProfile: this.updateProfile,
Validate: this.validate, Validate: this.validate,
}; };
} }
@ -178,23 +138,6 @@ class Actions {
} }
} }
async getCliToken(_, successMessage, errorMessage) {
try {
const response = await this.context.appGraphql.getCliToken();
console.log('CLI TOKEN:');
console.log(response);
try {
navigator.clipboard.writeText(response);
} catch (error) {
console.error(error);
}
return { successMessage, response };
} catch (error) {
// log e
return Promise.reject({ errorMessage: errorMessage || 'Failed to get cli token.', error });
}
}
fetch(params, successMessage, errorMessage) { fetch(params, successMessage, errorMessage) {
if (type.isNone(params)) { if (type.isNone(params)) {
return this.context.Requests.callRequests() return this.context.Requests.callRequests()
@ -250,37 +193,6 @@ class Actions {
}); });
} }
notification(params = {}, successMessage, errorMessage, args, arrayIndices, blockId) {
try {
const { output: parsed, errors: parseErrors } = this.context.parser.parse({
args,
arrayIndices,
input: params,
location: blockId,
});
if (parseErrors.length > 0) {
return Promise.reject({
errorMessage: errorMessage || `Notification failed.`,
error: parseErrors,
});
}
this.context.displayNotification[parsed.status || 'success']({
bottom: parsed.bottom,
description: parsed.description || '',
duration: type.isNone(parsed.duration) ? 5 : parsed.duration,
message: parsed.message || 'Success',
placement: parsed.placement,
top: parsed.top,
});
return Promise.resolve({ successMessage });
} catch (error) {
return Promise.reject({
errorMessage: errorMessage || `Notification failed.`,
error,
});
}
}
message(params = {}, successMessage, errorMessage, args, arrayIndices, blockId) { message(params = {}, successMessage, errorMessage, args, arrayIndices, blockId) {
try { try {
const { output: parsed, errors: parseErrors } = this.context.parser.parse({ const { output: parsed, errors: parseErrors } = this.context.parser.parse({
@ -420,7 +332,6 @@ class Actions {
// set input for page before changing // set input for page before changing
if (!type.isNone(parsedParams.input)) { if (!type.isNone(parsedParams.input)) {
const nextContextId = makeContextId({ const nextContextId = makeContextId({
branch: this.context.branch,
pageId, pageId,
search: parsedParams.urlQuery, search: parsedParams.urlQuery,
blockId: pageId, blockId: pageId,
@ -455,97 +366,6 @@ class Actions {
return Promise.resolve({ successMessage }); return Promise.resolve({ successMessage });
} }
logout(_, successMessage, errorMessage) {
try {
this.context.localStore.setItem(`token:${this.context.branch}`, '');
if (this.context.openidLogoutUrl) {
this.context.window.location.href = this.context.openidLogoutUrl;
} else {
this.context.window.location.href = this.context.window.location.origin;
}
} catch (error) {
return Promise.reject({ errorMessage: errorMessage || 'Failed to logout.', error });
}
return Promise.resolve({ successMessage });
}
login(_, successMessage, errorMessage) {
try {
this.context.routeHistory.push(`/login`);
} catch (error) {
return Promise.reject({ errorMessage: errorMessage || 'Failed login redirect.', error });
}
return Promise.resolve({ successMessage });
}
updateProfile(userUpdate, successMessage, errorMessage, args, arrayIndices, blockId) {
try {
const { output: parsedUserUpdate, errors: userParseErrors } = this.context.parser.parse({
args,
arrayIndices,
input: userUpdate,
location: blockId,
});
if (userParseErrors.length > 0) {
return Promise.reject({
errorMessage: errorMessage || 'Failed to update profile due to parser error.',
error: userParseErrors,
});
}
const {
id,
phone_number,
name,
family_name,
given_name,
nickname,
picture,
preferred_username,
attributes,
} = parsedUserUpdate;
return this.context.client
.mutate({
mutation: UPDATE_USER_PROFILE,
variables: {
updateUserProfileInput: {
userId: id,
phone_number,
name,
family_name,
given_name,
nickname,
picture,
preferred_username,
attributes,
},
},
// refetch user query
// TODO: Apollo cache does not update if user is returned by mutation
// Maybe Apollo client V3 will fix this?
refetchQueries: [{ query: REFRESH_USER }],
awaitRefetchQueries: true,
})
.then(() => {
return { successMessage };
})
.catch((error) => {
if (errorMessage) {
return Promise.reject({ errorMessage, error });
}
try {
const { displayTitle, displayMessage } = error.graphQLErrors[0].extensions;
return Promise.reject({ errorMessage: `${displayTitle}: ${displayMessage}`, error });
} catch (e) {
// Not a graphQLError, displayTitle, displayMessage do not exist
}
return Promise.reject({ errorMessage: error.message, error });
});
} catch (error) {
// log e
return Promise.reject({ errorMessage: errorMessage || 'Failed to update profile.', error });
}
}
validate(blockId, successMessage, errorMessage) { validate(blockId, successMessage, errorMessage) {
try { try {
this.context.showValidationErrors = true; this.context.showValidationErrors = true;

View File

@ -1,55 +0,0 @@
/*
Copyright 2020 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import gql from 'graphql-tag';
const GET_CLI_TOKEN = gql`
query getCliToken {
cliToken
}
`;
class AppGraphql {
constructor({ branch, client }) {
this.branch = branch;
this.client = client;
}
callMutation(mutation, variables) {
return this.client.mutate({
mutation,
variables,
});
}
callQuery(query, variables) {
return this.client.query({
query,
variables,
});
}
async getCliToken() {
try {
const res = await this.callQuery(GET_CLI_TOKEN, {});
return res.data.cliToken;
} catch (error) {
return null;
}
}
}
export default AppGraphql;

View File

@ -613,7 +613,7 @@ class Blocks {
} }
generateCacheId(blockIdPattern) { generateCacheId(blockIdPattern) {
return `${this.context.branch}:${this.context.pageId}:${blockIdPattern}:${Math.random() return `${this.context.pageId}:${blockIdPattern}:${Math.random()
.toString(36) .toString(36)
.replace(/[^a-z]+/g, '') .replace(/[^a-z]+/g, '')
.substr(0, 5)}`; .substr(0, 5)}`;

View File

@ -72,7 +72,6 @@ class Mutations {
mutationId, mutationId,
args: serializer.serialize(args) || {}, args: serializer.serialize(args) || {},
blockId: this.context.blockId, blockId: this.context.blockId,
branch: this.context.branch,
input: serializer.serialize(this.context.input), input: serializer.serialize(this.context.input),
lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal), lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal),
pageId: this.context.pageId, pageId: this.context.pageId,

View File

@ -90,7 +90,6 @@ class Requests {
requestInput: { requestInput: {
requestId, requestId,
blockId: this.context.blockId, blockId: this.context.blockId,
branch: this.context.branch,
input: serializer.serialize(this.context.input), input: serializer.serialize(this.context.input),
lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal), lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal),
pageId: this.context.pageId, pageId: this.context.pageId,

View File

@ -14,7 +14,6 @@
limitations under the License. limitations under the License.
*/ */
import { getFieldVales } from '@lowdefy/helpers';
import { WebParser } from '@lowdefy/operators'; import { WebParser } from '@lowdefy/operators';
import Actions from './Actions'; import Actions from './Actions';
@ -29,7 +28,6 @@ const blockData = ({
areas, areas,
blockId, blockId,
blocks, blocks,
branch,
defaultValue, defaultValue,
field, field,
id, id,
@ -49,7 +47,6 @@ const blockData = ({
areas, areas,
blockId, blockId,
blocks, blocks,
branch,
defaultValue, defaultValue,
field, field,
id, id,
@ -73,7 +70,6 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti
rootContext.contexts[contextId].lowdefyGlobal = rootContext.lowdefyGlobal; rootContext.contexts[contextId].lowdefyGlobal = rootContext.lowdefyGlobal;
rootContext.contexts[contextId].menus = rootContext.menus; rootContext.contexts[contextId].menus = rootContext.menus;
rootContext.contexts[contextId].config = rootContext.config; rootContext.contexts[contextId].config = rootContext.config;
rootContext.contexts[contextId].user = rootContext.user;
rootContext.contexts[contextId].update(); rootContext.contexts[contextId].update();
return rootContext.contexts[contextId]; return rootContext.contexts[contextId];
} }
@ -85,22 +81,16 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti
id: contextId, id: contextId,
pageId, pageId,
actionLog: [], actionLog: [],
appGraphql: rootContext.appGraphql,
blockId: block.blockId, blockId: block.blockId,
branch: rootContext.branch,
client: rootContext.client, client: rootContext.client,
Components: rootContext.Components,
config: rootContext.config, config: rootContext.config,
displayMessage: message, displayMessage: message,
displayNotification: notification,
document: rootContext.document, document: rootContext.document,
input: rootContext.input[contextId] || {}, input: rootContext.input[contextId] || {},
allInputs: rootContext.input, allInputs: rootContext.input,
localStore: rootContext.localStore,
lowdefyGlobal: rootContext.lowdefyGlobal, lowdefyGlobal: rootContext.lowdefyGlobal,
menus: rootContext.menus, menus: rootContext.menus,
mutations: {}, mutations: {},
openidLogoutUrl: rootContext.openidLogoutUrl,
requests: {}, requests: {},
rootBlock: blockData(block), // filter block to prevent circular loop structure rootBlock: blockData(block), // filter block to prevent circular loop structure
routeHistory: rootContext.routeHistory, routeHistory: rootContext.routeHistory,
@ -108,7 +98,6 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti
state: {}, state: {},
update: () => {}, // Initialize update since Requests/Mutations might call it during context creation update: () => {}, // Initialize update since Requests/Mutations might call it during context creation
urlQuery: rootContext.urlQuery, urlQuery: rootContext.urlQuery,
user: rootContext.user,
window: rootContext.window, window: rootContext.window,
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -15,7 +15,6 @@
*/ */
import Actions from './Actions'; import Actions from './Actions';
import AppGraphql from './AppGraphql';
import BlockActions from './BlockActions'; import BlockActions from './BlockActions';
import Blocks from './Blocks'; import Blocks from './Blocks';
import makeContextId from './makeContextId'; import makeContextId from './makeContextId';
@ -25,6 +24,6 @@ import State from './State';
import getContext from './getContext'; import getContext from './getContext';
export { Actions, AppGraphql, BlockActions, Blocks, makeContextId, Mutations, Requests, State }; export { Actions, BlockActions, Blocks, makeContextId, Mutations, Requests, State };
export default getContext; export default getContext;

View File

@ -17,17 +17,14 @@
import type from '@lowdefy/type'; import type from '@lowdefy/type';
import serializer from '@lowdefy/serializer'; import serializer from '@lowdefy/serializer';
function makeContextId({ blockId, branch, pageId, urlQuery = {} }) { function makeContextId({ blockId, pageId, urlQuery = {} }) {
if (!type.isString(blockId)) { if (!type.isString(blockId)) {
throw new Error(`Expected string for parameter blockId, received ${blockId}`); throw new Error(`Expected string for parameter blockId, received ${blockId}`);
} }
if (!type.isString(branch)) {
throw new Error(`Expected string for parameter branch, received ${branch}`);
}
if (!type.isString(pageId)) { if (!type.isString(pageId)) {
throw new Error(`Expected string for parameter pageId, received ${pageId}`); throw new Error(`Expected string for parameter pageId, received ${pageId}`);
} }
return `${branch}:${pageId}:${blockId}:${serializer.serializeToString(urlQuery)}`; return `${pageId}:${blockId}:${serializer.serializeToString(urlQuery)}`;
} }
export default makeContextId; export default makeContextId;

View File

@ -1,6 +1,5 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
@ -15,7 +14,6 @@ const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const rootContext = { const rootContext = {
branch,
client, client,
message, message,
openidLogoutUrl, openidLogoutUrl,

View File

@ -44,13 +44,11 @@ const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn(); const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,

View File

@ -19,13 +19,11 @@ const window = {
scrollTo: mockWindowScrollTo, scrollTo: mockWindowScrollTo,
}; };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,
@ -300,7 +298,7 @@ test('Link with pageId and input', async () => {
const { button } = context.RootBlocks.map; const { button } = context.RootBlocks.map;
button.callAction({ action: 'onClick' }); button.callAction({ action: 'onClick' });
expect(context.routeHistory).toEqual(['/page1']); expect(context.routeHistory).toEqual(['/page1']);
expect(context.allInputs['branch:page1:page1:{}']).toEqual({ data: 1 }); expect(context.allInputs['page1:page1:{}']).toEqual({ data: 1 });
}); });
test('Link with pageId and input and newWindow', async () => { test('Link with pageId and input and newWindow', async () => {
@ -341,5 +339,5 @@ test('Link with pageId and input and newWindow', async () => {
const { button } = context.RootBlocks.map; const { button } = context.RootBlocks.map;
button.callAction({ action: 'onClick' }); button.callAction({ action: 'onClick' });
expect(context.window.open.mock.calls).toEqual([['http://lowdefy.com/page1', '_blank']]); expect(context.window.open.mock.calls).toEqual([['http://lowdefy.com/page1', '_blank']]);
expect(context.allInputs['branch:page1:page1:{}']).toEqual({ data: 1 }); expect(context.allInputs['page1:page1:{}']).toEqual({ data: 1 });
}); });

View File

@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn(); const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,

View File

@ -93,13 +93,11 @@ const window = {
scrollTo: mockWindowScrollTo, scrollTo: mockWindowScrollTo,
}; };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,

View File

@ -1,189 +0,0 @@
import testContext from '../testContext';
const client = {
writeFragment: jest.fn(),
};
// Mock message
const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
// Mock Notification
const mockNotificationSuccess = jest.fn();
const mockNotificationError = jest.fn();
const notification = {
loading: () => jest.fn(),
error: mockNotificationError,
success: mockNotificationSuccess,
};
const branch = 'master';
const openidLogoutUrl = 'logout';
const pageId = 'one';
const user = { firstName: 'ABC' };
const rootContext = {
branch,
client,
// appGraphql,
message,
notification,
openidLogoutUrl,
user,
};
test('Notification with message', async () => {
const rootBlock = {
blockId: 'root',
meta: {
category: 'context',
},
areas: {
content: {
blocks: [
{
blockId: 'button',
type: 'Button',
meta: {
category: 'display',
valueType: 'string',
},
actions: {
onClick: [
{
id: 'a',
type: 'Notification',
params: { message: 'test' },
},
],
},
},
],
},
},
};
const context = testContext({
rootContext,
rootBlock,
pageId,
});
const { button } = context.RootBlocks.map;
button.callAction({ action: 'onClick' });
expect(mockNotificationError.mock.calls).toEqual([]);
expect(mockNotificationSuccess.mock.calls).toEqual([
[
{
bottom: undefined,
description: '',
duration: 5,
message: 'test',
placement: undefined,
top: undefined,
},
],
]);
});
test('Notification with status error and message', async () => {
const rootBlock = {
blockId: 'root',
meta: {
category: 'context',
},
areas: {
content: {
blocks: [
{
blockId: 'button',
type: 'Button',
meta: {
category: 'display',
valueType: 'string',
},
actions: {
onClick: [
{
id: 'a',
type: 'Notification',
params: { message: 'err', status: 'error' },
},
],
},
},
],
},
},
};
const context = testContext({
rootContext,
rootBlock,
pageId,
});
const { button } = context.RootBlocks.map;
button.callAction({ action: 'onClick' });
expect(mockNotificationSuccess.mock.calls).toEqual([]);
expect(mockNotificationError.mock.calls).toEqual([
[
{
bottom: undefined,
description: '',
duration: 5,
message: 'err',
placement: undefined,
top: undefined,
},
],
]);
});
test('Notification with no params', async () => {
const rootBlock = {
blockId: 'root',
meta: {
category: 'context',
},
areas: {
content: {
blocks: [
{
blockId: 'button',
type: 'Button',
meta: {
category: 'display',
valueType: 'string',
},
actions: {
onClick: [
{
id: 'a',
type: 'Notification',
},
],
},
},
],
},
},
};
const context = testContext({
rootContext,
rootBlock,
pageId,
});
const { button } = context.RootBlocks.map;
button.callAction({ action: 'onClick' });
expect(mockNotificationError.mock.calls).toEqual([]);
expect(mockNotificationSuccess.mock.calls).toEqual([
[
{
bottom: undefined,
description: '',
duration: 5,
message: 'Success',
placement: undefined,
top: undefined,
},
],
]);
});

View File

@ -44,13 +44,11 @@ const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn(); const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
message, message,
document, document,

View File

@ -29,13 +29,11 @@ const window = {
scrollTo: mockWindowScrollTo, scrollTo: mockWindowScrollTo,
}; };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,

View File

@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn(); const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
// appGraphql, // appGraphql,
message, message,

View File

@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn();
const mockMessageError = jest.fn(); const mockMessageError = jest.fn();
const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess };
const branch = 'master';
const openidLogoutUrl = 'logout'; const openidLogoutUrl = 'logout';
const pageId = 'one'; const pageId = 'one';
const user = { firstName: 'ABC' }; const user = { firstName: 'ABC' };
const rootContext = { const rootContext = {
branch,
client, client,
message, message,
openidLogoutUrl, openidLogoutUrl,

View File

@ -7,12 +7,10 @@ import State from '../../src/State';
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };
@ -53,7 +51,6 @@ test('set block to init', () => {
// can't use testContext // can't use testContext
test('Blocks to init with no blocks passed', () => { test('Blocks to init with no blocks passed', () => {
const context = { const context = {
branch,
client, client,
pageId, pageId,
state: { a: 'a' }, state: { a: 'a' },
@ -73,7 +70,6 @@ test('Blocks to init with no blocks passed', () => {
// can't use testContext // can't use testContext
test('Blocks to init with arrayIndices not an array', () => { test('Blocks to init with arrayIndices not an array', () => {
const context = { const context = {
branch,
client, client,
pageId, pageId,
state: { textInput: 'a' }, state: { textInput: 'a' },
@ -116,7 +112,6 @@ test('Blocks to init with arrayIndices not an array', () => {
test('Blocks to init with undefined arrayIndices', () => { test('Blocks to init with undefined arrayIndices', () => {
const context = { const context = {
branch,
client, client,
pageId, pageId,
state: { textInput: 'a' }, state: { textInput: 'a' },

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -2,12 +2,10 @@
import testContext from '../testContext'; import testContext from '../testContext';
const NUM_TIMES = 10; const NUM_TIMES = 10;
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,12 +1,10 @@
/* eslint-disable dot-notation */ /* eslint-disable dot-notation */
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,12 +1,10 @@
/* eslint-disable dot-notation */ /* eslint-disable dot-notation */
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -1,11 +1,9 @@
import testContext from '../testContext'; import testContext from '../testContext';
const branch = 'master';
const pageId = 'one'; const pageId = 'one';
const client = { writeFragment: jest.fn() }; const client = { writeFragment: jest.fn() };
const rootContext = { const rootContext = {
branch,
client, client,
}; };

View File

@ -2,7 +2,6 @@
import testContext from './testContext'; import testContext from './testContext';
const pageId = 'one'; const pageId = 'one';
const branch = 'master';
const mockLoadingCallback = jest.fn(); const mockLoadingCallback = jest.fn();
const mockLoading = jest.fn(() => mockLoadingCallback); const mockLoading = jest.fn(() => mockLoadingCallback);
@ -35,7 +34,6 @@ const mockDate = jest.fn(() => ({ date: 0 }));
mockDate.now = jest.fn(() => 0); mockDate.now = jest.fn(() => 0);
const rootContext = { const rootContext = {
branch,
client, client,
message, message,
}; };

View File

@ -38,7 +38,6 @@ const rootBlock = {
}; };
const blockId = 'one'; const blockId = 'one';
const branch = 'master';
const input = {}; const input = {};
const lowdefyGlobal = {}; const lowdefyGlobal = {};
const pageId = 'one'; const pageId = 'one';
@ -53,7 +52,6 @@ beforeEach(() => {
test('callMutation', async () => { test('callMutation', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -78,7 +76,6 @@ test('callMutation', async () => {
test('callMutation error', async () => { test('callMutation error', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -111,7 +108,6 @@ test('callMutation error', async () => {
test('callMutation that is not on root block', async () => { test('callMutation that is not on root block', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -140,7 +136,6 @@ test('callMutation that is not on root block', async () => {
test('callMutation on root block with no mutations', async () => { test('callMutation on root block with no mutations', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -170,7 +165,6 @@ test('update function should be called', async () => {
const updateFunction = jest.fn(); const updateFunction = jest.fn();
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,

View File

@ -50,7 +50,6 @@ const rootBlock = {
}; };
const blockId = 'one'; const blockId = 'one';
const branch = 'master';
const input = {}; const input = {};
const lowdefyGlobal = {}; const lowdefyGlobal = {};
const pageId = 'one'; const pageId = 'one';
@ -65,7 +64,6 @@ beforeEach(() => {
test('callRequest', async () => { test('callRequest', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -90,7 +88,6 @@ test('callRequest', async () => {
test('callRequests all requests', async () => { test('callRequests all requests', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -148,7 +145,6 @@ test('callRequests all requests', async () => {
test('callRequests', async () => { test('callRequests', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -182,7 +178,6 @@ test('callRequests', async () => {
test('callRequest error', async () => { test('callRequest error', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -215,7 +210,6 @@ test('callRequest error', async () => {
test('callRequest that is not on root block', async () => { test('callRequest that is not on root block', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -235,7 +229,6 @@ test('callRequest that is not on root block', async () => {
test('callRequest on root block with no requests', async () => { test('callRequest on root block with no requests', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -255,7 +248,6 @@ test('callRequest on root block with no requests', async () => {
test('callRequest request does not exist', async () => { test('callRequest request does not exist', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -282,7 +274,6 @@ test('callRequest request does not exist', async () => {
test('callRequest not called the same request twice with onlyNew true', async () => { test('callRequest not called the same request twice with onlyNew true', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -310,7 +301,6 @@ test('update unction should be called', async () => {
const updateFunction = jest.fn(); const updateFunction = jest.fn();
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,
@ -329,7 +319,6 @@ test('update unction should be called', async () => {
test('fetch should set blocks loading and call query every time it is called', async () => { test('fetch should set blocks loading and call query every time it is called', async () => {
const context = { const context = {
blockId, blockId,
branch,
client, client,
input, input,
lowdefyGlobal, lowdefyGlobal,

View File

@ -4,38 +4,34 @@ test('makeContextId, empty urlQuery', () => {
expect( expect(
makeContextId({ makeContextId({
blockId: 'blockId', blockId: 'blockId',
branch: 'branch',
pageId: 'pageId', pageId: 'pageId',
search: {}, search: {},
}) })
).toEqual('branch:pageId:blockId:{}'); ).toEqual('pageId:blockId:{}');
}); });
test('makeContextId, search', () => { test('makeContextId, search', () => {
expect( expect(
makeContextId({ makeContextId({
blockId: 'blockId', blockId: 'blockId',
branch: 'branch',
pageId: 'pageId', pageId: 'pageId',
urlQuery: { a: 1 }, urlQuery: { a: 1 },
}) })
).toEqual('branch:pageId:blockId:{"a":1}'); ).toEqual('pageId:blockId:{"a":1}');
}); });
test('makeContextId, undefined urlQuery', () => { test('makeContextId, undefined urlQuery', () => {
expect( expect(
makeContextId({ makeContextId({
blockId: 'blockId', blockId: 'blockId',
branch: 'branch',
pageId: 'pageId', pageId: 'pageId',
}) })
).toEqual('branch:pageId:blockId:{}'); ).toEqual('pageId:blockId:{}');
}); });
test('makeContextId, undefined blockId', () => { test('makeContextId, undefined blockId', () => {
expect(() => expect(() =>
makeContextId({ makeContextId({
branch: 'branch',
pageId: 'pageId', pageId: 'pageId',
search: {}, search: {},
}) })
@ -46,7 +42,6 @@ test('makeContextId, blockId not a string', () => {
expect(() => expect(() =>
makeContextId({ makeContextId({
blockId: 1, blockId: 1,
branch: 'branch',
pageId: 'pageId', pageId: 'pageId',
search: {}, search: {},
}) })
@ -56,7 +51,6 @@ test('makeContextId, blockId not a string', () => {
test('makeContextId, undefined pageId', () => { test('makeContextId, undefined pageId', () => {
expect(() => expect(() =>
makeContextId({ makeContextId({
branch: 'branch',
blockId: 'blockId', blockId: 'blockId',
search: {}, search: {},
}) })
@ -67,30 +61,8 @@ test('makeContextId, pageId not a string', () => {
expect(() => expect(() =>
makeContextId({ makeContextId({
pageId: 1, pageId: 1,
branch: 'branch',
blockId: 'blockId', blockId: 'blockId',
search: {}, search: {},
}) })
).toThrow('Expected string for parameter pageId, received 1'); ).toThrow('Expected string for parameter pageId, received 1');
}); });
test('makeContextId, undefined branch', () => {
expect(() =>
makeContextId({
blockId: 'blockId',
pageId: 'pageId',
search: {},
})
).toThrow('Expected string for parameter branch, received undefined');
});
test('makeContextId, branch not a string', () => {
expect(() =>
makeContextId({
branch: 1,
blockId: 'blockId',
pageId: 'pageId',
search: {},
})
).toThrow('Expected string for parameter branch, received 1');
});

View File

@ -13,7 +13,6 @@ const testContext = ({ rootContext, rootBlock, pageId, initState, initLowdefyGlo
actionLog: [], actionLog: [],
appGraphql: rootContext.appGraphql, appGraphql: rootContext.appGraphql,
blockId: rootBlock.blockId, blockId: rootBlock.blockId,
branch: 'branch',
client: rootContext.client, client: rootContext.client,
Components: rootContext.Components || {}, Components: rootContext.Components || {},
config: rootContext.config || {}, config: rootContext.config || {},

View File

@ -16,6 +16,11 @@
import getFormatter from '../src/index'; import getFormatter from '../src/index';
test('default formatter', () => {
const formatter = getFormatter();
expect(formatter('string')).toEqual('string');
});
test('Invalid formatter name', () => { test('Invalid formatter name', () => {
expect(() => { expect(() => {
getFormatter('invalid', {}); getFormatter('invalid', {});

View File

@ -67,10 +67,6 @@ function _args({ params, args, location }) {
return getFromObject(params, args, '_args', location); return getFromObject(params, args, '_args', location);
} }
function _config({ params, config, location }) {
return getFromObject(params, config, '_config', location);
}
function _global({ params, lowdefyGlobal, location }) { function _global({ params, lowdefyGlobal, location }) {
return getFromObject(params, lowdefyGlobal, '_global', location); return getFromObject(params, lowdefyGlobal, '_global', location);
} }
@ -91,10 +87,6 @@ function _url_query({ params, urlQuery, location }) {
return getFromObject(params, urlQuery, '_url_query', location); return getFromObject(params, urlQuery, '_url_query', location);
} }
function _user({ params, user, location }) {
return getFromObject(params, user, '_user', location);
}
function _get({ params, location }) { function _get({ params, location }) {
if (!type.isObject(params)) { if (!type.isObject(params)) {
throw new Error( throw new Error(
@ -116,18 +108,16 @@ function _get({ params, location }) {
} }
class NodeParser { class NodeParser {
constructor({ config, input, lowdefyGlobal, secrets, state, urlQuery, user } = {}) { constructor({ config, input, lowdefyGlobal, secrets, state, urlQuery } = {}) {
this.config = config; this.config = config;
this.input = input; this.input = input;
this.lowdefyGlobal = lowdefyGlobal; this.lowdefyGlobal = lowdefyGlobal;
this.secrets = secrets; this.secrets = secrets;
this.state = state; this.state = state;
this.urlQuery = urlQuery; this.urlQuery = urlQuery;
this.user = user;
this.operations = { this.operations = {
_and, _and,
_args, _args,
_config,
_date, _date,
_dump_yaml, _dump_yaml,
_eq, _eq,
@ -150,7 +140,6 @@ class NodeParser {
_stringify, _stringify,
_type, _type,
_url_query, _url_query,
_user,
}; };
this.operationList = Object.keys(this.operations); this.operationList = Object.keys(this.operations);
} }
@ -184,7 +173,6 @@ class NodeParser {
secrets: this.secrets, secrets: this.secrets,
state: this.state, state: this.state,
urlQuery: this.urlQuery, urlQuery: this.urlQuery,
user: this.user,
}); });
return res; return res;
} }

View File

@ -387,9 +387,6 @@ function _dump_yaml({ params }) {
function _operator(options) { function _operator(options) {
const { operations, params, location } = options; const { operations, params, location } = options;
if (Object.prototype.hasOwnProperty.call(operations, params.name)) {
return operations[params.name]({ ...options, location, params: params && params.params });
}
if (!type.isString(params.name)) { if (!type.isString(params.name)) {
throw new Error( throw new Error(
`Operator Error: _operator.name must be a valid operator name as string. Received: ${JSON.stringify( `Operator Error: _operator.name must be a valid operator name as string. Received: ${JSON.stringify(
@ -404,6 +401,9 @@ function _operator(options) {
)} at ${location}.` )} at ${location}.`
); );
} }
if (Object.prototype.hasOwnProperty.call(operations, params.name)) {
return operations[params.name]({ ...options, location, params: params && params.params });
}
throw new Error( throw new Error(
`Operator Error: _operator - Invalid operator name. Received: ${JSON.stringify( `Operator Error: _operator - Invalid operator name. Received: ${JSON.stringify(
params params

View File

@ -114,10 +114,6 @@ function _args({ args, arrayIndices, location, params }) {
return getFromObject(params, args, arrayIndices, '_args', location); return getFromObject(params, args, arrayIndices, '_args', location);
} }
function _config({ arrayIndices, config, location, params }) {
return getFromObject(params, config, arrayIndices, '_config', location);
}
function _global({ arrayIndices, location, lowdefyGlobal, params }) { function _global({ arrayIndices, location, lowdefyGlobal, params }) {
return getFromObject(params, lowdefyGlobal, arrayIndices, '_global', location); return getFromObject(params, lowdefyGlobal, arrayIndices, '_global', location);
} }
@ -192,10 +188,6 @@ function _url_query({ arrayIndices, context, contexts, location, params, urlQuer
return getFromObject(params, urlQuery, arrayIndices, '_url_query', location); return getFromObject(params, urlQuery, arrayIndices, '_url_query', location);
} }
function _user({ params, user, arrayIndices, location }) {
return getFromObject(params, user, arrayIndices, '_user', location);
}
function _action_log({ params, actionLog, context, contexts, arrayIndices, location }) { function _action_log({ params, actionLog, context, contexts, arrayIndices, location }) {
if (params && params.contextId) { if (params && params.contextId) {
return getFromOtherContext({ return getFromOtherContext({
@ -302,14 +294,13 @@ function _list_contexts({ contexts }) {
} }
class WebParser { class WebParser {
constructor({ context, contexts } = {}) { constructor({ context, contexts }) {
this.context = context; this.context = context;
this.contexts = contexts; this.contexts = contexts;
this.operations = { this.operations = {
_action_log, _action_log,
_and, _and,
_args, _args,
_config,
_date, _date,
_dump_yaml, _dump_yaml,
_eq, _eq,
@ -337,7 +328,6 @@ class WebParser {
_stringify, _stringify,
_type, _type,
_url_query, _url_query,
_user,
}; };
this.operationList = Object.keys(this.operations); this.operationList = Object.keys(this.operations);
} }
@ -376,7 +366,6 @@ class WebParser {
params: value[op], params: value[op],
state: this.context.state, state: this.context.state,
urlQuery: this.context.urlQuery, urlQuery: this.context.urlQuery,
user: this.context.user,
}); });
return res; return res;
} }

View File

@ -1,187 +0,0 @@
/* eslint-disable max-classes-per-file */
import NodeParser from '../../src/nodeParser';
const config = {
string: 'Some String',
number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }],
};
const user = { firstName: 'Name' };
const args = {};
test('_config in object', () => {
const input = { a: { _config: 'string' } };
const parser = new NodeParser({ config, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({
a: 'Some String',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config full config', () => {
const input = { _config: true };
const parser = new NodeParser({ config, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(config);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
// test('_config replace key arrayIndices', () => {
// const input = { a: { _config: 'arr.$.a' } };
// const parser = new NodeParser({
// config,
// user,
// arrayIndices: [1],
// });
// const res = parser.parse({ input, args, location: 'locationId' });
// expect(res.output).toEqual({
// a: 'a2',
// });
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
test('_config param object key', () => {
const input = {
_config: {
key: 'string',
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('Some String');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object all', () => {
const input = {
_config: {
all: true,
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(config);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object all and key', () => {
const input = {
_config: {
all: true,
key: 'string',
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(config);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object invalid', () => {
const input = {
_config: {
other: true,
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _config.key must be of type string. Received: {"other":true} at locationId.],
]
`);
});
test('_config param array', () => {
const input = {
_config: ['string'],
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _config params must be of type string or object. Received: ["string"] at locationId.],
]
`);
});
test('_config param object with string default', () => {
const input = {
_config: {
key: 'notFound',
default: 'defaultValue',
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('defaultValue');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with zero default', () => {
const input = {
_config: {
key: 'notFound',
default: 0,
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(0);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with false default', () => {
const input = {
_config: {
key: 'notFound',
default: false,
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with no default', () => {
const input = {
_config: {
key: 'notFound',
},
};
const parser = new NodeParser({
config,
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});

View File

@ -5,7 +5,6 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_date now', () => { test('_date now', () => {
@ -18,7 +17,7 @@ test('_date now', () => {
} }
}; };
const input = { _date: 'now' }; const input = { _date: 'now' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(constantDate); expect(res.output).toEqual(constantDate);
global.Date = RealDate; global.Date = RealDate;
@ -27,7 +26,7 @@ test('_date now', () => {
test('_date from string', () => { test('_date from string', () => {
const input = { _date: '2018-01-01T12:00:00.000Z' }; const input = { _date: '2018-01-01T12:00:00.000Z' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(new Date('2018-01-01T12:00:00.000Z')); expect(res.output).toEqual(new Date('2018-01-01T12:00:00.000Z'));
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -35,7 +34,7 @@ test('_date from string', () => {
test('_date short format', () => { test('_date short format', () => {
const input = { _date: '2018-01-01' }; const input = { _date: '2018-01-01' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(new Date('2018-01-01')); expect(res.output).toEqual(new Date('2018-01-01'));
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -43,7 +42,7 @@ test('_date short format', () => {
test('_date from unix timestamp', () => { test('_date from unix timestamp', () => {
const input = { _date: 1569579992 }; const input = { _date: 1569579992 };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(new Date(1569579992)); expect(res.output).toEqual(new Date(1569579992));
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -51,7 +50,7 @@ test('_date from unix timestamp', () => {
test('_date null', () => { test('_date null', () => {
const input = { _date: null }; const input = { _date: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -63,7 +62,7 @@ test('_date null', () => {
test('_date invalid operator', () => { test('_date invalid operator', () => {
const input = { _date: {} }; const input = { _date: {} };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -75,7 +74,7 @@ test('_date invalid operator', () => {
test('_date invalid string', () => { test('_date invalid string', () => {
const input = { _date: 'abc' }; const input = { _date: 'abc' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -87,7 +86,7 @@ test('_date invalid string', () => {
test('_date invalid float', () => { test('_date invalid float', () => {
const input = { _date: 1.3 }; const input = { _date: 1.3 };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -99,7 +98,7 @@ test('_date invalid float', () => {
test('_date negative int', () => { test('_date negative int', () => {
const input = { _date: -1000 }; const input = { _date: -1000 };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(new Date(-1000)); expect(res.output).toEqual(new Date(-1000));
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);

View File

@ -6,12 +6,11 @@ const lowdefyGlobal = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_global in object', () => { test('_global in object', () => {
const input = { a: { _global: 'string' } }; const input = { a: { _global: 'string' } };
const parser = new NodeParser({ lowdefyGlobal, user }); const parser = new NodeParser({ lowdefyGlobal });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ expect(res.output).toEqual({
a: 'Some String', a: 'Some String',
@ -21,7 +20,7 @@ test('_global in object', () => {
test('_global full lowdefyGlobal', () => { test('_global full lowdefyGlobal', () => {
const input = { _global: true }; const input = { _global: true };
const parser = new NodeParser({ lowdefyGlobal, user }); const parser = new NodeParser({ lowdefyGlobal });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(lowdefyGlobal); expect(res.output).toEqual(lowdefyGlobal);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -29,7 +28,7 @@ test('_global full lowdefyGlobal', () => {
test('_global null', () => { test('_global null', () => {
const input = { _global: null }; const input = { _global: null };
const parser = new NodeParser({ lowdefyGlobal, user }); const parser = new NodeParser({ lowdefyGlobal });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -39,20 +38,6 @@ test('_global null', () => {
`); `);
}); });
// test('_global replace key arrayIndices', () => {
// const input = { a: { _global: 'arr.$.a' } };
// const parser = new NodeParser({
// lowdefyGlobal,
// user,
// arrayIndices: [1],
// });
// const res = parser.parse({ input, args, location: 'locationId' });
// expect(res.output).toEqual({
// a: 'a2',
// });
// expect(res.errors).toMatchInlineSnapshot(`Array []`);
// });
test('_global param object key', () => { test('_global param object key', () => {
const input = { const input = {
_global: { _global: {
@ -61,7 +46,6 @@ test('_global param object key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('Some String'); expect(res.output).toEqual('Some String');
@ -76,7 +60,6 @@ test('_global param object all', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(lowdefyGlobal); expect(res.output).toEqual(lowdefyGlobal);
@ -92,7 +75,6 @@ test('_global param object all and key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(lowdefyGlobal); expect(res.output).toEqual(lowdefyGlobal);
@ -107,7 +89,6 @@ test('_global param object invalid', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -124,7 +105,6 @@ test('_global param array', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -144,7 +124,6 @@ test('_global param object with string default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('defaultValue'); expect(res.output).toEqual('defaultValue');
@ -160,7 +139,6 @@ test('_global param object with zero default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(0); expect(res.output).toEqual(0);
@ -176,7 +154,6 @@ test('_global param object with false default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(false); expect(res.output).toEqual(false);
@ -191,7 +168,6 @@ test('_global param object with no default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
lowdefyGlobal, lowdefyGlobal,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);

View File

@ -6,7 +6,6 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const input = { const input = {
string: 'input String', string: 'input String',
number: 500, number: 500,
@ -15,7 +14,7 @@ const input = {
test('_input in object', () => { test('_input in object', () => {
const obj = { a: { _input: 'string' } }; const obj = { a: { _input: 'string' } };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual({ expect(res.output).toEqual({
a: 'input String', a: 'input String',
@ -25,7 +24,7 @@ test('_input in object', () => {
test('_input full input', () => { test('_input full input', () => {
const obj = { _input: true }; const obj = { _input: true };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(input); expect(res.output).toEqual(input);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -33,7 +32,7 @@ test('_input full input', () => {
test('_input array', () => { test('_input array', () => {
const obj = { _input: 'arr' }; const obj = { _input: 'arr' };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(input.arr); expect(res.output).toEqual(input.arr);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -41,7 +40,7 @@ test('_input array', () => {
test('_input null', () => { test('_input null', () => {
const obj = { _input: null }; const obj = { _input: null };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -57,7 +56,7 @@ test('_input param object key', () => {
key: 'string', key: 'string',
}, },
}; };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual('input String'); expect(res.output).toEqual('input String');
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -69,7 +68,7 @@ test('_input param object all', () => {
all: true, all: true,
}, },
}; };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(input); expect(res.output).toEqual(input);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -82,7 +81,7 @@ test('_input param object all and key', () => {
key: 'string', key: 'string',
}, },
}; };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(input); expect(res.output).toEqual(input);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -94,7 +93,7 @@ test('_input param object invalid', () => {
other: true, other: true,
}, },
}; };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -108,7 +107,7 @@ test('_input param array', () => {
const obj = { const obj = {
_state: ['string'], _state: ['string'],
}; };
const parser = new NodeParser({ state, user, input }); const parser = new NodeParser({ state, input });
const res = parser.parse({ input: obj, location: 'locationId' }); const res = parser.parse({ input: obj, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -6,7 +6,6 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_mql_aggregate sort', () => { test('_mql_aggregate sort', () => {
@ -29,7 +28,7 @@ test('_mql_aggregate sort', () => {
], ],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual([ expect(res.output).toEqual([
{ {
@ -57,7 +56,7 @@ test('_mql_aggregate on is object', () => {
}, },
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual([ expect(res.output).toEqual([
{ {
@ -88,7 +87,7 @@ test('_mql_aggregate group', () => {
], ],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual([ expect(res.output).toEqual([
{ {
@ -113,7 +112,7 @@ test('_mql_aggregate empty pipeline', () => {
], ],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual([ expect(res.output).toEqual([
{ {
@ -139,7 +138,7 @@ test('_mql_aggregate empty collection', () => {
on: [], on: [],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual([]); expect(res.output).toEqual([]);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -158,7 +157,7 @@ test('_mql_aggregate on is string', () => {
on: 'invalid', on: 'invalid',
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -188,7 +187,7 @@ test('_mql_aggregate invalid', () => {
], ],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -212,7 +211,7 @@ test('_mql_aggregate pipeline not an array', () => {
], ],
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -232,7 +231,7 @@ test('_mql_aggregate params not object', () => {
}, },
], ],
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -5,12 +5,12 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name', number: 2 };
const args = {}; const args = {};
test('_mql_expr add number', () => { test('_mql_expr add number', () => {
const input = { _mql_expr: { $add: ['$number', 2] } }; const input = { _mql_expr: { $add: ['$number', 2] } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(44); expect(res.output).toBe(44);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -18,7 +18,7 @@ test('_mql_expr add number', () => {
test('_mql_expr null', () => { test('_mql_expr null', () => {
const input = { _mql_expr: null }; const input = { _mql_expr: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -32,10 +32,12 @@ test('_mql_expr params on', () => {
const input = { const input = {
_mql_expr: { _mql_expr: {
expr: { $add: ['$number', 2] }, expr: { $add: ['$number', 2] },
on: { _user: true }, on: {
number: 2,
},
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(4); expect(res.output).toBe(4);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -43,7 +45,7 @@ test('_mql_expr params on', () => {
test('_mql_expr invalid', () => { test('_mql_expr invalid', () => {
const input = { _mql_expr: { $cond: ['$number'] } }; const input = { _mql_expr: { $cond: ['$number'] } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -5,12 +5,11 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_mql_test string equal', () => { test('_mql_test string equal', () => {
const input = { _mql_test: { string: { $eq: 'Some String' } } }; const input = { _mql_test: { string: { $eq: 'Some String' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -18,7 +17,7 @@ test('_mql_test string equal', () => {
test('_mql_test string equal shorthand', () => { test('_mql_test string equal shorthand', () => {
const input = { _mql_test: { string: 'Some String' } }; const input = { _mql_test: { string: 'Some String' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -26,7 +25,7 @@ test('_mql_test string equal shorthand', () => {
test('_mql_test string not equal', () => { test('_mql_test string not equal', () => {
const input = { _mql_test: { string: 'Some Other String' } }; const input = { _mql_test: { string: 'Some Other String' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -34,7 +33,7 @@ test('_mql_test string not equal', () => {
test('_mql_test number equal', () => { test('_mql_test number equal', () => {
const input = { _mql_test: { number: { $eq: 42 } } }; const input = { _mql_test: { number: { $eq: 42 } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -42,7 +41,7 @@ test('_mql_test number equal', () => {
test('_mql_test number not equal', () => { test('_mql_test number not equal', () => {
const input = { _mql_test: { number: 'Some Other String' } }; const input = { _mql_test: { number: 'Some Other String' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -50,7 +49,7 @@ test('_mql_test number not equal', () => {
test('_mql_test number greater than', () => { test('_mql_test number greater than', () => {
const input = { _mql_test: { number: { $gt: 1 } } }; const input = { _mql_test: { number: { $gt: 1 } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -58,7 +57,7 @@ test('_mql_test number greater than', () => {
test('_mql_test null', () => { test('_mql_test null', () => {
const input = { _mql_test: null }; const input = { _mql_test: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -71,11 +70,11 @@ test('_mql_test null', () => {
test('_mql_test object params', () => { test('_mql_test object params', () => {
const input = { const input = {
_mql_test: { _mql_test: {
test: { firstName: 'Name' }, test: { value: 'test' },
on: { _user: true }, on: { value: 'test' },
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -84,11 +83,10 @@ test('_mql_test object params', () => {
test('_mql_test invalid params', () => { test('_mql_test invalid params', () => {
const input = { const input = {
_mql_test: { _mql_test: {
other: { firstName: 'Name' }, test: { value: 'test' },
on: { _user: true },
}, },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -96,7 +94,7 @@ test('_mql_test invalid params', () => {
test('_mql_test invalid test', () => { test('_mql_test invalid test', () => {
const input = { _mql_test: { string: { $badOp: 'Some String' } } }; const input = { _mql_test: { string: { $badOp: 'Some String' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -5,12 +5,11 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_nunjucks string template', () => { test('_nunjucks string template', () => {
const input = { _nunjucks: 'String with {{ string }} embedded' }; const input = { _nunjucks: 'String with {{ string }} embedded' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('String with Some String embedded'); expect(res.output).toEqual('String with Some String embedded');
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -18,7 +17,7 @@ test('_nunjucks string template', () => {
test('_nunjucks null', () => { test('_nunjucks null', () => {
const input = { _nunjucks: null }; const input = { _nunjucks: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -28,7 +27,7 @@ test('_nunjucks { template: , on: }', () => {
const input = { const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: { string: 'test' } }, _nunjucks: { template: 'String with {{ string }} embedded', on: { string: 'test' } },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('String with test embedded'); expect(res.output).toEqual('String with test embedded');
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -36,7 +35,7 @@ test('_nunjucks { template: , on: }', () => {
test('_nunjucks template not a string', () => { test('_nunjucks template not a string', () => {
const input = { _nunjucks: ['String with {{ string }} embedded'] }; const input = { _nunjucks: ['String with {{ string }} embedded'] };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -46,7 +45,7 @@ test('_nunjucks params on template not a string', () => {
const input = { const input = {
_nunjucks: { template: ['String with {{ string }} embedded'], on: { string: 'test' } }, _nunjucks: { template: ['String with {{ string }} embedded'], on: { string: 'test' } },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -56,7 +55,7 @@ test('_nunjucks on not a object', () => {
const input = { const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: [{ string: 'test' }] }, _nunjucks: { template: 'String with {{ string }} embedded', on: [{ string: 'test' }] },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe('String with embedded'); expect(res.output).toBe('String with embedded');
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -66,7 +65,7 @@ test('_nunjucks on null', () => {
const input = { const input = {
_nunjucks: { template: 'String with {{ string }} embedded', on: null }, _nunjucks: { template: 'String with {{ string }} embedded', on: null },
}; };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe('String with embedded'); expect(res.output).toBe('String with embedded');
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -74,7 +73,7 @@ test('_nunjucks on null', () => {
test('_nunjucks invalid template', () => { test('_nunjucks invalid template', () => {
const input = { _nunjucks: 'String with {{ string embedded' }; const input = { _nunjucks: 'String with {{ string embedded' };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -5,12 +5,21 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_operator, _state', () => {
const input = { a: { _operator: { name: '_state', params: 'string' } } };
const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({
a: 'Some String',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_operator.name invalid', () => { test('_operator.name invalid', () => {
const input = { a: { _operator: { name: '_a' } } }; const input = { a: { _operator: { name: '_a' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ a: null }); expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -22,7 +31,7 @@ test('_operator.name invalid', () => {
test('_operator.name not a string', () => { test('_operator.name not a string', () => {
const input = { a: { _operator: { name: 1 } } }; const input = { a: { _operator: { name: 1 } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ a: null }); expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -34,7 +43,7 @@ test('_operator.name not a string', () => {
test('_operator with value not a object', () => { test('_operator with value not a object', () => {
const input = { a: { _operator: 'a' } }; const input = { a: { _operator: 'a' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ a: null }); expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -46,19 +55,19 @@ test('_operator with value not a object', () => {
test('_operator cannot be set to _operator', () => { test('_operator cannot be set to _operator', () => {
const input = { a: { _operator: { name: '_operator' } } }; const input = { a: { _operator: { name: '_operator' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ a: null }); expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
Array [ Array [
[TypeError: Cannot read property 'name' of undefined], [Error: Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: {"name":"_operator"} at locationId.],
] ]
`); `);
}); });
test('_operator, _not with no params', () => { test('_operator, _not with no params', () => {
const input = { a: { _operator: { name: '_not' } } }; const input = { a: { _operator: { name: '_not' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ a: true }); expect(res.output).toEqual({ a: true });
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -66,7 +75,7 @@ test('_operator, _not with no params', () => {
test('_operator, _parse with params', () => { test('_operator, _parse with params', () => {
const input = { a: { _operator: { name: '_parse', params: '[{ "a": "a1"}]' } } }; const input = { a: { _operator: { name: '_parse', params: '[{ "a": "a1"}]' } } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ expect(res.output).toEqual({
a: [{ a: 'a1' }], a: [{ a: 'a1' }],

View File

@ -5,12 +5,11 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name', number: 2 };
const args = {}; const args = {};
test('_regex with on, pass', () => { test('_regex with on, pass', () => {
const input = { _regex: { pattern: '^a$', on: 'a' } }; const input = { _regex: { pattern: '^a$', on: 'a' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -18,7 +17,7 @@ test('_regex with on, pass', () => {
test('_regex with on, fail', () => { test('_regex with on, fail', () => {
const input = { _regex: { pattern: '^a$', on: 'b' } }; const input = { _regex: { pattern: '^a$', on: 'b' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -26,7 +25,7 @@ test('_regex with on, fail', () => {
test('_regex with key, pass', () => { test('_regex with key, pass', () => {
const input = { _regex: { pattern: '^Some String$', key: 'string' } }; const input = { _regex: { pattern: '^Some String$', key: 'string' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -34,7 +33,7 @@ test('_regex with key, pass', () => {
test('_regex with key, fail', () => { test('_regex with key, fail', () => {
const input = { _regex: { pattern: '^a$', key: 'string' } }; const input = { _regex: { pattern: '^a$', key: 'string' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -42,7 +41,7 @@ test('_regex with key, fail', () => {
test('_regex with null on', () => { test('_regex with null on', () => {
const input = { _regex: { pattern: '^a$', on: null } }; const input = { _regex: { pattern: '^a$', on: null } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -50,7 +49,7 @@ test('_regex with null on', () => {
test('_regex with nonexistent key', () => { test('_regex with nonexistent key', () => {
const input = { _regex: { pattern: '^a$', key: 'notThere' } }; const input = { _regex: { pattern: '^a$', key: 'notThere' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -62,7 +61,7 @@ test('_regex with nonexistent key', () => {
test('_regex with nonexistent key', () => { test('_regex with nonexistent key', () => {
const input = { _regex: { pattern: '^a$', key: null } }; const input = { _regex: { pattern: '^a$', key: null } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -74,7 +73,7 @@ test('_regex with nonexistent key', () => {
test('_regex null', () => { test('_regex null', () => {
const input = { _regex: null }; const input = { _regex: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -86,7 +85,7 @@ test('_regex null', () => {
test('_regex with non-string on', () => { test('_regex with non-string on', () => {
const input = { _regex: { pattern: '^a$', on: 5 } }; const input = { _regex: { pattern: '^a$', on: 5 } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -98,7 +97,7 @@ test('_regex with non-string on', () => {
test('_regex flags', () => { test('_regex flags', () => {
const input = { _regex: { pattern: 'a', on: 'A', flags: 'i' } }; const input = { _regex: { pattern: 'a', on: 'A', flags: 'i' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -106,7 +105,7 @@ test('_regex flags', () => {
test('_regex invalid flags', () => { test('_regex invalid flags', () => {
const input = { _regex: { pattern: 'a', on: 'a', flags: 1 } }; const input = { _regex: { pattern: 'a', on: 'a', flags: 1 } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`

View File

@ -6,12 +6,11 @@ const secrets = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_secret in object', () => { test('_secret in object', () => {
const input = { a: { _secret: 'string' } }; const input = { a: { _secret: 'string' } };
const parser = new NodeParser({ secrets, user }); const parser = new NodeParser({ secrets });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ expect(res.output).toEqual({
a: 'Some String', a: 'Some String',
@ -21,7 +20,7 @@ test('_secret in object', () => {
test('_secret full secrets', () => { test('_secret full secrets', () => {
const input = { _secret: true }; const input = { _secret: true };
const parser = new NodeParser({ secrets, user }); const parser = new NodeParser({ secrets });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(secrets); expect(res.output).toEqual(secrets);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -29,7 +28,7 @@ test('_secret full secrets', () => {
test('_secret null', () => { test('_secret null', () => {
const input = { _secret: null }; const input = { _secret: null };
const parser = new NodeParser({ secrets, user }); const parser = new NodeParser({ secrets });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -47,7 +46,6 @@ test('_secret param object key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('Some String'); expect(res.output).toEqual('Some String');
@ -62,7 +60,6 @@ test('_secret param object all', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(secrets); expect(res.output).toEqual(secrets);
@ -78,7 +75,6 @@ test('_secret param object all and key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(secrets); expect(res.output).toEqual(secrets);
@ -93,7 +89,6 @@ test('_secret param object invalid', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -110,7 +105,6 @@ test('_secret param array', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -130,7 +124,6 @@ test('_secret param object with string default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('defaultValue'); expect(res.output).toEqual('defaultValue');
@ -146,7 +139,6 @@ test('_secret param object with zero default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(0); expect(res.output).toEqual(0);
@ -162,7 +154,6 @@ test('_secret param object with false default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(false); expect(res.output).toEqual(false);
@ -177,7 +168,6 @@ test('_secret param object with no default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
secrets, secrets,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);

View File

@ -6,12 +6,11 @@ const state = {
number: 42, number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
}; };
const user = { firstName: 'Name' };
const args = {}; const args = {};
test('_state in object', () => { test('_state in object', () => {
const input = { a: { _state: 'string' } }; const input = { a: { _state: 'string' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({ expect(res.output).toEqual({
a: 'Some String', a: 'Some String',
@ -21,7 +20,7 @@ test('_state in object', () => {
test('_state full state', () => { test('_state full state', () => {
const input = { _state: true }; const input = { _state: true };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(state); expect(res.output).toEqual(state);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -29,7 +28,7 @@ test('_state full state', () => {
test('_state null', () => { test('_state null', () => {
const input = { _state: null }; const input = { _state: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -47,7 +46,6 @@ test('_state param object key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('Some String'); expect(res.output).toEqual('Some String');
@ -62,7 +60,6 @@ test('_state param object all', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(state); expect(res.output).toEqual(state);
@ -78,7 +75,6 @@ test('_state param object all and key', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(state); expect(res.output).toEqual(state);
@ -93,7 +89,6 @@ test('_state param object invalid', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -110,7 +105,6 @@ test('_state param array', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);
@ -130,7 +124,6 @@ test('_state param object with string default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('defaultValue'); expect(res.output).toEqual('defaultValue');
@ -146,7 +139,6 @@ test('_state param object with zero default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(0); expect(res.output).toEqual(0);
@ -162,7 +154,6 @@ test('_state param object with false default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(false); expect(res.output).toEqual(false);
@ -177,7 +168,6 @@ test('_state param object with no default', () => {
}; };
const parser = new NodeParser({ const parser = new NodeParser({
state, state,
user,
}); });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null); expect(res.output).toEqual(null);

View File

@ -6,12 +6,11 @@ const state = {
arr: [{ a: 'a1' }, { a: 'a2' }], arr: [{ a: 'a1' }, { a: 'a2' }],
boolean: true, boolean: true,
}; };
const user = { firstName: 'Name', number: 2 };
const args = {}; const args = {};
test('_type with on, pass', () => { test('_type with on, pass', () => {
const input = { _type: { type: 'string', on: 'a' } }; const input = { _type: { type: 'string', on: 'a' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -19,7 +18,7 @@ test('_type with on, pass', () => {
test('_type with on, fail', () => { test('_type with on, fail', () => {
const input = { _type: { type: 'number', on: 'b' } }; const input = { _type: { type: 'number', on: 'b' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -27,7 +26,7 @@ test('_type with on, fail', () => {
test('_type with key, pass', () => { test('_type with key, pass', () => {
const input = { _type: { type: 'string', key: 'string' } }; const input = { _type: { type: 'string', key: 'string' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -35,7 +34,7 @@ test('_type with key, pass', () => {
test('_type with key, fail', () => { test('_type with key, fail', () => {
const input = { _type: { type: 'number', key: 'string' } }; const input = { _type: { type: 'number', key: 'string' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -43,14 +42,14 @@ test('_type with key, fail', () => {
test('_type with null on pass', () => { test('_type with null on pass', () => {
const input = { _type: { type: 'null', on: null } }; const input = { _type: { type: 'null', on: null } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
}); });
test('_type with null on fail', () => { test('_type with null on fail', () => {
const input = { _type: { type: 'boolean', on: null } }; const input = { _type: { type: 'boolean', on: null } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -58,7 +57,7 @@ test('_type with null on fail', () => {
test('_type with nonexistent key', () => { test('_type with nonexistent key', () => {
const input = { _type: { type: 'string', key: 'notThere' } }; const input = { _type: { type: 'string', key: 'notThere' } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -66,7 +65,7 @@ test('_type with nonexistent key', () => {
test('_type with nonexistent key', () => { test('_type with nonexistent key', () => {
const input = { _type: { type: 'string', key: null } }; const input = { _type: { type: 'string', key: null } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -74,7 +73,7 @@ test('_type with nonexistent key', () => {
test('_type null', () => { test('_type null', () => {
const input = { _type: null }; const input = { _type: null };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -86,7 +85,7 @@ test('_type null', () => {
test('_type with non-string on', () => { test('_type with non-string on', () => {
const input = { _type: { type: 'number', on: 5 } }; const input = { _type: { type: 'number', on: 5 } };
const parser = new NodeParser({ state, user }); const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' }); const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -94,7 +93,7 @@ test('_type with non-string on', () => {
test('_type with unknown type', () => { test('_type with unknown type', () => {
const input = { _type: 'strings', key: 'string' }; const input = { _type: 'strings', key: 'string' };
const parser = new NodeParser({ state, user, arrayIndices: [] }); const parser = new NodeParser({ state, arrayIndices: [] });
const res = parser.parse({ input, location: 'locationId' }); const res = parser.parse({ input, location: 'locationId' });
expect(res.output).toBe(null); expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
@ -106,7 +105,7 @@ test('_type with unknown type', () => {
test('_type date with on packed date pass', () => { test('_type date with on packed date pass', () => {
const input = { _type: { type: 'date', on: { _date: Date.now() } } }; const input = { _type: { type: 'date', on: { _date: Date.now() } } };
const parser = new NodeParser({ state, user, arrayIndices: [] }); const parser = new NodeParser({ state, arrayIndices: [] });
const res = parser.parse({ input, id: '1', location: 'locationId' }); const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -114,7 +113,7 @@ test('_type date with on packed date pass', () => {
test('_type date on string date fail', () => { test('_type date on string date fail', () => {
const input = { _type: { type: 'date', on: '2019-11-28T08:10:09.844Z' } }; const input = { _type: { type: 'date', on: '2019-11-28T08:10:09.844Z' } };
const parser = new NodeParser({ state, user, arrayIndices: [] }); const parser = new NodeParser({ state, arrayIndices: [] });
const res = parser.parse({ input, id: '1', location: 'locationId' }); const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(false); expect(res.output).toBe(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
@ -122,7 +121,7 @@ test('_type date on string date fail', () => {
test('_type date on date object pass', () => { test('_type date on date object pass', () => {
const input = { _type: { type: 'date', on: new Date() } }; const input = { _type: { type: 'date', on: new Date() } };
const parser = new NodeParser({ state, user, arrayIndices: [] }); const parser = new NodeParser({ state, arrayIndices: [] });
const res = parser.parse({ input, id: '1', location: 'locationId' }); const res = parser.parse({ input, id: '1', location: 'locationId' });
expect(res.output).toBe(true); expect(res.output).toBe(true);
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);

View File

@ -1,165 +0,0 @@
import NodeParser from '../../src/nodeParser';
const state = {
string: 'Some String',
number: 42,
arr: [{ a: 'a1' }, { a: 'a2' }],
};
const user = { firstName: 'Name' };
const args = {};
test('_user in object', () => {
const input = { a: { _user: 'firstName' } };
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual({
a: 'Name',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user full user', () => {
const input = { _user: true };
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(user);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user null', () => {
const input = { _user: null };
const parser = new NodeParser({ state });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user params must be of type string or object. Received: null at locationId.],
]
`);
});
test('_user param object key', () => {
const input = {
_user: {
key: 'firstName',
},
};
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('Name');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object all', () => {
const input = {
_user: {
all: true,
},
};
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(user);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object all and key', () => {
const input = {
_user: {
all: true,
key: 'firstName',
},
};
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(user);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object invalid', () => {
const input = {
_user: {
other: true,
},
};
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user.key must be of type string. Received: {"other":true} at locationId.],
]
`);
});
test('_user param array', () => {
const input = {
_user: ['firstName'],
};
const parser = new NodeParser({ state, user });
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user params must be of type string or object. Received: ["firstName"] at locationId.],
]
`);
});
test('_user param object with string default', () => {
const input = {
_user: {
key: 'notFound',
default: 'defaultValue',
},
};
const parser = new NodeParser({
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual('defaultValue');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with zero default', () => {
const input = {
_user: {
key: 'notFound',
default: 0,
},
};
const parser = new NodeParser({
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(0);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with false default', () => {
const input = {
_user: {
key: 'notFound',
default: false,
},
};
const parser = new NodeParser({
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with no default', () => {
const input = {
_user: {
key: 'notFound',
},
};
const parser = new NodeParser({
user,
});
const res = parser.parse({ input, args, location: 'locationId' });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};
@ -161,3 +157,11 @@ test('parse js dates, do not modify input', () => {
expect(input).toEqual({ a: new Date(1) }); expect(input).toEqual({ a: new Date(1) });
expect(res.errors).toMatchInlineSnapshot(`Array []`); expect(res.errors).toMatchInlineSnapshot(`Array []`);
}); });
test('parse location not specified', () => {
const input = { _state: 'string' };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, arrayIndices });
expect(res.output).toEqual('state');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});

View File

@ -64,10 +64,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -1,216 +0,0 @@
/* eslint-disable max-classes-per-file */
import WebParser from '../../src/webParser';
const args = {
string: 'args',
arr: [{ a: 'args1' }, { a: 'args2' }],
};
const context = {
config: {
string: 'config',
arr: [{ a: 'config1' }, { a: 'config2' }],
},
input: {
string: 'input',
arr: [{ a: 'input1' }, { a: 'input2' }],
},
lowdefyGlobal: {
string: 'global',
arr: [{ a: 'global1' }, { a: 'global2' }],
},
menus: [
{
menuId: 'default',
},
{
menuId: 'm_1',
},
{
menuId: 'm_2',
},
],
mutations: {
not_loaded: { loading: true, response: 'fail' },
string: { loading: false, response: 'mutation String' },
number: { loading: false, response: 500 },
arr: { loading: false, response: [{ a: 'mutation a1' }, { a: 'mutation a2' }] },
},
requests: {
not_loaded: { loading: true, response: 'fail' },
string: { loading: false, response: 'request String' },
number: { loading: false, response: 500 },
arr: { loading: false, response: [{ a: 'request a1' }, { a: 'request a2' }] },
},
state: {
string: 'state',
arr: [{ a: 'state1' }, { a: 'state2' }],
},
urlQuery: {
string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
},
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
};
const contexts = {};
const arrayIndices = [1];
test('_config in object', () => {
const input = { a: { _config: 'string' } };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
a: 'config',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config full config', () => {
const input = { _config: true };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'config',
arr: [{ a: 'config1' }, { a: 'config2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config replace key arrayIndices', () => {
const input = { a: { _config: 'arr.$.a' } };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
a: 'config2',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object key', () => {
const input = {
_config: {
key: 'string',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual('config');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object all', () => {
const input = {
_config: {
all: true,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'config',
arr: [{ a: 'config1' }, { a: 'config2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object all and key', () => {
const input = {
_config: {
all: true,
key: 'string',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'config',
arr: [{ a: 'config1' }, { a: 'config2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object invalid', () => {
const input = {
_config: {
other: true,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _config.key must be of type string. Received: {"other":true} at locationId.],
]
`);
});
test('_config param array', () => {
const input = {
_config: ['string'],
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _config params must be of type string or object. Received: ["string"] at locationId.],
]
`);
});
test('_config param object with string default', () => {
const input = {
_config: {
key: 'notFound',
default: 'defaultValue',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual('defaultValue');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with zero default', () => {
const input = {
_config: {
key: 'notFound',
default: 0,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(0);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with false default', () => {
const input = {
_config: {
key: 'notFound',
default: false,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_config param object with no default', () => {
const input = {
_config: {
key: 'notFound',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -66,10 +66,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -133,10 +129,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -103,10 +99,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -103,10 +99,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -103,10 +99,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -103,10 +99,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };
@ -103,10 +99,6 @@ const otherContext = {
string: 'urlQuery-other', string: 'urlQuery-other',
arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
updateListeners: new Set(), updateListeners: new Set(),
}; };

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -45,10 +45,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -46,10 +46,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = { const contexts = {

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -44,10 +44,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};
@ -123,8 +119,8 @@ test('_mql_test null', () => {
test('_mql_test object params', () => { test('_mql_test object params', () => {
const input = { const input = {
_mql_test: { _mql_test: {
test: { string: 'user' }, test: { test: 'value' },
on: { _user: true }, on: { test: 'value' },
}, },
}; };
const parser = new WebParser({ context, contexts }); const parser = new WebParser({ context, contexts });
@ -136,8 +132,7 @@ test('_mql_test object params', () => {
test('_mql_test invalid params', () => { test('_mql_test invalid params', () => {
const input = { const input = {
_mql_test: { _mql_test: {
other: { string: 'user' }, other: { test: 'value' },
on: { _user: true },
}, },
}; };
const parser = new WebParser({ context, contexts }); const parser = new WebParser({ context, contexts });

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,16 +49,22 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};
const arrayIndices = [1]; const arrayIndices = [1];
test('_operator, _state', () => {
const input = { a: { _operator: { name: '_state', params: 'string' } } };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
a: 'state',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_operator.name invalid', () => { test('_operator.name invalid', () => {
const input = { a: { _operator: { name: '_a' } } }; const input = { a: { _operator: { name: '_a' } } };
const parser = new WebParser({ context, contexts }); const parser = new WebParser({ context, contexts });
@ -102,7 +108,7 @@ test('_operator cannot be set to _operator', () => {
expect(res.output).toEqual({ a: null }); expect(res.output).toEqual({ a: null });
expect(res.errors).toMatchInlineSnapshot(` expect(res.errors).toMatchInlineSnapshot(`
Array [ Array [
[TypeError: Cannot read property 'name' of undefined], [Error: Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: {"name":"_operator"} at locationId.],
] ]
`); `);
}); });

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -50,10 +50,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -55,10 +55,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -51,10 +51,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -49,10 +49,6 @@ const context = {
string: 'urlQuery', string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
}, },
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
}; };
const contexts = {}; const contexts = {};

View File

@ -1,227 +0,0 @@
import WebParser from '../../src/webParser';
const args = {
string: 'args',
arr: [{ a: 'args1' }, { a: 'args2' }],
};
const context = {
config: {
string: 'config',
arr: [{ a: 'config1' }, { a: 'config2' }],
},
input: {
string: 'input',
arr: [{ a: 'input1' }, { a: 'input2' }],
},
lowdefyGlobal: {
string: 'global',
arr: [{ a: 'global1' }, { a: 'global2' }],
},
menus: [
{
menuId: 'default',
},
{
menuId: 'm_1',
},
{
menuId: 'm_2',
},
],
mutations: {
not_loaded: { loading: true, response: 'fail' },
string: { loading: false, response: 'mutation String' },
number: { loading: false, response: 500 },
arr: { loading: false, response: [{ a: 'mutation a1' }, { a: 'mutation a2' }] },
},
requests: {
not_loaded: { loading: true, response: 'fail' },
string: { loading: false, response: 'request String' },
number: { loading: false, response: 500 },
arr: { loading: false, response: [{ a: 'request a1' }, { a: 'request a2' }] },
},
state: {
string: 'state',
arr: [{ a: 'state1' }, { a: 'state2' }],
},
urlQuery: {
string: 'urlQuery',
arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }],
},
user: {
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
},
};
const contexts = {};
const arrayIndices = [1];
test('_user in object', () => {
const input = { a: { _user: 'string' } };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
a: 'user',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user full user', () => {
const input = { _user: true };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user null', () => {
const input = { _user: null };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toBe(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user params must be of type string or object. Received: null at locationId.],
]
`);
});
test('_user param object key', () => {
const input = {
_user: {
key: 'string',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual('user');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object all', () => {
const input = {
_user: {
all: true,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object all and key', () => {
const input = {
_user: {
all: true,
key: 'string',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
string: 'user',
arr: [{ a: 'user1' }, { a: 'user2' }],
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object invalid', () => {
const input = {
_user: {
other: true,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user.key must be of type string. Received: {"other":true} at locationId.],
]
`);
});
test('_user param array', () => {
const input = {
_user: ['firstName'],
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`
Array [
[Error: Operator Error: _user params must be of type string or object. Received: ["firstName"] at locationId.],
]
`);
});
test('_user param object with string default', () => {
const input = {
_user: {
key: 'notFound',
default: 'defaultValue',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual('defaultValue');
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with zero default', () => {
const input = {
_user: {
key: 'notFound',
default: 0,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(0);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with false default', () => {
const input = {
_user: {
key: 'notFound',
default: false,
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(false);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user param object with no default', () => {
const input = {
_user: {
key: 'notFound',
},
};
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, args, location: 'locationId', arrayIndices });
expect(res.output).toEqual(null);
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});
test('_user replace key arrayIndices', () => {
const input = { a: { _user: 'arr.$.a' } };
const parser = new WebParser({ context, contexts });
const res = parser.parse({ input, location: 'locationId', arrayIndices });
expect(res.output).toEqual({
a: 'user2',
});
expect(res.errors).toMatchInlineSnapshot(`Array []`);
});