How to use queryParameterValue method in apickli

Best JavaScript code snippet using apickli

urlHelpers.ts

Source:urlHelpers.ts Github

copy

Full Screen

1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT license.3import { OperationSpec, OperationArguments, QueryCollectionFormat } from "./interfaces";4import { getOperationArgumentValueFromParameter } from "./operationHelpers";5import { getPathStringFromParameter } from "./interfaceHelpers";6const CollectionFormatToDelimiterMap: { [key in QueryCollectionFormat]: string } = {7 CSV: ",",8 SSV: " ",9 Multi: "Multi",10 TSV: "\t",11 Pipes: "|"12};13export function getRequestUrl(14 baseUri: string,15 operationSpec: OperationSpec,16 operationArguments: OperationArguments,17 fallbackObject: { [parameterName: string]: any }18): string {19 const urlReplacements = calculateUrlReplacements(20 operationSpec,21 operationArguments,22 fallbackObject23 );24 let isAbsolutePath = false;25 let requestUrl = replaceAll(baseUri, urlReplacements);26 if (operationSpec.path) {27 const path = replaceAll(operationSpec.path, urlReplacements);28 // QUIRK: sometimes we get a path component like {nextLink}29 // which may be a fully formed URL. In that case, we should30 // ignore the baseUri.31 if (isAbsoluteUrl(path)) {32 requestUrl = path;33 isAbsolutePath = true;34 } else {35 requestUrl = appendPath(requestUrl, path);36 }37 }38 const { queryParams, sequenceParams } = calculateQueryParameters(39 operationSpec,40 operationArguments,41 fallbackObject42 );43 /**44 * Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`45 * is an absolute path. This ensures that existing query parameter values in `requestUrl`46 * do not get overwritten. On the other hand when `requestUrl` is not absolute path, it47 * is still being built so there is nothing to overwrite.48 */49 requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);50 return requestUrl;51}52function replaceAll(input: string, replacements: Map<string, string>): string {53 let result = input;54 for (const [searchValue, replaceValue] of replacements) {55 result = result.split(searchValue).join(replaceValue);56 }57 return result;58}59function calculateUrlReplacements(60 operationSpec: OperationSpec,61 operationArguments: OperationArguments,62 fallbackObject: { [parameterName: string]: any }63): Map<string, string> {64 const result = new Map<string, string>();65 if (operationSpec.urlParameters?.length) {66 for (const urlParameter of operationSpec.urlParameters) {67 let urlParameterValue: string = getOperationArgumentValueFromParameter(68 operationArguments,69 urlParameter,70 fallbackObject71 );72 const parameterPathString = getPathStringFromParameter(urlParameter);73 urlParameterValue = operationSpec.serializer.serialize(74 urlParameter.mapper,75 urlParameterValue,76 parameterPathString77 );78 if (!urlParameter.skipEncoding) {79 urlParameterValue = encodeURIComponent(urlParameterValue);80 }81 result.set(82 `{${urlParameter.mapper.serializedName || parameterPathString}}`,83 urlParameterValue84 );85 }86 }87 return result;88}89function isAbsoluteUrl(url: string): boolean {90 return url.includes("://");91}92function appendPath(url: string, pathToAppend?: string): string {93 if (!pathToAppend) {94 return url;95 }96 const parsedUrl = new URL(url);97 let newPath = parsedUrl.pathname;98 if (!newPath.endsWith("/")) {99 newPath = `${newPath}/`;100 }101 if (pathToAppend.startsWith("/")) {102 pathToAppend = pathToAppend.substring(1);103 }104 const searchStart = pathToAppend.indexOf("?");105 if (searchStart !== -1) {106 const path = pathToAppend.substring(0, searchStart);107 const search = pathToAppend.substring(searchStart + 1);108 newPath = newPath + path;109 if (search) {110 parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;111 }112 } else {113 newPath = newPath + pathToAppend;114 }115 parsedUrl.pathname = newPath;116 return parsedUrl.toString();117}118function calculateQueryParameters(119 operationSpec: OperationSpec,120 operationArguments: OperationArguments,121 fallbackObject: { [parameterName: string]: any }122): {123 queryParams: Map<string, string | string[]>;124 sequenceParams: Set<string>;125} {126 const result = new Map<string, string | string[]>();127 const sequenceParams: Set<string> = new Set<string>();128 if (operationSpec.queryParameters?.length) {129 for (const queryParameter of operationSpec.queryParameters) {130 if (queryParameter.mapper.type.name === "Sequence" && queryParameter.mapper.serializedName) {131 sequenceParams.add(queryParameter.mapper.serializedName);132 }133 let queryParameterValue: string | string[] = getOperationArgumentValueFromParameter(134 operationArguments,135 queryParameter,136 fallbackObject137 );138 if (139 (queryParameterValue !== undefined && queryParameterValue !== null) ||140 queryParameter.mapper.required141 ) {142 queryParameterValue = operationSpec.serializer.serialize(143 queryParameter.mapper,144 queryParameterValue,145 getPathStringFromParameter(queryParameter)146 );147 const delimiter = queryParameter.collectionFormat148 ? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]149 : "";150 if (Array.isArray(queryParameterValue)) {151 // replace null and undefined152 queryParameterValue = queryParameterValue.map((item) => {153 if (item === null || item === undefined) {154 return "";155 }156 return item;157 });158 }159 if (queryParameter.collectionFormat === "Multi" && queryParameterValue.length === 0) {160 continue;161 } else if (162 Array.isArray(queryParameterValue) &&163 (queryParameter.collectionFormat === "SSV" || queryParameter.collectionFormat === "TSV")164 ) {165 queryParameterValue = queryParameterValue.join(delimiter);166 }167 if (!queryParameter.skipEncoding) {168 if (Array.isArray(queryParameterValue)) {169 queryParameterValue = queryParameterValue.map((item: string) => {170 return encodeURIComponent(item);171 });172 } else {173 queryParameterValue = encodeURIComponent(queryParameterValue);174 }175 }176 // Join pipes and CSV *after* encoding, or the server will be upset.177 if (178 Array.isArray(queryParameterValue) &&179 (queryParameter.collectionFormat === "CSV" || queryParameter.collectionFormat === "Pipes")180 ) {181 queryParameterValue = queryParameterValue.join(delimiter);182 }183 result.set(184 queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter),185 queryParameterValue186 );187 }188 }189 }190 return {191 queryParams: result,192 sequenceParams193 };194}195function simpleParseQueryParams(queryString: string): Map<string, string | string[] | undefined> {196 const result: Map<string, string | string[] | undefined> = new Map<197 string,198 string | string[] | undefined199 >();200 if (!queryString || queryString[0] !== "?") {201 return result;202 }203 // remove the leading ?204 queryString = queryString.slice(1);205 const pairs = queryString.split("&");206 for (const pair of pairs) {207 const [name, value] = pair.split("=", 2);208 const existingValue = result.get(name);209 if (existingValue) {210 if (Array.isArray(existingValue)) {211 existingValue.push(value);212 } else {213 result.set(name, [existingValue, value]);214 }215 } else {216 result.set(name, value);217 }218 }219 return result;220}221/** @internal */222export function appendQueryParams(223 url: string,224 queryParams: Map<string, string | string[]>,225 sequenceParams: Set<string>,226 noOverwrite: boolean = false227): string {228 if (queryParams.size === 0) {229 return url;230 }231 const parsedUrl = new URL(url);232 // QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which233 // can change their meaning to the server, such as in the case of a SAS signature.234 // To avoid accidentally un-encoding a query param, we parse the key/values ourselves235 const combinedParams = simpleParseQueryParams(parsedUrl.search);236 for (const [name, value] of queryParams) {237 const existingValue = combinedParams.get(name);238 if (Array.isArray(existingValue)) {239 if (Array.isArray(value)) {240 existingValue.push(...value);241 const valueSet = new Set(existingValue);242 combinedParams.set(name, Array.from(valueSet));243 } else {244 existingValue.push(value);245 }246 } else if (existingValue) {247 if (Array.isArray(value)) {248 value.unshift(existingValue);249 } else if (sequenceParams.has(name)) {250 combinedParams.set(name, [existingValue, value]);251 }252 if (!noOverwrite) {253 combinedParams.set(name, value);254 }255 } else {256 combinedParams.set(name, value);257 }258 }259 const searchPieces: string[] = [];260 for (const [name, value] of combinedParams) {261 if (typeof value === "string") {262 searchPieces.push(`${name}=${value}`);263 } else if (Array.isArray(value)) {264 // QUIRK: If we get an array of values, include multiple key/value pairs265 for (const subValue of value) {266 searchPieces.push(`${name}=${subValue}`);267 }268 } else {269 searchPieces.push(`${name}=${value}`);270 }271 }272 // QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.273 parsedUrl.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";274 return parsedUrl.toString();...

Full Screen

Full Screen

convertGraphQLParameters.js

Source:convertGraphQLParameters.js Github

copy

Full Screen

1/**2 * converts graphql parameters to standard FHIR parameters3 * @param {string | string[] | Object} queryParameterValue4 * @param {Object} args5 * @param {string} queryParameter6 * @return {string | string[]}7 */8function convertGraphQLParameters(queryParameterValue, args, queryParameter) {9 if (queryParameterValue) {10 // un-bundle any objects coming from graphql11 if (12 typeof queryParameterValue === 'object' &&13 !Array.isArray(queryParameterValue) &&14 queryParameterValue['searchType']15 ) {16 switch (queryParameterValue['searchType']) {17 case 'string':18 // handle SearchString19 if (queryParameterValue['value']) {20 queryParameterValue = queryParameterValue['value'];21 } else if (queryParameterValue['values']) {22 queryParameterValue = queryParameterValue['values'];23 }24 break;25 case 'token':26 if (queryParameterValue['value']) {27 queryParameterValue['values'] = [queryParameterValue['value']];28 }29 if (queryParameterValue['values']) {30 for (const token of queryParameterValue['values']) {31 queryParameterValue = [];32 let tokenString = '';33 if (token['system']) {34 tokenString = token['system'] + '|';35 }36 if (token['code']) {37 tokenString += token['code'];38 }39 if (token['value']) {40 tokenString += token['value'];41 }42 if (tokenString) {43 queryParameterValue.push(tokenString);44 }45 }46 }47 break;48 case 'reference':49 // eslint-disable-next-line no-case-declarations50 let referenceText = '';51 if (queryParameterValue['target']) {52 referenceText = queryParameterValue['target'] + '/';53 }54 if (queryParameterValue['value']) {55 referenceText += queryParameterValue['value'];56 }57 queryParameterValue = referenceText;58 break;59 case 'quantity':60 // eslint-disable-next-line no-case-declarations61 let quantityString = '';62 if (queryParameterValue['prefix']) {63 quantityString += queryParameterValue['prefix'];64 }65 if (queryParameterValue['value']) {66 quantityString += queryParameterValue['value'];67 }68 if (queryParameterValue['system']) {69 quantityString = '|' + queryParameterValue['system'];70 }71 if (queryParameterValue['code']) {72 quantityString = '|' + queryParameterValue['code'];73 }74 queryParameterValue = quantityString;75 break;76 case 'date':77 case 'dateTime':78 case 'number':79 if (queryParameterValue['value']) {80 queryParameterValue['values'] = [queryParameterValue['value']];81 }82 if (queryParameterValue['values']) {83 const numberValues = [];84 for (const dateValue of queryParameterValue['values']) {85 queryParameterValue = [];86 let dateString = '';87 if (dateValue['equals']) {88 dateString = 'eq' + dateValue['equals'];89 }90 if (dateValue['notEquals']) {91 dateString = 'ne' + dateValue['notEquals'];92 }93 if (dateValue['greaterThan']) {94 dateString = 'gt' + dateValue['greaterThan'];95 }96 if (dateValue['greaterThanOrEqualTo']) {97 dateString = 'ge' + dateValue['greaterThanOrEqualTo'];98 }99 if (dateValue['lessThan']) {100 dateString = 'lt' + dateValue['lessThan'];101 }102 if (dateValue['lessThanOrEqualTo']) {103 dateString = 'le' + dateValue['lessThanOrEqualTo'];104 }105 if (dateValue['startsAfter']) {106 dateString = 'sa' + dateValue['startsAfter'];107 }108 if (dateValue['endsBefore']) {109 dateString = 'eb' + dateValue['endsBefore'];110 }111 if (dateValue['approximately']) {112 dateString = 'ap' + dateValue['approximately'];113 }114 if (dateString) {115 numberValues.push(dateString);116 }117 }118 if (numberValues.length > 0) {119 queryParameterValue = queryParameterValue.concat(numberValues);120 }121 }122 break;123 }124 if (queryParameterValue['missing'] !== null) {125 args[`${queryParameter}:missing`] = queryParameterValue['missing'];126 }127 }128 }129 return queryParameterValue;130}131module.exports = {132 convertGraphQLParameters: convertGraphQLParameters...

Full Screen

Full Screen

query-builder.ts

Source:query-builder.ts Github

copy

Full Screen

1import { RepositoryQuery } from './repository-query';2import { Entity, EntityType } from './entity';3import { QueryParameter } from './query-parameter';4import { QueryParameterValue } from './query-parameter-value';5import { QueryOperator } from './query-operator';6type PropertyType<T> = keyof T & string;7const BASE_SELECT = 'select * from c';8export class QueryBuilder<T extends Entity> {9 private readonly parameters: Array<QueryParameter> = [];10 constructor(private readonly entityType: EntityType<T>) {11 this.where('type', entityType.type);12 }13 where(14 property: PropertyType<T>,15 value: QueryParameterValue,16 operator: QueryOperator = QueryOperator.Equal17 ): QueryBuilder<T> {18 this.parameters.push({ name: property, value, operator });19 return this;20 }21 whereEqual(22 property: PropertyType<T>,23 value: QueryParameterValue24 ): QueryBuilder<T> {25 return this.where(property, value);26 }27 whereLessThan(28 property: PropertyType<T>,29 value: QueryParameterValue30 ): QueryBuilder<T> {31 return this.where(property, value, QueryOperator.LessThan);32 }33 whereGreaterThan(34 property: PropertyType<T>,35 value: QueryParameterValue36 ): QueryBuilder<T> {37 return this.where(property, value, QueryOperator.GreaterThan);38 }39 whereLessThanOrEqual(40 property: PropertyType<T>,41 value: QueryParameterValue42 ): QueryBuilder<T> {43 return this.where(property, value, QueryOperator.LessThanOrEqual);44 }45 whereGreaterThanOrEqual(46 property: PropertyType<T>,47 value: QueryParameterValue48 ): QueryBuilder<T> {49 return this.where(property, value, QueryOperator.GreaterThanOrEqual);50 }51 whereLike(52 property: PropertyType<T>,53 value: QueryParameterValue54 ): QueryBuilder<T> {55 return this.where(property, value, QueryOperator.Like);56 }57 build(): RepositoryQuery {58 const wheres = this.parameters59 .map((p) => `c.${p.name} ${p.operator} @${p.name}`)60 .join(' and ');61 return {62 text: `${BASE_SELECT} where ${wheres}`,63 parameters: this.parameters.map((p) => ({64 name: `@${p.name}`,65 value: p.value,66 operator: p.operator,67 })),68 };69 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var apickliObject = new apickli.Apickli('http', 'httpbin.org');3apickliObject.addRequestHeader('Content-Type', 'application/json');4apickliObject.addRequestHeader('Accept', 'application/json');5apickliObject.get('/get?name=apickli');6apickliObject.getResponseStatusCode().should.equal(200);7apickliObject.getResponseObject().args.name.should.equal('apickli');8var apickli = require('apickli');9var apickliObject = new apickli.Apickli('http', 'httpbin.org');10apickliObject.addRequestHeader('Content-Type', 'application/json');11apickliObject.addRequestHeader('Accept', 'application/json');12apickliObject.get('/get?name=apickli');13apickliObject.getResponseStatusCode().should.equal(200);14apickliObject.getResponseObject().args.name.should.equal('apickli');15var apickli = require('apickli');16var apickliObject = new apickli.Apickli('http', 'httpbin.org');17apickliObject.addRequestHeader('Content-Type', 'application/json');18apickliObject.addRequestHeader('Accept', 'application/json');19apickliObject.get('/get?name=apickli');20apickliObject.getResponseStatusCode().should.equal(200);21apickliObject.getResponseObject().args.name.should.equal('apickli');22var apickli = require('apickli');23var apickliObject = new apickli.Apickli('http', 'httpbin.org');24apickliObject.addRequestHeader('Content-Type', 'application/json');25apickliObject.addRequestHeader('Accept', 'application/json');26apickliObject.get('/get?name=apickli');27apickliObject.getResponseStatusCode().should.equal(200);28apickliObject.getResponseObject().args.name.should.equal('apickli');29var apickli = require('apickli');30var apickliObject = new apickli.Apickli('http', 'httpbin.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given}) {4 Given('I set the query parameter {string} to {string}', function (queryParamName, queryParamValue, callback) {5 var queryParamValue = this.apickli.getQueryParameterValue(queryParamName);6 callback();7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given, When, Then}) {4 Given('I set the query parameter {string} to {string}', function (queryParameter, value, callback) {5 this.apickli.addQueryParameter(queryParameter, value);6 callback();7 });8});9var apickli = require('apickli');10var {defineSupportCode} = require('cucumber');11defineSupportCode(function({Given, When, Then}) {12 Given('I set the query parameter {string} to {string}', function (queryParameter, value, callback) {13 this.apickli.addQueryParameter(queryParameter, value);14 callback();15 });16});17var apickli = require('apickli');18var {defineSupportCode} = require('cucumber');19defineSupportCode(function({Given, When, Then}) {20 Given('I set the query parameter {string} to {string}', function (queryParameter, value, callback) {21 this.apickli.addQueryParameter(queryParameter, value);22 callback();23 });24});25var apickli = require('apickli');26var {defineSupportCode} = require('cucumber');27defineSupportCode(function({Given, When, Then}) {28 Given('I set the query parameter {string} to {string}', function (queryParameter, value, callback) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var myApickli = new apickli.Apickli('http', 'localhost:8080');3myApickli.queryParameterValue('name', 'value');4var apickli = require('apickli');5var myApickli = new apickli.Apickli('http', 'localhost:8080');6this.Given(/^I have query parameter "([^"]*)" set to "([^"]*)"$/, function (name, value, callback) {7 myApickli.queryParameterValue(name, value);8 callback();9});10var apickli = require('apickli');11var myApickli = new apickli.Apickli('http', 'localhost:8080');12this.Given(/^I have query parameter "([^"]*)" set to "([^"]*)"$/, function (name, value, callback) {13 myApickli.queryParameterValue(name, value);14 callback();15});16apickli.Apickli.prototype.addRequestHeader(headerName, headerValue)17apickli.Apickli.prototype.addRequestQueryParameter(parameterName, parameterValue)18apickli.Apickli.prototype.addRequestJsonBody(jsonBody)19apickli.Apickli.prototype.addRequestFormParameter(parameterName, parameterValue)20apickli.Apickli.prototype.addRequestMultipartParameter(parameterName, parameterValue)21apickli.Apickli.prototype.get(path, callback)22apickli.Apickli.prototype.post(path, callback)23apickli.Apickli.prototype.put(path, callback)24apickli.Apickli.prototype.delete(path, callback)25apickli.Apickli.prototype.head(path, callback)26apickli.Apickli.prototype.patch(path, callback)27apickli.Apickli.prototype.getResponseObject()

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given, When, Then}) {4 var apickli = new apickli.Apickli('http', 'httpbin.org');5 apickli.addRequestHeader('foo', queryParameterValue);6 When('I GET /get', function(callback) {7 apickli.get('/get', callback);8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function ({Given, When, Then}) {4 var apickliObject = new apickli.Apickli('http', 'localhost:8000');5 apickliObject.addRequestHeader('Content-Type', 'application/json');6 apickliObject.addRequestHeader('Accept', 'application/json');7 Given('I have set query parameter {string} to {string}', function (parameterName, parameterValue, callback) {8 apickliObject.queryParameterValue(parameterName, parameterValue);9 callback();10 });11 When('I GET the {string} resource', function (resource, callback) {12 apickliObject.get(resource, callback);13 });14 Then('the response code should be {int}', function (statusCode, callback) {15 apickliObject.assertResponseCode(statusCode);16 callback();17 });18});

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 apickli 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