How to use parsedQuery method in Best

Best JavaScript code snippet using best

preprocessor-ts.test.ts

Source:preprocessor-ts.test.ts Github

copy

Full Screen

1import { parseTSQuery } from './loader/typescript';2import { ParamTransform } from './preprocessor';3import { processTSQueryAST } from './preprocessor-ts';4test('(TS) name parameter interpolation', () => {5 const query = 'SELECT id, name from users where id = $id and age > $age';6 const parsedQuery = parseTSQuery(query);7 const parameters = {8 id: '123',9 age: 12,10 };11 const expectedResult = {12 query: 'SELECT id, name from users where id = $1 and age > $2',13 mapping: [],14 bindings: ['123', 12],15 };16 const result = processTSQueryAST(parsedQuery.query, parameters);17 expect(result).toEqual(expectedResult);18});19test('(TS) pick parameter interpolation (multiline)', () => {20 const query = `21 INSERT INTO notifications (payload, user_id, type)22 VALUES $notification(payload, user_id, type)23 `;24 const parsedQuery = parseTSQuery(query);25 const parameters = {26 notification: {27 user_id: 1,28 payload: { num_frogs: 1002 },29 type: 'reminder',30 },31 };32 const expectedResult = {33 query: `34 INSERT INTO notifications (payload, user_id, type)35 VALUES ($1, $2, $3)`,36 mapping: [],37 bindings: [{ num_frogs: 1002 }, 1, 'reminder'],38 };39 const result = processTSQueryAST(parsedQuery.query, parameters as any);40 expect(result).toEqual(expectedResult);41});42test('(TS) pick array parameter interpolation (multiline)', () => {43 const query = `44 INSERT INTO notifications (payload, user_id, type)45 VALUES $$params(payload, user_id, type)46 `;47 const parsedQuery = parseTSQuery(query);48 const parameters = {49 params: [50 {51 user_id: 1,52 payload: { num_frogs: 1002 },53 type: 'reminder',54 },55 ],56 };57 const expectedResult = {58 query: `59 INSERT INTO notifications (payload, user_id, type)60 VALUES ($1, $2, $3)`,61 mapping: [],62 bindings: [{ num_frogs: 1002 }, 1, 'reminder'],63 };64 const result = processTSQueryAST(parsedQuery.query, parameters as any);65 expect(result).toEqual(expectedResult);66});67test('(TS) scalar param used twice', () => {68 const query = 'SELECT id, name from users where id = $id and parent_id = $id';69 const parsedQuery = parseTSQuery(query);70 const parameters = {71 id: '123',72 };73 const expectedResult = {74 query: 'SELECT id, name from users where id = $1 and parent_id = $1',75 mapping: [],76 bindings: ['123'],77 };78 const result = processTSQueryAST(parsedQuery.query, parameters);79 expect(result).toEqual(expectedResult);80});81test('(TS) name parameter mapping', () => {82 const query =83 'SELECT id, name from users where id = $id and age > $age and parent_id = $id';84 const parsedQuery = parseTSQuery(query);85 const expectedResult = {86 query:87 'SELECT id, name from users where id = $1 and age > $2 and parent_id = $1',88 mapping: [],89 bindings: ['1234-1235', 33],90 };91 const result = processTSQueryAST(parsedQuery.query, {92 id: '1234-1235',93 age: 33,94 });95 expect(result).toEqual(expectedResult);96});97test('(TS) single value list parameter interpolation', () => {98 const query =99 'INSERT INTO users (name, age) VALUES $user(name, age) RETURNING id';100 const parsedQuery = parseTSQuery(query);101 const expectedResult = {102 query: 'INSERT INTO users (name, age) VALUES ($1, $2) RETURNING id',103 mapping: [104 {105 name: 'user',106 type: ParamTransform.Pick,107 dict: {108 name: {109 assignedIndex: 1,110 name: 'name',111 type: ParamTransform.Scalar,112 required: false,113 },114 age: {115 assignedIndex: 2,116 name: 'age',117 type: ParamTransform.Scalar,118 required: false,119 },120 },121 },122 ],123 bindings: [],124 };125 const result = processTSQueryAST(parsedQuery.query);126 expect(result).toEqual(expectedResult);127});128test('(TS) single value list parameter interpolation twice', () => {129 const query =130 'INSERT INTO users (name, age) VALUES $user(name, age) BOGUS $user(name, id) RETURNING id';131 const parsedQuery = parseTSQuery(query);132 const parameters = {133 user: {134 id: '1234-123-1233',135 name: 'Bob',136 age: 12,137 },138 };139 const expectedResult = {140 query:141 'INSERT INTO users (name, age) VALUES ($1, $2) BOGUS ($1, $3) RETURNING id',142 mapping: [],143 bindings: ['Bob', 12, '1234-123-1233'],144 };145 const result = processTSQueryAST(parsedQuery.query, parameters);146 expect(result).toEqual(expectedResult);147});148test('(TS) multiple value list (array) parameter mapping', () => {149 const query =150 'SELECT FROM users where (age in $$ages and age in $$ages) or (age in $$otherAges)';151 const parsedQuery = parseTSQuery(query);152 const expectedResult = {153 query:154 'SELECT FROM users where (age in ($1) and age in ($1)) or (age in ($2))',155 mapping: [156 {157 name: 'ages',158 type: ParamTransform.Spread,159 required: false,160 assignedIndex: [1],161 },162 {163 name: 'otherAges',164 type: ParamTransform.Spread,165 required: false,166 assignedIndex: [2],167 },168 ],169 bindings: [],170 };171 const result = processTSQueryAST(parsedQuery.query);172 expect(result).toEqual(expectedResult);173});174test('(TS) multiple value list (array) parameter interpolation', () => {175 const query = 'SELECT FROM users where age in $$ages or parent_age in $$ages';176 const parsedQuery = parseTSQuery(query);177 const parameters = {178 ages: [23, 27, 50],179 };180 const expectedResult = {181 query:182 'SELECT FROM users where age in ($1, $2, $3) or parent_age in ($1, $2, $3)',183 bindings: [23, 27, 50],184 mapping: [],185 };186 const result = processTSQueryAST(parsedQuery.query, parameters);187 expect(result).toEqual(expectedResult);188});189test('(TS) multiple value list parameter mapping', () => {190 const query =191 'INSERT INTO users (name, age) VALUES $$users(name, age) RETURNING id';192 const parsedQuery = parseTSQuery(query);193 const expectedResult = {194 query: 'INSERT INTO users (name, age) VALUES ($1, $2) RETURNING id',195 bindings: [],196 mapping: [197 {198 name: 'users',199 type: ParamTransform.PickSpread,200 dict: {201 name: {202 name: 'name',203 type: ParamTransform.Scalar,204 required: false,205 assignedIndex: 1,206 },207 age: {208 name: 'age',209 type: ParamTransform.Scalar,210 required: false,211 assignedIndex: 2,212 },213 },214 },215 ],216 };217 const result = processTSQueryAST(parsedQuery.query);218 expect(result).toEqual(expectedResult);219});220test('(TS) multiple value list parameter mapping twice', () => {221 const query =222 'INSERT INTO users (name, age) VALUES $$users(name, age), $$users(name) RETURNING id';223 const parsedQuery = parseTSQuery(query);224 const expectedResult = {225 query: 'INSERT INTO users (name, age) VALUES ($1, $2), ($1) RETURNING id',226 bindings: [],227 mapping: [228 {229 name: 'users',230 type: ParamTransform.PickSpread,231 dict: {232 name: {233 name: 'name',234 type: ParamTransform.Scalar,235 required: false,236 assignedIndex: 1,237 },238 age: {239 name: 'age',240 type: ParamTransform.Scalar,241 required: false,242 assignedIndex: 2,243 },244 },245 },246 ],247 };248 const result = processTSQueryAST(parsedQuery.query);249 expect(result).toEqual(expectedResult);250});251test('(TS) multiple value list parameter interpolation', () => {252 const query =253 'INSERT INTO users (name, age) VALUES $$users(name, age) RETURNING id';254 const parsedQuery = parseTSQuery(query);255 const parameters = {256 users: [257 { name: 'Bob', age: 12 },258 { name: 'Tom', age: 22 },259 ],260 };261 const expectedResult = {262 query:263 'INSERT INTO users (name, age) VALUES ($1, $2), ($3, $4) RETURNING id',264 bindings: ['Bob', 12, 'Tom', 22],265 mapping: [],266 };267 const result = processTSQueryAST(parsedQuery.query, parameters);268 expect(result).toEqual(expectedResult);269});270test('(TS) multiple value list parameter interpolation twice', () => {271 const query =272 'INSERT INTO users (name, age) VALUES $$users(name, age), $$users(name, age) RETURNING id';273 const parsedQuery = parseTSQuery(query);274 const parameters = {275 users: [276 { name: 'Bob', age: 12 },277 { name: 'Tom', age: 22 },278 ],279 };280 const expectedResult = {281 query:282 'INSERT INTO users (name, age) VALUES ($1, $2), ($3, $4), ($5, $6), ($7, $8) RETURNING id',283 bindings: ['Bob', 12, 'Tom', 22, 'Bob', 12, 'Tom', 22],284 mapping: [],285 };286 const result = processTSQueryAST(parsedQuery.query, parameters);287 expect(result).toEqual(expectedResult);288});289test('(TS) query with no params', () => {290 const query = `UPDATE notifications SET payload = '{"a": "b"}'::jsonb`;291 const parsedQuery = parseTSQuery(query);292 const expectedResult = {293 query: `UPDATE notifications SET payload = '{"a": "b"}'::jsonb`,294 bindings: [],295 mapping: [],296 };297 const result = processTSQueryAST(parsedQuery.query);298 expect(result).toEqual(expectedResult);299});300test('(TS) query with empty spread params', () => {301 const query = `SELECT * FROM users WHERE id IN $$ids`;302 const parsedQuery = parseTSQuery(query);303 const expectedResult = {304 query: `SELECT * FROM users WHERE id IN ()`,305 bindings: [],306 mapping: [],307 };308 const result = processTSQueryAST(parsedQuery.query, { ids: [] });309 expect(result).toEqual(expectedResult);310});311test('(TS) query with empty spread params', () => {312 const query = `INSERT INTO data.action_log (id, name) VALUES $$params(id, name)`;313 const parsedQuery = parseTSQuery(query);314 const expectedResult = {315 query: `INSERT INTO data.action_log (id, name) VALUES ()`,316 bindings: [],317 mapping: [],318 };319 const result = processTSQueryAST(parsedQuery.query, { params: [] });320 expect(result).toEqual(expectedResult);321});322test('(TS) query with underscores in key names and param names', () => {323 const query = `INSERT INTO data.action_log (_id, _name) VALUES $$_params(_id, _name)`;324 const parsedQuery = parseTSQuery(query);325 const expectedResult = {326 query: `INSERT INTO data.action_log (_id, _name) VALUES ($1, $2)`,327 bindings: ['one', 'two'],328 mapping: [],329 };330 const result = processTSQueryAST(parsedQuery.query, {331 _params: [{ _id: 'one', _name: 'two' }],332 });333 expect(result).toEqual(expectedResult);334});335test('(TS) all kinds mapping ', () => {336 const query =337 'SELECT $userId $age! $userId $$users $age $user(id) $$users $user(id, parentId, age) $$comments(id!, text) $user(age!)';338 const parsedQuery = parseTSQuery(query);339 const expectedResult = {340 query: 'SELECT $1 $2 $1 ($3) $2 ($4) ($3) ($4, $5, $6) ($7, $8) ($6)',341 bindings: [],342 mapping: [343 {344 name: 'userId',345 type: ParamTransform.Scalar,346 required: false,347 assignedIndex: 1,348 },349 {350 name: 'age',351 type: ParamTransform.Scalar,352 required: true,353 assignedIndex: 2,354 },355 {356 name: 'users',357 type: ParamTransform.Spread,358 required: false,359 assignedIndex: [3],360 },361 {362 name: 'user',363 type: ParamTransform.Pick,364 dict: {365 id: {366 name: 'id',367 type: ParamTransform.Scalar,368 required: false,369 assignedIndex: 4,370 },371 age: {372 name: 'age',373 type: ParamTransform.Scalar,374 required: true,375 assignedIndex: 6,376 },377 parentId: {378 name: 'parentId',379 type: ParamTransform.Scalar,380 required: false,381 assignedIndex: 5,382 },383 },384 },385 {386 name: 'comments',387 type: ParamTransform.PickSpread,388 dict: {389 id: {390 name: 'id',391 type: ParamTransform.Scalar,392 required: true,393 assignedIndex: 7,394 },395 text: {396 name: 'text',397 type: ParamTransform.Scalar,398 required: false,399 assignedIndex: 8,400 },401 },402 },403 ],404 };405 const result = processTSQueryAST(parsedQuery.query);406 expect(result).toEqual(expectedResult);407});408test('(TS) required spread', () => {409 const query = 'SELECT $$users!';410 const parsedQuery = parseTSQuery(query);411 const expectedResult = {412 query: 'SELECT ($1)',413 bindings: [],414 mapping: [415 {416 name: 'users',417 type: ParamTransform.Spread,418 required: true,419 assignedIndex: [1],420 },421 ],422 };423 const result = processTSQueryAST(parsedQuery.query);424 expect(result).toEqual(expectedResult);...

Full Screen

Full Screen

api_search_tests.js

Source:api_search_tests.js Github

copy

Full Screen

1import ApiSearch from 'app/lib/api_search';2module("ApiSearch public api");3function buildApiSearch (data) {4 return new ApiSearch(data || {});5}6test("namespace", function(){7 ok(ApiSearch);8});9test("instantiation", function(){10 var instance;11 instance = buildApiSearch();12 ok(instance);13 ok(instance.search);14});15module("ApiSearch.search");16test("empty query", function(){17 var instance;18 instance = buildApiSearch();19 deepEqual(instance.search(), {}, 'no results');20});21test("simple search, with no data", function(){22 var instance, result, query, apiSearch;23 instance = buildApiSearch();24 query = "Ember.View";25 result = instance.search(query);26 ok(result, 'returned a result object');27 deepEqual(result.files, [], 'empty files');28 deepEqual(result.classes, [], 'empty classes');29 deepEqual(result.modules, [], 'empty modules');30 deepEqual(result.classItems, [], 'empty classitems');31});32var exampleData = {33 project: { },34 files: {35 "../packages/ember-views/lib/views/view.js": {36 name: "../packages/ember-views/lib/views/view.js",37 modules: {},38 classes: { "Ember.View":1 },39 fors: { Ember: 1 },40 namespaces: { Ember: 1 }41 }42 },43 classes: {44 'Ember.View': {45 classitems: [],46 description: "description text",47 extends: "Ember.Object",48 extension_for: [],49 extensions: [],50 file: "../packages/ember-views/lib/views/view.js",51 line: 208,52 module: "ember",53 name: "Ember.View",54 namespace: "Ember",55 plugin_for: [],56 plugins: [],57 shortname: "Ember.View",58 submodule: "ember-views"59 }60 },61 classitems: [62 {63 file: "../packages/ember-views/lib/views/view.js",64 line: 762,65 description:"description",66 itemtype: "property",67 name:"isView",68 type: "Boolean",69 default: "true",70 final: 1,71 class: "Ember.View",72 module: "ember",73 submodule: "ember-views",74 namespace: "Ember"75 }76 ],77 modules: {78 ember: {79 name: "ember",80 submodules: {81 "ember-application": 1,82 "ember-debug": 1,83 "ember-handlebars": 1,84 "ember-routing": 1,85 "ember-runtime": 1,86 "ember-states": 1,87 "ember-views": 188 }89 }90 }91};92test("simple search, with simple data", function(){93 var instance, result, query, apiSearch, data;94 instance = buildApiSearch(exampleData);95 query = "Ember.View";96 result = instance.search(query);97 ok(result, 'returned a result object');98 var emberViewClass = exampleData.classes['Ember.View'];99 var emberViewFile = exampleData.files['../packages/ember-views/lib/views/view.js'];100 deepEqual(result.modules, [], 'empty modules');101 deepEqual(result.classes, [emberViewClass], 'Ember.View class');102 deepEqual(result.classItems, [], 'empty classitems');103 // once each search catagory can return cross category results104 // deepEqual(result.files, [emberViewFile], 'empty files');105 // deepEqual(result.classItems, exampleData.json.classitems, 'empty classitems');106});107module("ApiSearch.helpers.parseQuery");108var helpers = ApiSearch.helpers;109test("empty query", function(){110 var query, parsedQuery;111 parsedQuery = helpers.parseQuery(query);112 deepEqual(parsedQuery.files, [], 'expected no files');113 deepEqual(parsedQuery.modules, [], 'expected no modules');114 deepEqual(parsedQuery.classes, [], 'expected no classes');115 deepEqual(parsedQuery.classitems, [], 'expected no classitems');116});117test("a class", function(){118 var query, parsedQuery;119 query = 'Ember.View';120 parsedQuery = helpers.parseQuery(query);121 deepEqual(parsedQuery.files, [], 'expected no files');122 deepEqual(parsedQuery.modules, [], 'expected no modules');123 deepEqual(parsedQuery.classes, ['Ember.View'], 'expected classes');124 deepEqual(parsedQuery.classitems, [], 'expected no classitems');125});126test("a function or property", function(){127 var query, parsedQuery;128 query = "#isView";129 parsedQuery = helpers.parseQuery(query);130 deepEqual(parsedQuery.files, [], 'expected no files');131 deepEqual(parsedQuery.modules, [], 'expected no modules');132 deepEqual(parsedQuery.classes, [], 'expected no classes');133 deepEqual(parsedQuery.classitems, ['isView'], 'expected classitems');134});135test("a file", function(){136 var query, parsedQuery;137 query = "/a/file/path";138 parsedQuery = helpers.parseQuery(query);139 deepEqual(parsedQuery.files, ['/a/file/path'], 'expect files');140 deepEqual(parsedQuery.modules, [], 'expected no modules');141 deepEqual(parsedQuery.classes, [], 'expected no classes');142 deepEqual(parsedQuery.classitems, [], 'expected no classitems');143});144module("ApiSearch.helpers.compileParsedQuery");145test("empty query", function(){146 var compileQuery;147 compileQuery = helpers.compileParsedQuery({});148 deepEqual(compileQuery, {}, 'expected nothing');149});150test("non empty-query", function(){151 var query, parsedQuery;152 query = {153 files: ['/a/file/path'],154 modules: ['ember','ember-debug'],155 classes: ['Ember.View'],156 classitems: ['isView']157 };158 parsedQuery = helpers.compileParsedQuery(query);159 deepEqual(parsedQuery.files, new RegExp('/a/file/path','i'));160 deepEqual(parsedQuery.modules, /ember|ember-debug/i);161 deepEqual(parsedQuery.classes, /Ember.*View/i);162 deepEqual(parsedQuery.classitems, /isView/i);...

Full Screen

Full Screen

crud-body-request.ts

Source:crud-body-request.ts Github

copy

Full Screen

1import {CrudRequest, ParamsOptions, QueryOptions, RoutesOptions} from '@nestjsx/crud';2import {RequestQueryParser} from '@nestjsx/crud-request';3import {ErrorUtils, ExceptionBuilder} from '../../../utils';4interface IGetRequestFromBodyOptions {5 query?: QueryOptions;6 routes?: RoutesOptions;7 params?: ParamsOptions;8 key?: string;9}10const defaultGetRequestFromBodyOptions: IGetRequestFromBodyOptions = {11 query: {},12 routes: {},13 params: {},14 key: 'query',15};16export class CrudBodyRequest {17 constructor() {}18 static getRequestFromBody(19 body: {query: any} & any,20 options: IGetRequestFromBodyOptions = {},21 ) {22 const {key, query, routes, params} = {...defaultGetRequestFromBodyOptions, ...options};23 const queryObject = body[key];24 if (!queryObject) {25 ErrorUtils.throwHttpException(ExceptionBuilder.BAD_REQUEST);26 }27 if (queryObject.s && !queryObject.search) {28 queryObject.search = queryObject.s;29 }30 const queryParser = RequestQueryParser.create();31 const parsedQuery = queryParser.parseQuery(queryObject);32 if (!parsedQuery.page) {33 parsedQuery.page = queryObject.page || 1;34 }35 // parsedQuery.offset = parsedQuery.page;36 if (!parsedQuery.limit) {37 parsedQuery.limit = queryObject.limit || 100;38 }39 if (!parsedQuery.search) {40 parsedQuery.search = {};41 }42 if (!parsedQuery.search.$and) {43 parsedQuery.search.$and = [];44 }45 for (const [k, v] of Object.entries(parsedQuery.search)) {46 if (k !== '$and') {47 parsedQuery.search.$and.push({[k]: v});48 delete parsedQuery.search[k];49 }50 }51 if (parsedQuery.filter && parsedQuery.filter.length && !parsedQuery.search.$and.length) {52 for (const rule of parsedQuery.filter) {53 parsedQuery.search.$and.push({[rule.field]: {[rule.operator]: rule.value}});54 }55 }56 return {parsed: parsedQuery, options: {query, routes, params}} as CrudRequest;57 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestbuy = require('bestbuy')('9n7d7z6b4y7v7z8n8r7r2z2a');2var searchTerm = 'nintendo 3ds';3bestbuy.products('(search='+searchTerm+')', {show: 'sku,name,salePrice,manufacturer,shortDescription'}, function(err, data) {4 if (err) {5 console.error(err);6 }7 console.log(data);8});9var bestbuy = require('bestbuy')('9n7d7z6b4y7v7z8n8r7r2z2a');10var searchTerm = 'nintendo 3ds';11bestbuy.products('(search='+searchTerm+')', {show: 'sku,name,salePrice,manufacturer,shortDescription', sort: 'salePrice.asc'}, function(err, data) {12 if (err) {13 console.error(err);14 }15 console.log(data);16});17var bestbuy = require('bestbuy')('9n7d7z6b4y7v7z8n8r7r2z2a');18var searchTerm = 'nintendo 3ds';19bestbuy.products('(search='+searchTerm+')', {show: 'sku,name,salePrice,manufacturer,shortDescription', sort: 'salePrice.asc', pageSize: 5}, function(err, data) {20 if (err) {21 console.error(err);22 }23 console.log(data);24});25var bestbuy = require('bestbuy')('9n7d7z6b4y7v7z8n8r7r2z2a');26var searchTerm = 'nintendo 3ds';27bestbuy.products('(search='+searchTerm+')', {show: 'sku,name,salePrice,manufacturer,shortDescription', sort: 'salePrice.asc', pageSize: 5, page:

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful