{"size": 3997, "ext": "js", "max_stars_repo_path": "test/unit/query/classification-query.spec.js", "max_stars_repo_name": "mathiasrw/winnow", "max_stars_repo_stars_event_min_datetime": "2017-10-13T11:41:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-29T05:12:08.000Z", "max_issues_repo_path": "test/unit/query/classification-query.spec.js", "max_issues_repo_name": "mathiasrw/winnow", "max_issues_repo_issues_event_min_datetime": "2017-08-18T15:13:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T14:58:28.000Z", "max_forks_repo_path": "test/unit/query/classification-query.spec.js", "max_forks_repo_name": "mathiasrw/winnow", "max_forks_repo_forks_event_min_datetime": "2017-12-04T21:51:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-10T23:47:22.000Z"}
{"max_stars_count": 60, "max_issues_count": 71, "max_forks_count": 15, "avg_line_length": 31.7222222222, "max_line_length": 100, "alphanum_fraction": 0.6599949962}
const test = require('tape')
const sinon = require('sinon')
const proxyquire = require('proxyquire')
const modulePath = '../../../lib/query/classification-query'

test('classificationQuery, unsupported classification type', t => {
  const standardQuerySpy = sinon.spy(function () {
    return { features: ['feature1', 'feature2'] }
  })

  const classificationQuery = proxyquire(modulePath, {
    './standard-query': standardQuerySpy
  })

  try {
    classificationQuery(['feature1', 'feature2', 'feature3'], 'SQL statement', {
      foo: 'bar',
      collection: {},
      classification: { }
    })
    t.fail('classificationQuery should have failed')
  } catch (error) {
    t.equals(error.message, 'unacceptable classification type: undefined')
    t.ok(standardQuerySpy.calledOnce)
    t.deepEquals(standardQuerySpy.firstCall.args, [
      ['feature1', 'feature2', 'feature3'],
      'SQL statement',
      { foo: 'bar', collection: {}, classification: {} }
    ])
  }
  t.end()
})

test('classificationQuery, unsupported breakCount', t => {
  const standardQuerySpy = sinon.spy(function () {
    return { features: ['feature1', 'feature2'] }
  })

  const classificationQuery = proxyquire(modulePath, {
    './standard-query': standardQuerySpy
  })

  try {
    classificationQuery(['feature1', 'feature2', 'feature3'], 'SQL statement', {
      foo: 'bar',
      collection: {},
      classification: { type: 'classes', breakCount: 0 }
    })
    t.fail('classificationQuery should have failed')
  } catch (error) {
    t.equals(error.message, 'breakCount must be positive: 0')
    t.ok(standardQuerySpy.calledOnce)
    t.deepEquals(standardQuerySpy.firstCall.args, [
      ['feature1', 'feature2', 'feature3'],
      'SQL statement',
      { foo: 'bar', collection: {}, classification: { type: 'classes', breakCount: 0 } }
    ])
  }
  t.end()
})

test('classificationQuery, classes classification type', t => {
  const standardQuerySpy = sinon.spy(function () {
    return { features: ['feature1', 'feature2'] }
  })

  const calculateClassBreaksSpy = sinon.spy(function () {
    return 'classification results'
  })

  const classificationQuery = proxyquire(modulePath, {
    './standard-query': standardQuerySpy,
    '../calculate-class-breaks/index': calculateClassBreaksSpy
  })

  const result = classificationQuery(['feature1', 'feature2', 'feature3'], 'SQL statement', {
    foo: 'bar',
    collection: {},
    classification: { type: 'classes', breakCount: 1 }
  })
  t.deepEquals(result, 'classification results')
  t.ok(standardQuerySpy.calledOnce)
  t.deepEquals(standardQuerySpy.firstCall.args, [
    ['feature1', 'feature2', 'feature3'],
    'SQL statement',
    { foo: 'bar', collection: {}, classification: { type: 'classes', breakCount: 1 } }
  ])
  t.ok(calculateClassBreaksSpy.calledOnce)
  t.deepEquals(calculateClassBreaksSpy.firstCall.args, [
    ['feature1', 'feature2'],
    { type: 'classes', breakCount: 1 }
  ])
  t.end()
})

test('classificationQuery, unique classification type', t => {
  const standardQuerySpy = sinon.spy(function () {
    return { features: ['feature1', 'feature2'] }
  })

  const uniqueValueQuerySpy = sinon.spy(function () {
    return 'unique value query result'
  })

  const classificationQuery = proxyquire(modulePath, {
    './standard-query': standardQuerySpy,
    './unique-value-query': uniqueValueQuerySpy
  })

  const result = classificationQuery(['feature1', 'feature2', 'feature3'], 'SQL filter statement', {
    foo: 'bar',
    collection: {},
    classification: { type: 'unique' }
  })
  t.deepEquals(result, 'unique value query result')
  t.ok(standardQuerySpy.calledOnce)
  t.deepEquals(standardQuerySpy.firstCall.args, [
    ['feature1', 'feature2', 'feature3'],
    'SQL filter statement',
    { foo: 'bar', collection: {}, classification: { type: 'unique' } }
  ])
  t.ok(uniqueValueQuerySpy.calledOnce)
  t.deepEquals(uniqueValueQuerySpy.firstCall.args, [['feature1', 'feature2'], { type: 'unique' }])
  t.end()
})
