11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst http2 = require('http2');
81cb0ef41Sopenharmony_ciconst { inspect } = require('util');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Check if correct errors are emitted when wrong type of data is passed
111cb0ef41Sopenharmony_ci// to certain options of ClientHttp2Session request method
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst optionsToTest = {
141cb0ef41Sopenharmony_ci  endStream: 'boolean',
151cb0ef41Sopenharmony_ci  weight: 'number',
161cb0ef41Sopenharmony_ci  parent: 'number',
171cb0ef41Sopenharmony_ci  exclusive: 'boolean',
181cb0ef41Sopenharmony_ci  silent: 'boolean'
191cb0ef41Sopenharmony_ci};
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciconst types = {
221cb0ef41Sopenharmony_ci  boolean: true,
231cb0ef41Sopenharmony_ci  function: () => {},
241cb0ef41Sopenharmony_ci  number: 1,
251cb0ef41Sopenharmony_ci  object: {},
261cb0ef41Sopenharmony_ci  array: [],
271cb0ef41Sopenharmony_ci  null: null,
281cb0ef41Sopenharmony_ci  symbol: Symbol('test')
291cb0ef41Sopenharmony_ci};
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciconst server = http2.createServer(common.mustNotCall());
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
341cb0ef41Sopenharmony_ci  const port = server.address().port;
351cb0ef41Sopenharmony_ci  const client = http2.connect(`http://localhost:${port}`);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  client.on('connect', () => {
381cb0ef41Sopenharmony_ci    Object.keys(optionsToTest).forEach((option) => {
391cb0ef41Sopenharmony_ci      Object.keys(types).forEach((type) => {
401cb0ef41Sopenharmony_ci        if (type === optionsToTest[option])
411cb0ef41Sopenharmony_ci          return;
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci        assert.throws(
441cb0ef41Sopenharmony_ci          () => client.request({
451cb0ef41Sopenharmony_ci            ':method': 'CONNECT',
461cb0ef41Sopenharmony_ci            ':authority': `localhost:${port}`
471cb0ef41Sopenharmony_ci          }, {
481cb0ef41Sopenharmony_ci            [option]: types[type]
491cb0ef41Sopenharmony_ci          }), {
501cb0ef41Sopenharmony_ci            name: 'TypeError',
511cb0ef41Sopenharmony_ci            code: 'ERR_INVALID_ARG_VALUE',
521cb0ef41Sopenharmony_ci            message: `The property 'options.${option}' is invalid. ` +
531cb0ef41Sopenharmony_ci                    `Received ${inspect(types[type])}`
541cb0ef41Sopenharmony_ci          });
551cb0ef41Sopenharmony_ci      });
561cb0ef41Sopenharmony_ci    });
571cb0ef41Sopenharmony_ci    server.close();
581cb0ef41Sopenharmony_ci    client.close();
591cb0ef41Sopenharmony_ci  });
601cb0ef41Sopenharmony_ci}));
61