Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import deepEqual from 'deep-equal';
import * as fastCheck from 'fast-check';
import test from 'ava';
import queryString from '..';
// Valid query parameters must follow:
// - key can be any unicode string (not empty)
// - value must be one of:
// --> any unicode string
// --> null
// --> array containing values defined above (at least two items)
const queryParamsArbitrary = fastCheck.dictionary(
fastCheck.fullUnicodeString(1, 10),
fastCheck.oneof(
fastCheck.fullUnicodeString(),
fastCheck.constant(null),
fastCheck.array(fastCheck.oneof(fastCheck.fullUnicodeString(), fastCheck.constant(null)), 2, 10)
)
);
const optionsArbitrary = fastCheck.record({
arrayFormat: fastCheck.constantFrom('bracket', 'index', 'none'),
strict: fastCheck.boolean(),
encode: fastCheck.constant(true),
sort: fastCheck.constant(false)
}, {withDeletedKeys: true});
test('should read correctly from stringified query params', t => {
it('successful server-stream call', async () => {
await fc.assert(
fc.asyncProperty(
fc.record({
method: lowerCamelCase(),
requestContext: context(),
responseContext: context(),
useCompression: fc.boolean(),
request: fc.array(fc.dictionary(fc.string(), fc.jsonObject())),
}),
async arb => {
const app = express();
const handler: ModuleRpcServer.ServiceHandlerFor<
typeof serverStreamServiceDefinition,
any
> = {
async serverStream(
request: any[],
{ onReady, onMessage },
requestContext,
) {
onReady(() => {});
for (const item of request) {
onMessage({
item,
const context = () =>
fc.dictionary(
fc.stringOf(
fc.constantFrom(...'abcdefghijklmnopqrstuvzxyz-'.split('')),
1,
20,
),
fc.stringOf(
fc.constantFrom(...'abcdefghijklmnopqrstuvzxyz-'.split('')),
1,
20,
),
);
it('successful unary call', async () => {
await fc.assert(
fc.asyncProperty(
fc.record({
method: lowerCamelCase(),
requestContext: context(),
responseContext: context(),
useCompression: fc.boolean(),
request: fc.dictionary(fc.string(), fc.jsonObject()),
useRequestFunction: fc.boolean(),
}),
async arb => {
const app = express();
const handler: ModuleRpcServer.ServiceHandlerFor<
typeof unaryServiceDefinition,
any
> = {
async unary(request, requestContext) {
return {
fooRequest: request,
barRequestContext: requestContext,
};
},
};
app.use(
packageNames.map(pname =>
fc.tuple(fc.constant(pname), fc.record({
dependencies: fc.dictionary(fc.constantFrom(...packageNames), fc.constant('1.0.0'))
}) as fc.Arbitrary)
)
case 'NullType':
return fc.constant(null) as any;
case 'StringType':
return fc.string() as any;
case 'NumberType':
return fc.float() as any;
case 'BooleanType':
return fc.boolean() as any;
case 'KeyofType':
return fc.oneof(...keys(type.keys).map(fc.constant)) as any;
case 'LiteralType':
return fc.constant(type.value);
case 'ArrayType':
return fc.array(getArbitrary(type.type)) as any;
case 'DictionaryType':
return fc.dictionary(getArbitrary(type.domain), getArbitrary(type.codomain)) as any;
case 'InterfaceType':
case 'PartialType':
case 'ExactType':
return fc.record(record.map(getProps(type), getArbitrary as any) as any) as any;
case 'TupleType':
return (fc.tuple as any)(...type.types.map(getArbitrary));
case 'UnionType':
return fc.oneof(...type.types.map(getArbitrary)) as any;
case 'IntersectionType':
const isObjectIntersection = objectTypes.includes(type.types[0]._tag);
return isObjectIntersection
? (fc.tuple as any)(...type.types.map(t => getArbitrary(t)))
.map((values: Array) => Object.assign({}, ...values))
.filter(type.is)
: fc.oneof(...type.types.map(t => getArbitrary(t))).filter(type.is);
case 'RefinementType':