diff --git a/packages/engine/src/Actions.js b/packages/engine/src/Actions.js index 8f615c9c2..086cb38de 100644 --- a/packages/engine/src/Actions.js +++ b/packages/engine/src/Actions.js @@ -22,39 +22,9 @@ import type from '@lowdefy/type'; import get from '@lowdefy/get'; import set from '@lowdefy/set'; import serializer from '@lowdefy/serializer'; -import gql from 'graphql-tag'; 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 { constructor(context) { this.context = context; @@ -62,35 +32,25 @@ class Actions { this.build = this.build.bind(this); this.callMethod = this.callMethod.bind(this); this.fetch = this.fetch.bind(this); - this.getCliToken = this.getCliToken.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.mutate = this.mutate.bind(this); - this.notification = this.notification.bind(this); this.reset = this.reset.bind(this); this.scrollTo = this.scrollTo.bind(this); this.setGlobal = this.setGlobal.bind(this); this.setState = this.setState.bind(this); - this.updateProfile = this.updateProfile.bind(this); this.validate = this.validate.bind(this); this.actions = { CallMethod: this.callMethod, Fetch: this.fetch, - GetCliToken: this.getCliToken, Link: this.link, - Login: this.login, - Logout: this.logout, Message: this.message, Mutate: this.mutate, - Notification: this.notification, Reset: this.reset, ScrollTo: this.scrollTo, SetGlobal: this.setGlobal, SetState: this.setState, - UpdateProfile: this.updateProfile, 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) { if (type.isNone(params)) { 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) { try { const { output: parsed, errors: parseErrors } = this.context.parser.parse({ @@ -420,7 +332,6 @@ class Actions { // set input for page before changing if (!type.isNone(parsedParams.input)) { const nextContextId = makeContextId({ - branch: this.context.branch, pageId, search: parsedParams.urlQuery, blockId: pageId, @@ -455,97 +366,6 @@ class Actions { 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) { try { this.context.showValidationErrors = true; diff --git a/packages/engine/src/AppGraphql.js b/packages/engine/src/AppGraphql.js deleted file mode 100644 index b82d34a9a..000000000 --- a/packages/engine/src/AppGraphql.js +++ /dev/null @@ -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; diff --git a/packages/engine/src/Blocks.js b/packages/engine/src/Blocks.js index 4206df67e..7b86517e5 100644 --- a/packages/engine/src/Blocks.js +++ b/packages/engine/src/Blocks.js @@ -613,7 +613,7 @@ class Blocks { } generateCacheId(blockIdPattern) { - return `${this.context.branch}:${this.context.pageId}:${blockIdPattern}:${Math.random() + return `${this.context.pageId}:${blockIdPattern}:${Math.random() .toString(36) .replace(/[^a-z]+/g, '') .substr(0, 5)}`; diff --git a/packages/engine/src/Mutations.js b/packages/engine/src/Mutations.js index 6372de8d1..148082b92 100644 --- a/packages/engine/src/Mutations.js +++ b/packages/engine/src/Mutations.js @@ -72,7 +72,6 @@ class Mutations { mutationId, args: serializer.serialize(args) || {}, blockId: this.context.blockId, - branch: this.context.branch, input: serializer.serialize(this.context.input), lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal), pageId: this.context.pageId, diff --git a/packages/engine/src/Requests.js b/packages/engine/src/Requests.js index ec477fa5a..8b56726b3 100644 --- a/packages/engine/src/Requests.js +++ b/packages/engine/src/Requests.js @@ -90,7 +90,6 @@ class Requests { requestInput: { requestId, blockId: this.context.blockId, - branch: this.context.branch, input: serializer.serialize(this.context.input), lowdefyGlobal: serializer.serialize(this.context.lowdefyGlobal), pageId: this.context.pageId, diff --git a/packages/engine/src/getContext.js b/packages/engine/src/getContext.js index ecc278485..dab7184ac 100644 --- a/packages/engine/src/getContext.js +++ b/packages/engine/src/getContext.js @@ -14,7 +14,6 @@ limitations under the License. */ -import { getFieldVales } from '@lowdefy/helpers'; import { WebParser } from '@lowdefy/operators'; import Actions from './Actions'; @@ -29,7 +28,6 @@ const blockData = ({ areas, blockId, blocks, - branch, defaultValue, field, id, @@ -49,7 +47,6 @@ const blockData = ({ areas, blockId, blocks, - branch, defaultValue, field, id, @@ -73,7 +70,6 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti rootContext.contexts[contextId].lowdefyGlobal = rootContext.lowdefyGlobal; rootContext.contexts[contextId].menus = rootContext.menus; rootContext.contexts[contextId].config = rootContext.config; - rootContext.contexts[contextId].user = rootContext.user; rootContext.contexts[contextId].update(); return rootContext.contexts[contextId]; } @@ -85,22 +81,16 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti id: contextId, pageId, actionLog: [], - appGraphql: rootContext.appGraphql, blockId: block.blockId, - branch: rootContext.branch, client: rootContext.client, - Components: rootContext.Components, config: rootContext.config, displayMessage: message, - displayNotification: notification, document: rootContext.document, input: rootContext.input[contextId] || {}, allInputs: rootContext.input, - localStore: rootContext.localStore, lowdefyGlobal: rootContext.lowdefyGlobal, menus: rootContext.menus, mutations: {}, - openidLogoutUrl: rootContext.openidLogoutUrl, requests: {}, rootBlock: blockData(block), // filter block to prevent circular loop structure routeHistory: rootContext.routeHistory, @@ -108,7 +98,6 @@ const getContext = async ({ block, contextId, pageId, rootContext, message, noti state: {}, update: () => {}, // Initialize update since Requests/Mutations might call it during context creation urlQuery: rootContext.urlQuery, - user: rootContext.user, window: rootContext.window, updateListeners: new Set(), }; diff --git a/packages/engine/src/index.js b/packages/engine/src/index.js index 36620b8c7..fe218ed68 100644 --- a/packages/engine/src/index.js +++ b/packages/engine/src/index.js @@ -15,7 +15,6 @@ */ import Actions from './Actions'; -import AppGraphql from './AppGraphql'; import BlockActions from './BlockActions'; import Blocks from './Blocks'; import makeContextId from './makeContextId'; @@ -25,6 +24,6 @@ import State from './State'; import getContext from './getContext'; -export { Actions, AppGraphql, BlockActions, Blocks, makeContextId, Mutations, Requests, State }; +export { Actions, BlockActions, Blocks, makeContextId, Mutations, Requests, State }; export default getContext; diff --git a/packages/engine/src/makeContextId.js b/packages/engine/src/makeContextId.js index 224704f9c..990f9d488 100644 --- a/packages/engine/src/makeContextId.js +++ b/packages/engine/src/makeContextId.js @@ -17,17 +17,14 @@ import type from '@lowdefy/type'; import serializer from '@lowdefy/serializer'; -function makeContextId({ blockId, branch, pageId, urlQuery = {} }) { +function makeContextId({ blockId, pageId, urlQuery = {} }) { if (!type.isString(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)) { 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; diff --git a/packages/engine/test/Actions/CallMethod.test.js b/packages/engine/test/Actions/CallMethod.test.js index 0374a8a05..641adfc4a 100644 --- a/packages/engine/test/Actions/CallMethod.test.js +++ b/packages/engine/test/Actions/CallMethod.test.js @@ -1,6 +1,5 @@ import testContext from '../testContext'; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; @@ -15,7 +14,6 @@ const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; const rootContext = { - branch, client, message, openidLogoutUrl, diff --git a/packages/engine/test/Actions/Fetch.test.js b/packages/engine/test/Actions/Fetch.test.js index f14496cf4..442a04ade 100644 --- a/packages/engine/test/Actions/Fetch.test.js +++ b/packages/engine/test/Actions/Fetch.test.js @@ -44,13 +44,11 @@ const mockMessageSuccess = jest.fn(); const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, diff --git a/packages/engine/test/Actions/Link.test.js b/packages/engine/test/Actions/Link.test.js index 8dd8dbec0..ee42da816 100644 --- a/packages/engine/test/Actions/Link.test.js +++ b/packages/engine/test/Actions/Link.test.js @@ -19,13 +19,11 @@ const window = { scrollTo: mockWindowScrollTo, }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, @@ -300,7 +298,7 @@ test('Link with pageId and input', async () => { const { button } = context.RootBlocks.map; button.callAction({ action: 'onClick' }); 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 () => { @@ -341,5 +339,5 @@ test('Link with pageId and input and newWindow', async () => { const { button } = context.RootBlocks.map; button.callAction({ action: 'onClick' }); 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 }); }); diff --git a/packages/engine/test/Actions/Message.test.js b/packages/engine/test/Actions/Message.test.js index 326618931..3e0c3206e 100644 --- a/packages/engine/test/Actions/Message.test.js +++ b/packages/engine/test/Actions/Message.test.js @@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn(); const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, diff --git a/packages/engine/test/Actions/Mutate.test.js b/packages/engine/test/Actions/Mutate.test.js index dc84155da..b3127b319 100644 --- a/packages/engine/test/Actions/Mutate.test.js +++ b/packages/engine/test/Actions/Mutate.test.js @@ -93,13 +93,11 @@ const window = { scrollTo: mockWindowScrollTo, }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, diff --git a/packages/engine/test/Actions/Notification.test.js b/packages/engine/test/Actions/Notification.test.js deleted file mode 100644 index 34da42f06..000000000 --- a/packages/engine/test/Actions/Notification.test.js +++ /dev/null @@ -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, - }, - ], - ]); -}); diff --git a/packages/engine/test/Actions/Reset.test.js b/packages/engine/test/Actions/Reset.test.js index 510f639a0..d18630387 100644 --- a/packages/engine/test/Actions/Reset.test.js +++ b/packages/engine/test/Actions/Reset.test.js @@ -44,13 +44,11 @@ const mockMessageSuccess = jest.fn(); const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, message, document, diff --git a/packages/engine/test/Actions/ScrollTo.test.js b/packages/engine/test/Actions/ScrollTo.test.js index 24a5aa8d8..b6ddce6ac 100644 --- a/packages/engine/test/Actions/ScrollTo.test.js +++ b/packages/engine/test/Actions/ScrollTo.test.js @@ -29,13 +29,11 @@ const window = { scrollTo: mockWindowScrollTo, }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, diff --git a/packages/engine/test/Actions/SetState.test.js b/packages/engine/test/Actions/SetState.test.js index c27da517c..3609c2c7d 100644 --- a/packages/engine/test/Actions/SetState.test.js +++ b/packages/engine/test/Actions/SetState.test.js @@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn(); const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, // appGraphql, message, diff --git a/packages/engine/test/Actions/Validate.test.js b/packages/engine/test/Actions/Validate.test.js index 7f46d93a9..cc18ce639 100644 --- a/packages/engine/test/Actions/Validate.test.js +++ b/packages/engine/test/Actions/Validate.test.js @@ -9,13 +9,11 @@ const mockMessageSuccess = jest.fn(); const mockMessageError = jest.fn(); const message = { loading: () => jest.fn(), error: mockMessageError, success: mockMessageSuccess }; -const branch = 'master'; const openidLogoutUrl = 'logout'; const pageId = 'one'; const user = { firstName: 'ABC' }; const rootContext = { - branch, client, message, openidLogoutUrl, diff --git a/packages/engine/test/Block/Blocks.test.js b/packages/engine/test/Block/Blocks.test.js index 8ad76a124..faba179cb 100644 --- a/packages/engine/test/Block/Blocks.test.js +++ b/packages/engine/test/Block/Blocks.test.js @@ -7,12 +7,10 @@ import State from '../../src/State'; import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; @@ -53,7 +51,6 @@ test('set block to init', () => { // can't use testContext test('Blocks to init with no blocks passed', () => { const context = { - branch, client, pageId, state: { a: 'a' }, @@ -73,7 +70,6 @@ test('Blocks to init with no blocks passed', () => { // can't use testContext test('Blocks to init with arrayIndices not an array', () => { const context = { - branch, client, pageId, state: { textInput: 'a' }, @@ -116,7 +112,6 @@ test('Blocks to init with arrayIndices not an array', () => { test('Blocks to init with undefined arrayIndices', () => { const context = { - branch, client, pageId, state: { textInput: 'a' }, diff --git a/packages/engine/test/Block/areas.test.js b/packages/engine/test/Block/areas.test.js index 3e04bc23a..15446f06f 100644 --- a/packages/engine/test/Block/areas.test.js +++ b/packages/engine/test/Block/areas.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/benchmark.test.js b/packages/engine/test/Block/benchmark.test.js index 44ae377b4..e2bfe8034 100644 --- a/packages/engine/test/Block/benchmark.test.js +++ b/packages/engine/test/Block/benchmark.test.js @@ -2,12 +2,10 @@ import testContext from '../testContext'; const NUM_TIMES = 10; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/container.test.js b/packages/engine/test/Block/container.test.js index be9bf4b14..bceed5f38 100644 --- a/packages/engine/test/Block/container.test.js +++ b/packages/engine/test/Block/container.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/context.test.js b/packages/engine/test/Block/context.test.js index 6c0df2d74..fd01dd53f 100644 --- a/packages/engine/test/Block/context.test.js +++ b/packages/engine/test/Block/context.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/evaluate.test.js b/packages/engine/test/Block/evaluate.test.js index efe53c1f5..fe52c3ec0 100644 --- a/packages/engine/test/Block/evaluate.test.js +++ b/packages/engine/test/Block/evaluate.test.js @@ -1,12 +1,10 @@ /* eslint-disable dot-notation */ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/field.test.js b/packages/engine/test/Block/field.test.js index 693f6ab24..930fea8f6 100644 --- a/packages/engine/test/Block/field.test.js +++ b/packages/engine/test/Block/field.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/list.test.js b/packages/engine/test/Block/list.test.js index ab64bc0f3..c805f6ae5 100644 --- a/packages/engine/test/Block/list.test.js +++ b/packages/engine/test/Block/list.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/map.test.js b/packages/engine/test/Block/map.test.js index 4f04cb08e..37acb91a4 100644 --- a/packages/engine/test/Block/map.test.js +++ b/packages/engine/test/Block/map.test.js @@ -1,12 +1,10 @@ /* eslint-disable dot-notation */ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/registerMethod.test.js b/packages/engine/test/Block/registerMethod.test.js index 611baa766..acdf107c4 100644 --- a/packages/engine/test/Block/registerMethod.test.js +++ b/packages/engine/test/Block/registerMethod.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/Block/validate.test.js b/packages/engine/test/Block/validate.test.js index ac12b53cb..2b7f5b79d 100644 --- a/packages/engine/test/Block/validate.test.js +++ b/packages/engine/test/Block/validate.test.js @@ -1,11 +1,9 @@ import testContext from '../testContext'; -const branch = 'master'; const pageId = 'one'; const client = { writeFragment: jest.fn() }; const rootContext = { - branch, client, }; diff --git a/packages/engine/test/BlockActions.test.js b/packages/engine/test/BlockActions.test.js index 828d11f68..b229fb998 100644 --- a/packages/engine/test/BlockActions.test.js +++ b/packages/engine/test/BlockActions.test.js @@ -2,7 +2,6 @@ import testContext from './testContext'; const pageId = 'one'; -const branch = 'master'; const mockLoadingCallback = jest.fn(); const mockLoading = jest.fn(() => mockLoadingCallback); @@ -35,7 +34,6 @@ const mockDate = jest.fn(() => ({ date: 0 })); mockDate.now = jest.fn(() => 0); const rootContext = { - branch, client, message, }; diff --git a/packages/engine/test/Mutations.test.js b/packages/engine/test/Mutations.test.js index 77efdb8aa..f92589d4c 100644 --- a/packages/engine/test/Mutations.test.js +++ b/packages/engine/test/Mutations.test.js @@ -38,7 +38,6 @@ const rootBlock = { }; const blockId = 'one'; -const branch = 'master'; const input = {}; const lowdefyGlobal = {}; const pageId = 'one'; @@ -53,7 +52,6 @@ beforeEach(() => { test('callMutation', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -78,7 +76,6 @@ test('callMutation', async () => { test('callMutation error', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -111,7 +108,6 @@ test('callMutation error', async () => { test('callMutation that is not on root block', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -140,7 +136,6 @@ test('callMutation that is not on root block', async () => { test('callMutation on root block with no mutations', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -170,7 +165,6 @@ test('update function should be called', async () => { const updateFunction = jest.fn(); const context = { blockId, - branch, client, input, lowdefyGlobal, diff --git a/packages/engine/test/Requests.test.js b/packages/engine/test/Requests.test.js index 51573500d..636ee9891 100644 --- a/packages/engine/test/Requests.test.js +++ b/packages/engine/test/Requests.test.js @@ -50,7 +50,6 @@ const rootBlock = { }; const blockId = 'one'; -const branch = 'master'; const input = {}; const lowdefyGlobal = {}; const pageId = 'one'; @@ -65,7 +64,6 @@ beforeEach(() => { test('callRequest', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -90,7 +88,6 @@ test('callRequest', async () => { test('callRequests all requests', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -148,7 +145,6 @@ test('callRequests all requests', async () => { test('callRequests', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -182,7 +178,6 @@ test('callRequests', async () => { test('callRequest error', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -215,7 +210,6 @@ test('callRequest error', async () => { test('callRequest that is not on root block', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -235,7 +229,6 @@ test('callRequest that is not on root block', async () => { test('callRequest on root block with no requests', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -255,7 +248,6 @@ test('callRequest on root block with no requests', async () => { test('callRequest request does not exist', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -282,7 +274,6 @@ test('callRequest request does not exist', async () => { test('callRequest not called the same request twice with onlyNew true', async () => { const context = { blockId, - branch, client, input, lowdefyGlobal, @@ -310,7 +301,6 @@ test('update unction should be called', async () => { const updateFunction = jest.fn(); const context = { blockId, - branch, client, input, 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 () => { const context = { blockId, - branch, client, input, lowdefyGlobal, diff --git a/packages/engine/test/makeContextId.test.js b/packages/engine/test/makeContextId.test.js index 155df34ab..b24a6ab39 100644 --- a/packages/engine/test/makeContextId.test.js +++ b/packages/engine/test/makeContextId.test.js @@ -4,38 +4,34 @@ test('makeContextId, empty urlQuery', () => { expect( makeContextId({ blockId: 'blockId', - branch: 'branch', pageId: 'pageId', search: {}, }) - ).toEqual('branch:pageId:blockId:{}'); + ).toEqual('pageId:blockId:{}'); }); test('makeContextId, search', () => { expect( makeContextId({ blockId: 'blockId', - branch: 'branch', pageId: 'pageId', urlQuery: { a: 1 }, }) - ).toEqual('branch:pageId:blockId:{"a":1}'); + ).toEqual('pageId:blockId:{"a":1}'); }); test('makeContextId, undefined urlQuery', () => { expect( makeContextId({ blockId: 'blockId', - branch: 'branch', pageId: 'pageId', }) - ).toEqual('branch:pageId:blockId:{}'); + ).toEqual('pageId:blockId:{}'); }); test('makeContextId, undefined blockId', () => { expect(() => makeContextId({ - branch: 'branch', pageId: 'pageId', search: {}, }) @@ -46,7 +42,6 @@ test('makeContextId, blockId not a string', () => { expect(() => makeContextId({ blockId: 1, - branch: 'branch', pageId: 'pageId', search: {}, }) @@ -56,7 +51,6 @@ test('makeContextId, blockId not a string', () => { test('makeContextId, undefined pageId', () => { expect(() => makeContextId({ - branch: 'branch', blockId: 'blockId', search: {}, }) @@ -67,30 +61,8 @@ test('makeContextId, pageId not a string', () => { expect(() => makeContextId({ pageId: 1, - branch: 'branch', blockId: 'blockId', search: {}, }) ).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'); -}); diff --git a/packages/engine/test/testContext.js b/packages/engine/test/testContext.js index c47226d74..6fd6e70c8 100644 --- a/packages/engine/test/testContext.js +++ b/packages/engine/test/testContext.js @@ -13,7 +13,6 @@ const testContext = ({ rootContext, rootBlock, pageId, initState, initLowdefyGlo actionLog: [], appGraphql: rootContext.appGraphql, blockId: rootBlock.blockId, - branch: 'branch', client: rootContext.client, Components: rootContext.Components || {}, config: rootContext.config || {}, diff --git a/packages/format/test/getFormatter.test.js b/packages/format/test/getFormatter.test.js index 7bad52dbc..192c7059d 100644 --- a/packages/format/test/getFormatter.test.js +++ b/packages/format/test/getFormatter.test.js @@ -16,6 +16,11 @@ import getFormatter from '../src/index'; +test('default formatter', () => { + const formatter = getFormatter(); + expect(formatter('string')).toEqual('string'); +}); + test('Invalid formatter name', () => { expect(() => { getFormatter('invalid', {}); diff --git a/packages/operators/src/nodeParser.js b/packages/operators/src/nodeParser.js index 9a06f263d..cdb50c0ad 100644 --- a/packages/operators/src/nodeParser.js +++ b/packages/operators/src/nodeParser.js @@ -67,10 +67,6 @@ function _args({ params, args, location }) { return getFromObject(params, args, '_args', location); } -function _config({ params, config, location }) { - return getFromObject(params, config, '_config', location); -} - function _global({ params, lowdefyGlobal, location }) { return getFromObject(params, lowdefyGlobal, '_global', location); } @@ -91,10 +87,6 @@ function _url_query({ params, urlQuery, location }) { return getFromObject(params, urlQuery, '_url_query', location); } -function _user({ params, user, location }) { - return getFromObject(params, user, '_user', location); -} - function _get({ params, location }) { if (!type.isObject(params)) { throw new Error( @@ -116,18 +108,16 @@ function _get({ params, location }) { } class NodeParser { - constructor({ config, input, lowdefyGlobal, secrets, state, urlQuery, user } = {}) { + constructor({ config, input, lowdefyGlobal, secrets, state, urlQuery } = {}) { this.config = config; this.input = input; this.lowdefyGlobal = lowdefyGlobal; this.secrets = secrets; this.state = state; this.urlQuery = urlQuery; - this.user = user; this.operations = { _and, _args, - _config, _date, _dump_yaml, _eq, @@ -150,7 +140,6 @@ class NodeParser { _stringify, _type, _url_query, - _user, }; this.operationList = Object.keys(this.operations); } @@ -184,7 +173,6 @@ class NodeParser { secrets: this.secrets, state: this.state, urlQuery: this.urlQuery, - user: this.user, }); return res; } diff --git a/packages/operators/src/operators.js b/packages/operators/src/operators.js index 9595267bb..e0967fa9a 100644 --- a/packages/operators/src/operators.js +++ b/packages/operators/src/operators.js @@ -387,9 +387,6 @@ function _dump_yaml({ params }) { function _operator(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)) { throw new Error( `Operator Error: _operator.name must be a valid operator name as string. Received: ${JSON.stringify( @@ -404,6 +401,9 @@ function _operator(options) { )} at ${location}.` ); } + if (Object.prototype.hasOwnProperty.call(operations, params.name)) { + return operations[params.name]({ ...options, location, params: params && params.params }); + } throw new Error( `Operator Error: _operator - Invalid operator name. Received: ${JSON.stringify( params diff --git a/packages/operators/src/webParser.js b/packages/operators/src/webParser.js index 3fb64eb21..e4055ded7 100644 --- a/packages/operators/src/webParser.js +++ b/packages/operators/src/webParser.js @@ -114,10 +114,6 @@ function _args({ args, arrayIndices, location, params }) { 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 }) { 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); } -function _user({ params, user, arrayIndices, location }) { - return getFromObject(params, user, arrayIndices, '_user', location); -} - function _action_log({ params, actionLog, context, contexts, arrayIndices, location }) { if (params && params.contextId) { return getFromOtherContext({ @@ -302,14 +294,13 @@ function _list_contexts({ contexts }) { } class WebParser { - constructor({ context, contexts } = {}) { + constructor({ context, contexts }) { this.context = context; this.contexts = contexts; this.operations = { _action_log, _and, _args, - _config, _date, _dump_yaml, _eq, @@ -337,7 +328,6 @@ class WebParser { _stringify, _type, _url_query, - _user, }; this.operationList = Object.keys(this.operations); } @@ -376,7 +366,6 @@ class WebParser { params: value[op], state: this.context.state, urlQuery: this.context.urlQuery, - user: this.context.user, }); return res; } diff --git a/packages/operators/test/node/config.test.js b/packages/operators/test/node/config.test.js deleted file mode 100644 index b433b798f..000000000 --- a/packages/operators/test/node/config.test.js +++ /dev/null @@ -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 []`); -}); diff --git a/packages/operators/test/node/date.test.js b/packages/operators/test/node/date.test.js index 2e5df0d25..f27ca00a9 100644 --- a/packages/operators/test/node/date.test.js +++ b/packages/operators/test/node/date.test.js @@ -5,7 +5,6 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_date now', () => { @@ -18,7 +17,7 @@ test('_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' }); expect(res.output).toEqual(constantDate); global.Date = RealDate; @@ -27,7 +26,7 @@ test('_date now', () => { test('_date from string', () => { 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' }); expect(res.output).toEqual(new Date('2018-01-01T12:00:00.000Z')); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -35,7 +34,7 @@ test('_date from string', () => { test('_date short format', () => { 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' }); expect(res.output).toEqual(new Date('2018-01-01')); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -43,7 +42,7 @@ test('_date short format', () => { test('_date from unix timestamp', () => { const input = { _date: 1569579992 }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(new Date(1569579992)); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -51,7 +50,7 @@ test('_date from unix timestamp', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -63,7 +62,7 @@ test('_date null', () => { test('_date invalid operator', () => { const input = { _date: {} }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -75,7 +74,7 @@ test('_date invalid operator', () => { test('_date invalid string', () => { const input = { _date: 'abc' }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -87,7 +86,7 @@ test('_date invalid string', () => { test('_date invalid float', () => { const input = { _date: 1.3 }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -99,7 +98,7 @@ test('_date invalid float', () => { test('_date negative int', () => { const input = { _date: -1000 }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(new Date(-1000)); expect(res.errors).toMatchInlineSnapshot(`Array []`); diff --git a/packages/operators/test/node/global.test.js b/packages/operators/test/node/global.test.js index 9c4295ceb..b886a0f54 100644 --- a/packages/operators/test/node/global.test.js +++ b/packages/operators/test/node/global.test.js @@ -6,12 +6,11 @@ const lowdefyGlobal = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_global in object', () => { const input = { a: { _global: 'string' } }; - const parser = new NodeParser({ lowdefyGlobal, user }); + const parser = new NodeParser({ lowdefyGlobal }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual({ a: 'Some String', @@ -21,7 +20,7 @@ test('_global in object', () => { test('_global full lowdefyGlobal', () => { const input = { _global: true }; - const parser = new NodeParser({ lowdefyGlobal, user }); + const parser = new NodeParser({ lowdefyGlobal }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(lowdefyGlobal); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -29,7 +28,7 @@ test('_global full lowdefyGlobal', () => { test('_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' }); expect(res.output).toBe(null); 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', () => { const input = { _global: { @@ -61,7 +46,6 @@ test('_global param object key', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('Some String'); @@ -76,7 +60,6 @@ test('_global param object all', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(lowdefyGlobal); @@ -92,7 +75,6 @@ test('_global param object all and key', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(lowdefyGlobal); @@ -107,7 +89,6 @@ test('_global param object invalid', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -124,7 +105,6 @@ test('_global param array', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -144,7 +124,6 @@ test('_global param object with string default', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('defaultValue'); @@ -160,7 +139,6 @@ test('_global param object with zero default', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(0); @@ -176,7 +154,6 @@ test('_global param object with false default', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(false); @@ -191,7 +168,6 @@ test('_global param object with no default', () => { }; const parser = new NodeParser({ lowdefyGlobal, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); diff --git a/packages/operators/test/node/input.test.js b/packages/operators/test/node/input.test.js index ff5c21b08..bfde009fe 100644 --- a/packages/operators/test/node/input.test.js +++ b/packages/operators/test/node/input.test.js @@ -6,7 +6,6 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const input = { string: 'input String', number: 500, @@ -15,7 +14,7 @@ const input = { test('_input in object', () => { 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' }); expect(res.output).toEqual({ a: 'input String', @@ -25,7 +24,7 @@ test('_input in object', () => { test('_input full input', () => { 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' }); expect(res.output).toEqual(input); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -33,7 +32,7 @@ test('_input full input', () => { test('_input array', () => { 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' }); expect(res.output).toEqual(input.arr); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -41,7 +40,7 @@ test('_input array', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -57,7 +56,7 @@ test('_input param object key', () => { key: 'string', }, }; - const parser = new NodeParser({ state, user, input }); + const parser = new NodeParser({ state, input }); const res = parser.parse({ input: obj, location: 'locationId' }); expect(res.output).toEqual('input String'); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -69,7 +68,7 @@ test('_input param object all', () => { all: true, }, }; - const parser = new NodeParser({ state, user, input }); + const parser = new NodeParser({ state, input }); const res = parser.parse({ input: obj, location: 'locationId' }); expect(res.output).toEqual(input); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -82,7 +81,7 @@ test('_input param object all and key', () => { key: 'string', }, }; - const parser = new NodeParser({ state, user, input }); + const parser = new NodeParser({ state, input }); const res = parser.parse({ input: obj, location: 'locationId' }); expect(res.output).toEqual(input); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -94,7 +93,7 @@ test('_input param object invalid', () => { other: true, }, }; - const parser = new NodeParser({ state, user, input }); + const parser = new NodeParser({ state, input }); const res = parser.parse({ input: obj, location: 'locationId' }); expect(res.output).toEqual(null); expect(res.errors).toMatchInlineSnapshot(` @@ -108,7 +107,7 @@ test('_input param array', () => { const obj = { _state: ['string'], }; - const parser = new NodeParser({ state, user, input }); + const parser = new NodeParser({ state, input }); const res = parser.parse({ input: obj, location: 'locationId' }); expect(res.output).toEqual(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/mql_aggregate.test.js b/packages/operators/test/node/mql_aggregate.test.js index ba7ee390f..c96124965 100644 --- a/packages/operators/test/node/mql_aggregate.test.js +++ b/packages/operators/test/node/mql_aggregate.test.js @@ -6,7 +6,6 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; 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' }); 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' }); 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' }); 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' }); expect(res.output).toEqual([ { @@ -139,7 +138,7 @@ test('_mql_aggregate empty collection', () => { on: [], }, }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual([]); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -158,7 +157,7 @@ test('_mql_aggregate on is string', () => { on: 'invalid', }, }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(null); 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' }); expect(res.output).toBe(null); 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' }); expect(res.output).toBe(null); 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/mql_expr.test.js b/packages/operators/test/node/mql_expr.test.js index a0cbc4088..7aeabd4bd 100644 --- a/packages/operators/test/node/mql_expr.test.js +++ b/packages/operators/test/node/mql_expr.test.js @@ -5,12 +5,12 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name', number: 2 }; + const args = {}; test('_mql_expr add number', () => { 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' }); expect(res.output).toBe(44); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -18,7 +18,7 @@ test('_mql_expr add number', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -32,10 +32,12 @@ test('_mql_expr params on', () => { const input = { _mql_expr: { 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' }); expect(res.output).toBe(4); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -43,7 +45,7 @@ test('_mql_expr params on', () => { test('_mql_expr invalid', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/mql_test.test.js b/packages/operators/test/node/mql_test.test.js index 1ea4d495b..463db5830 100644 --- a/packages/operators/test/node/mql_test.test.js +++ b/packages/operators/test/node/mql_test.test.js @@ -5,12 +5,11 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_mql_test string equal', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -18,7 +17,7 @@ test('_mql_test string equal', () => { test('_mql_test string equal shorthand', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -26,7 +25,7 @@ test('_mql_test string equal shorthand', () => { test('_mql_test string not equal', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -34,7 +33,7 @@ test('_mql_test string not equal', () => { test('_mql_test number equal', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -42,7 +41,7 @@ test('_mql_test number equal', () => { test('_mql_test number not equal', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -50,7 +49,7 @@ test('_mql_test number not equal', () => { test('_mql_test number greater than', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -58,7 +57,7 @@ test('_mql_test number greater than', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -71,11 +70,11 @@ test('_mql_test null', () => { test('_mql_test object params', () => { const input = { _mql_test: { - test: { firstName: 'Name' }, - on: { _user: true }, + test: { value: 'test' }, + on: { value: 'test' }, }, }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -84,11 +83,10 @@ test('_mql_test object params', () => { test('_mql_test invalid params', () => { const input = { _mql_test: { - other: { firstName: 'Name' }, - on: { _user: true }, + test: { value: 'test' }, }, }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -96,7 +94,7 @@ test('_mql_test invalid params', () => { test('_mql_test invalid test', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/nunjucks.test.js b/packages/operators/test/node/nunjucks.test.js index 6621ee675..d56982053 100644 --- a/packages/operators/test/node/nunjucks.test.js +++ b/packages/operators/test/node/nunjucks.test.js @@ -5,12 +5,11 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_nunjucks string template', () => { 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' }); expect(res.output).toEqual('String with Some String embedded'); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -18,7 +17,7 @@ test('_nunjucks string template', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -28,7 +27,7 @@ test('_nunjucks { template: , on: }', () => { const input = { _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' }); expect(res.output).toEqual('String with test embedded'); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -36,7 +35,7 @@ test('_nunjucks { template: , on: }', () => { test('_nunjucks template not a string', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -46,7 +45,7 @@ test('_nunjucks params on template not a string', () => { const input = { _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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -56,7 +55,7 @@ test('_nunjucks on not a object', () => { const input = { _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' }); expect(res.output).toBe('String with embedded'); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -66,7 +65,7 @@ test('_nunjucks on null', () => { const input = { _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' }); expect(res.output).toBe('String with embedded'); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -74,7 +73,7 @@ test('_nunjucks on null', () => { test('_nunjucks invalid template', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/operator.test.js b/packages/operators/test/node/operator.test.js index b9e1e7493..8368b60e3 100644 --- a/packages/operators/test/node/operator.test.js +++ b/packages/operators/test/node/operator.test.js @@ -5,12 +5,21 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; 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', () => { 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' }); expect(res.output).toEqual({ a: null }); expect(res.errors).toMatchInlineSnapshot(` @@ -22,7 +31,7 @@ test('_operator.name invalid', () => { test('_operator.name not a string', () => { 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' }); expect(res.output).toEqual({ a: null }); expect(res.errors).toMatchInlineSnapshot(` @@ -34,7 +43,7 @@ test('_operator.name not a string', () => { test('_operator with value not a object', () => { const input = { a: { _operator: 'a' } }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual({ a: null }); expect(res.errors).toMatchInlineSnapshot(` @@ -46,19 +55,19 @@ test('_operator with value not a object', () => { test('_operator cannot be set to _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' }); expect(res.output).toEqual({ a: null }); expect(res.errors).toMatchInlineSnapshot(` 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', () => { 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' }); expect(res.output).toEqual({ a: true }); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -66,7 +75,7 @@ test('_operator, _not with no params', () => { test('_operator, _parse with params', () => { 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' }); expect(res.output).toEqual({ a: [{ a: 'a1' }], diff --git a/packages/operators/test/node/regex.test.js b/packages/operators/test/node/regex.test.js index 59e2a1590..c74cc351b 100644 --- a/packages/operators/test/node/regex.test.js +++ b/packages/operators/test/node/regex.test.js @@ -5,12 +5,11 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name', number: 2 }; const args = {}; test('_regex with on, pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -18,7 +17,7 @@ test('_regex with on, pass', () => { test('_regex with on, fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -26,7 +25,7 @@ test('_regex with on, fail', () => { test('_regex with key, pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -34,7 +33,7 @@ test('_regex with key, pass', () => { test('_regex with key, fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -42,7 +41,7 @@ test('_regex with key, fail', () => { test('_regex with null on', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -50,7 +49,7 @@ test('_regex with null on', () => { test('_regex with nonexistent key', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -62,7 +61,7 @@ test('_regex with nonexistent key', () => { test('_regex with nonexistent key', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -74,7 +73,7 @@ test('_regex with nonexistent key', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -86,7 +85,7 @@ test('_regex null', () => { test('_regex with non-string on', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -98,7 +97,7 @@ test('_regex with non-string on', () => { test('_regex flags', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -106,7 +105,7 @@ test('_regex flags', () => { test('_regex invalid flags', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` diff --git a/packages/operators/test/node/secret.test.js b/packages/operators/test/node/secret.test.js index e81b4c891..e0ba28466 100644 --- a/packages/operators/test/node/secret.test.js +++ b/packages/operators/test/node/secret.test.js @@ -6,12 +6,11 @@ const secrets = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_secret in object', () => { const input = { a: { _secret: 'string' } }; - const parser = new NodeParser({ secrets, user }); + const parser = new NodeParser({ secrets }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual({ a: 'Some String', @@ -21,7 +20,7 @@ test('_secret in object', () => { test('_secret full secrets', () => { const input = { _secret: true }; - const parser = new NodeParser({ secrets, user }); + const parser = new NodeParser({ secrets }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(secrets); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -29,7 +28,7 @@ test('_secret full secrets', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -47,7 +46,6 @@ test('_secret param object key', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('Some String'); @@ -62,7 +60,6 @@ test('_secret param object all', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(secrets); @@ -78,7 +75,6 @@ test('_secret param object all and key', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(secrets); @@ -93,7 +89,6 @@ test('_secret param object invalid', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -110,7 +105,6 @@ test('_secret param array', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -130,7 +124,6 @@ test('_secret param object with string default', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('defaultValue'); @@ -146,7 +139,6 @@ test('_secret param object with zero default', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(0); @@ -162,7 +154,6 @@ test('_secret param object with false default', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(false); @@ -177,7 +168,6 @@ test('_secret param object with no default', () => { }; const parser = new NodeParser({ secrets, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); diff --git a/packages/operators/test/node/state.test.js b/packages/operators/test/node/state.test.js index 31ed570b4..d891458c6 100644 --- a/packages/operators/test/node/state.test.js +++ b/packages/operators/test/node/state.test.js @@ -6,12 +6,11 @@ const state = { number: 42, arr: [{ a: 'a1' }, { a: 'a2' }], }; -const user = { firstName: 'Name' }; const args = {}; test('_state in object', () => { const input = { a: { _state: 'string' } }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual({ a: 'Some String', @@ -21,7 +20,7 @@ test('_state in object', () => { test('_state full state', () => { const input = { _state: true }; - const parser = new NodeParser({ state, user }); + const parser = new NodeParser({ state }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(state); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -29,7 +28,7 @@ test('_state full state', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -47,7 +46,6 @@ test('_state param object key', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('Some String'); @@ -62,7 +60,6 @@ test('_state param object all', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(state); @@ -78,7 +75,6 @@ test('_state param object all and key', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(state); @@ -93,7 +89,6 @@ test('_state param object invalid', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -110,7 +105,6 @@ test('_state param array', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); @@ -130,7 +124,6 @@ test('_state param object with string default', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual('defaultValue'); @@ -146,7 +139,6 @@ test('_state param object with zero default', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(0); @@ -162,7 +154,6 @@ test('_state param object with false default', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(false); @@ -177,7 +168,6 @@ test('_state param object with no default', () => { }; const parser = new NodeParser({ state, - user, }); const res = parser.parse({ input, args, location: 'locationId' }); expect(res.output).toEqual(null); diff --git a/packages/operators/test/node/type.test.js b/packages/operators/test/node/type.test.js index 0bb1bf279..43ffc574d 100644 --- a/packages/operators/test/node/type.test.js +++ b/packages/operators/test/node/type.test.js @@ -6,12 +6,11 @@ const state = { arr: [{ a: 'a1' }, { a: 'a2' }], boolean: true, }; -const user = { firstName: 'Name', number: 2 }; const args = {}; test('_type with on, pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -19,7 +18,7 @@ test('_type with on, pass', () => { test('_type with on, fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -27,7 +26,7 @@ test('_type with on, fail', () => { test('_type with key, pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -35,7 +34,7 @@ test('_type with key, pass', () => { test('_type with key, fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -43,14 +42,14 @@ test('_type with key, fail', () => { test('_type with null on pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); }); test('_type with null on fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -58,7 +57,7 @@ test('_type with null on fail', () => { test('_type with nonexistent key', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -66,7 +65,7 @@ test('_type with nonexistent key', () => { test('_type with nonexistent key', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -74,7 +73,7 @@ test('_type with nonexistent key', () => { test('_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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -86,7 +85,7 @@ test('_type null', () => { test('_type with non-string on', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -94,7 +93,7 @@ test('_type with non-string on', () => { test('_type with unknown type', () => { 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' }); expect(res.output).toBe(null); expect(res.errors).toMatchInlineSnapshot(` @@ -106,7 +105,7 @@ test('_type with unknown type', () => { test('_type date with on packed date pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -114,7 +113,7 @@ test('_type date with on packed date pass', () => { test('_type date on string date fail', () => { 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' }); expect(res.output).toBe(false); expect(res.errors).toMatchInlineSnapshot(`Array []`); @@ -122,7 +121,7 @@ test('_type date on string date fail', () => { test('_type date on date object pass', () => { 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' }); expect(res.output).toBe(true); expect(res.errors).toMatchInlineSnapshot(`Array []`); diff --git a/packages/operators/test/node/user.test.js b/packages/operators/test/node/user.test.js deleted file mode 100644 index dafa308b8..000000000 --- a/packages/operators/test/node/user.test.js +++ /dev/null @@ -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 []`); -}); diff --git a/packages/operators/test/web/WebParser.test.js b/packages/operators/test/web/WebParser.test.js index fb331692d..f7682f0d3 100644 --- a/packages/operators/test/web/WebParser.test.js +++ b/packages/operators/test/web/WebParser.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; @@ -161,3 +157,11 @@ test('parse js dates, do not modify input', () => { expect(input).toEqual({ a: new Date(1) }); 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 []`); +}); diff --git a/packages/operators/test/web/action_log.test.js b/packages/operators/test/web/action_log.test.js index c50da52a3..b2f6d0090 100644 --- a/packages/operators/test/web/action_log.test.js +++ b/packages/operators/test/web/action_log.test.js @@ -64,10 +64,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/args.test.js b/packages/operators/test/web/args.test.js index e73fbfe63..4ba2e3830 100644 --- a/packages/operators/test/web/args.test.js +++ b/packages/operators/test/web/args.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/config.test.js b/packages/operators/test/web/config.test.js deleted file mode 100644 index 763383fa6..000000000 --- a/packages/operators/test/web/config.test.js +++ /dev/null @@ -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 []`); -}); diff --git a/packages/operators/test/web/date.test.js b/packages/operators/test/web/date.test.js index 2171c8a06..37b398ed8 100644 --- a/packages/operators/test/web/date.test.js +++ b/packages/operators/test/web/date.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/dump_yaml.test.js b/packages/operators/test/web/dump_yaml.test.js index 119615893..448d62e8b 100644 --- a/packages/operators/test/web/dump_yaml.test.js +++ b/packages/operators/test/web/dump_yaml.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/get.test.js b/packages/operators/test/web/get.test.js index 3417e3768..65252a1bd 100644 --- a/packages/operators/test/web/get.test.js +++ b/packages/operators/test/web/get.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/getFromContext/action_log.test.js b/packages/operators/test/web/getFromContext/action_log.test.js index 0e5ea495f..a9d9070c1 100644 --- a/packages/operators/test/web/getFromContext/action_log.test.js +++ b/packages/operators/test/web/getFromContext/action_log.test.js @@ -66,10 +66,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -133,10 +129,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/getFromContext/input.test.js b/packages/operators/test/web/getFromContext/input.test.js index 3a680901d..16aa5f1f6 100644 --- a/packages/operators/test/web/getFromContext/input.test.js +++ b/packages/operators/test/web/getFromContext/input.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -103,10 +99,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/getFromContext/mutation_details.test.js b/packages/operators/test/web/getFromContext/mutation_details.test.js index efd713ccd..abfe67be6 100644 --- a/packages/operators/test/web/getFromContext/mutation_details.test.js +++ b/packages/operators/test/web/getFromContext/mutation_details.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -103,10 +99,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/getFromContext/request_details.test.js b/packages/operators/test/web/getFromContext/request_details.test.js index 98f7016c6..70a46719c 100644 --- a/packages/operators/test/web/getFromContext/request_details.test.js +++ b/packages/operators/test/web/getFromContext/request_details.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -103,10 +99,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/getFromContext/state.test.js b/packages/operators/test/web/getFromContext/state.test.js index d20af90c8..7c3ef7e33 100644 --- a/packages/operators/test/web/getFromContext/state.test.js +++ b/packages/operators/test/web/getFromContext/state.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -103,10 +99,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/getFromContext/url_query.test.js b/packages/operators/test/web/getFromContext/url_query.test.js index 93b56cc13..11c32cc66 100644 --- a/packages/operators/test/web/getFromContext/url_query.test.js +++ b/packages/operators/test/web/getFromContext/url_query.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; @@ -103,10 +99,6 @@ const otherContext = { string: 'urlQuery-other', arr: [{ a: 'urlQuery1-other' }, { a: 'urlQuery2-other' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, updateListeners: new Set(), }; diff --git a/packages/operators/test/web/global.test.js b/packages/operators/test/web/global.test.js index 5b2816050..849753fc0 100644 --- a/packages/operators/test/web/global.test.js +++ b/packages/operators/test/web/global.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/input.test.js b/packages/operators/test/web/input.test.js index 1f05c2953..25bac45ab 100644 --- a/packages/operators/test/web/input.test.js +++ b/packages/operators/test/web/input.test.js @@ -45,10 +45,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/list_contexts.test.js b/packages/operators/test/web/list_contexts.test.js index e4a6f6815..472ecba4f 100644 --- a/packages/operators/test/web/list_contexts.test.js +++ b/packages/operators/test/web/list_contexts.test.js @@ -46,10 +46,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = { diff --git a/packages/operators/test/web/load_yaml.test.js b/packages/operators/test/web/load_yaml.test.js index ef04867c8..026bdf667 100644 --- a/packages/operators/test/web/load_yaml.test.js +++ b/packages/operators/test/web/load_yaml.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/logic.test.js b/packages/operators/test/web/logic.test.js index 043767e63..1ba8cef95 100644 --- a/packages/operators/test/web/logic.test.js +++ b/packages/operators/test/web/logic.test.js @@ -44,10 +44,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/menu.test.js b/packages/operators/test/web/menu.test.js index a0f3e7c55..fc405b3c3 100644 --- a/packages/operators/test/web/menu.test.js +++ b/packages/operators/test/web/menu.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/mql_aggregate.test.js b/packages/operators/test/web/mql_aggregate.test.js index d17f9bbe0..ab5310079 100644 --- a/packages/operators/test/web/mql_aggregate.test.js +++ b/packages/operators/test/web/mql_aggregate.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/mql_expr.test.js b/packages/operators/test/web/mql_expr.test.js index 54d661b1a..b1afb51c7 100644 --- a/packages/operators/test/web/mql_expr.test.js +++ b/packages/operators/test/web/mql_expr.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/mql_test.test.js b/packages/operators/test/web/mql_test.test.js index 1ccf457f0..6b46456eb 100644 --- a/packages/operators/test/web/mql_test.test.js +++ b/packages/operators/test/web/mql_test.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; @@ -123,8 +119,8 @@ test('_mql_test null', () => { test('_mql_test object params', () => { const input = { _mql_test: { - test: { string: 'user' }, - on: { _user: true }, + test: { test: 'value' }, + on: { test: 'value' }, }, }; const parser = new WebParser({ context, contexts }); @@ -136,8 +132,7 @@ test('_mql_test object params', () => { test('_mql_test invalid params', () => { const input = { _mql_test: { - other: { string: 'user' }, - on: { _user: true }, + other: { test: 'value' }, }, }; const parser = new WebParser({ context, contexts }); diff --git a/packages/operators/test/web/mutation.test.js b/packages/operators/test/web/mutation.test.js index b5f80ef30..a3cf36bd2 100644 --- a/packages/operators/test/web/mutation.test.js +++ b/packages/operators/test/web/mutation.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/mutation_details.test.js b/packages/operators/test/web/mutation_details.test.js index b09de0e54..8e5574e65 100644 --- a/packages/operators/test/web/mutation_details.test.js +++ b/packages/operators/test/web/mutation_details.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/nunjucks.test.js b/packages/operators/test/web/nunjucks.test.js index 45c6c1666..2a69f1b1f 100644 --- a/packages/operators/test/web/nunjucks.test.js +++ b/packages/operators/test/web/nunjucks.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/operator.test.js b/packages/operators/test/web/operator.test.js index 0f339f074..5d90c522b 100644 --- a/packages/operators/test/web/operator.test.js +++ b/packages/operators/test/web/operator.test.js @@ -49,16 +49,22 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; 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', () => { const input = { a: { _operator: { name: '_a' } } }; 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.errors).toMatchInlineSnapshot(` 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.], ] `); }); diff --git a/packages/operators/test/web/parse.test.js b/packages/operators/test/web/parse.test.js index 30ac80aeb..86dea9320 100644 --- a/packages/operators/test/web/parse.test.js +++ b/packages/operators/test/web/parse.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/regex.test.js b/packages/operators/test/web/regex.test.js index 6e3ae2384..bccf241d3 100644 --- a/packages/operators/test/web/regex.test.js +++ b/packages/operators/test/web/regex.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/request.test.js b/packages/operators/test/web/request.test.js index 8c4325320..491f3e2a8 100644 --- a/packages/operators/test/web/request.test.js +++ b/packages/operators/test/web/request.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/request_details.test.js b/packages/operators/test/web/request_details.test.js index 0f64ff065..ee7dc8d44 100644 --- a/packages/operators/test/web/request_details.test.js +++ b/packages/operators/test/web/request_details.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/state.test.js b/packages/operators/test/web/state.test.js index 28ed65fa3..7e7ccfc2d 100644 --- a/packages/operators/test/web/state.test.js +++ b/packages/operators/test/web/state.test.js @@ -50,10 +50,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/stringify.test.js b/packages/operators/test/web/stringify.test.js index 12d24f01f..097f994f1 100644 --- a/packages/operators/test/web/stringify.test.js +++ b/packages/operators/test/web/stringify.test.js @@ -55,10 +55,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/type.test.js b/packages/operators/test/web/type.test.js index 05553dca0..56d54d256 100644 --- a/packages/operators/test/web/type.test.js +++ b/packages/operators/test/web/type.test.js @@ -51,10 +51,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/url_query.test.js b/packages/operators/test/web/url_query.test.js index e46bb8c76..19d2db31c 100644 --- a/packages/operators/test/web/url_query.test.js +++ b/packages/operators/test/web/url_query.test.js @@ -49,10 +49,6 @@ const context = { string: 'urlQuery', arr: [{ a: 'urlQuery1' }, { a: 'urlQuery2' }], }, - user: { - string: 'user', - arr: [{ a: 'user1' }, { a: 'user2' }], - }, }; const contexts = {}; diff --git a/packages/operators/test/web/user.test.js b/packages/operators/test/web/user.test.js deleted file mode 100644 index eb60f680f..000000000 --- a/packages/operators/test/web/user.test.js +++ /dev/null @@ -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 []`); -});