{"size": 1524, "ext": "js", "max_stars_repo_path": "lib/https/createHttpsAgent.test.js", "max_stars_repo_name": "trasherdk/catkeys", "max_stars_repo_stars_event_min_datetime": "2021-03-04T21:43:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T13:25:25.000Z", "max_issues_repo_path": "lib/https/createHttpsAgent.test.js", "max_issues_repo_name": "93million/catkeys", "max_issues_repo_issues_event_min_datetime": "2021-04-25T11:24:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T11:34:25.000Z", "max_forks_repo_path": "lib/https/createHttpsAgent.test.js", "max_forks_repo_name": "trasherdk/catkeys", "max_forks_repo_forks_event_min_datetime": "2021-03-06T15:06:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T19:19:19.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 26.7368421053, "max_line_length": 78, "alphanum_fraction": 0.7342519685}
/* global expect jest test  */

const https = require('https')
const createHttpsAgent = require('./createHttpsAgent')
const createSecureContext = require('../createSecureContext')
const checkServerIdentity = require('../checkServerIdentity')

jest.mock('https')
jest.mock('../checkServerIdentity')
jest.mock('../createSecureContext')

const mockSecureContext = { ca: 'cadata', key: 'keydata', cert: 'certdata' }
const mockHost = 'mockhost.name'
const mockPort = 1337

https.Agent.mockImplementation(({ checkServerIdentity }) => {
  checkServerIdentity(mockHost, mockPort)
})

createSecureContext.mockReturnValue(Promise.resolve(mockSecureContext))

test(
  'should pass catRejectMismatchedHostname to checkServerIdentity()',
  async () => {
    const catRejectMismatchedHostname = 'testcatRejectMismatchedHostnameValue'

    await createHttpsAgent({ catRejectMismatchedHostname })

    expect(checkServerIdentity)
      .toBeCalledWith(mockHost, mockPort, { catRejectMismatchedHostname })
  }
)

test(
  'should pass all received options to createSecureContext()',
  async () => {
    const options = { random: 'option', foo: 'bar' }

    await createHttpsAgent(options)

    expect(createSecureContext).toBeCalledWith(options)
  }
)

test(
  'should run without passing options arg',
  async () => {
    await createHttpsAgent()

    expect(createSecureContext).toBeCalledWith({})
    expect(https.Agent).toBeCalledWith({
      checkServerIdentity: expect.any(Function),
      secureContext: mockSecureContext
    })
  }
)
