<commit_before>'use strict'

const assert = require('chai').assert
const Wmata = require('../captran-wmata')

describe('wmata module renderQueryUrl', () => {
  var wmata = new Wmata()
  let query = 'stops'
  let params = {
    queryType: query,
    key1: 'value1',
    key2: 'value2',
    key3: 'value3'
  }
  let testKey = 'abcde'

  it('should return a nice query URL', done => {
    let expectedBaseUrl = 'https://api.wmata.com/Bus.svc/json/' + 'jStops'
    assert.equal(wmata.renderQueryUrl(params, testKey),
      expectedBaseUrl + `?key1=value1&key2=value2&key3=value3&api_key=${testKey}`)

    assert.equal(wmata.renderQueryUrl({
      queryType: 'busPositions',
      Lat: 38.8690011,
      Lon: -77.0544217,
      Radius: 500
    }, testKey),
    `https://api.wmata.com/Bus.svc/json/jBusPositions?Lat=38.8690011&Lon=-77.0544217&Radius=500&api_key=${testKey}`)

    done()
  })

  it('should render query URLs that have no parameters (except API key)', done => {
    assert.equal(wmata.renderQueryUrl({
      queryType: 'routes'
    }, testKey), `https://api.wmata.com/Bus.svc/json/jRoutes?api_key=${testKey}`)
    done()
  })

  it('should throw an error if passed an invalid query param', done => {
    assert.throws(function() {
      wmata.renderQueryUrl({
        queryType: 'ruotes'
      }, testKey)
    }, /Ohnoes/)
    done()
  })
})

// describe('renderQueryUrl', () => {
//   const renderQueryUrl = require('../wmata').renderQueryUrl
//   let apiKey = 'secret'
//
//   it('should return a nice query string URL', done => {
//     let params = {
//       url: 'https://test.test/api',
//       key1: 'value1',
//       key2: 'value2',
//       key3: 'value3'
//     }
//     assert.equal(renderQueryUrl(params, apiKey),
//       `https://test.test/api?key1=value1&key2=value2&key3=value3&api_key=secret`)
//
//     assert.equal(renderQueryUrl({
//       url: 'https://api.wmata.com/Bus.svc/json/jBusPositions',
//       Lat: 38.8690011,
//       Lon: -77.0544217,
//       Radius: 500
//     }, apiKey),
//     'https://api.wmata.com/Bus.svc/json/jBusPositions?Lat=38.8690011&Lon=-77.0544217&Radius=500&api_key=secret')
//
//     done() // why is this needed here but not below?
//   })
//   it('should render query URLs that have no parameters (except API key)', (done) => {
//     assert.equal(renderQueryUrl({
//       url: 'https://api.wmata.com/Bus.svc/json/jRoutes'
//     }, apiKey), 'https://api.wmata.com/Bus.svc/json/jRoutes?api_key=secret')
//     done()
//   })
// })
//
// const wmata = require('../wmata')
// const wmataCache = require('../wmata_cache')
//
// describe('WMATA API wrapper', () => {
//   it('should have dummy ping function that returns "pong"', done => {
//     assert.equal(typeof(wmata.ping()), 'string')
//     assert.equal(wmata.ping(), 'pong')<commit_msg>Add test for WMATA wrapper class's addTimestamp method<commit_after>'use strict'

const assert = require('chai').assert
const Wmata = require('../captran-wmata')
var wmata = new Wmata()

describe('WMATA wrapper class\'s renderQueryUrl method', () => {
  let query = 'stops'
  let params = {
    queryType: query,
    key1: 'value1',
    key2: 'value2',
    key3: 'value3'
  }
  let testKey = 'abcde'

  it('should return a nice query URL', done => {
    let expectedBaseUrl = 'https://api.wmata.com/Bus.svc/json/' + 'jStops'
    assert.equal(wmata.renderQueryUrl(params, testKey),
      expectedBaseUrl + `?key1=value1&key2=value2&key3=value3&api_key=${testKey}`)

    assert.equal(wmata.renderQueryUrl({
      queryType: 'busPositions',
      Lat: 38.8690011,
      Lon: -77.0544217,
      Radius: 500
    }, testKey),
    `https://api.wmata.com/Bus.svc/json/jBusPositions?Lat=38.8690011&Lon=-77.0544217&Radius=500&api_key=${testKey}`)

    done()
  })

  it('should render query URLs that have no parameters (except API key)', done => {
    assert.equal(wmata.renderQueryUrl({
      queryType: 'routes'
    }, testKey), `https://api.wmata.com/Bus.svc/json/jRoutes?api_key=${testKey}`)
    done()
  })

  it('should throw an error if passed an invalid query param', done => {
    assert.throws(function() {
      wmata.renderQueryUrl({
        queryType: 'ruotes'
      }, testKey)
    }, /Ohnoes/)
    done()
  })
})

describe('WMATA API wrapper class\'s addTimestamp method', () => {
  it('should add a timestamp to an object', done => {
    let timeless = wmata.addTimestamp({})
    let now = Date.now()
    assert.isAtLeast(timeless.timestamp, now - 20)
    assert.isAtMost(timeless.timestamp, now + 200)
    done()
  })
  it(`should add a time-to-live (TTL, i.e. expiration) to an object whose queryType is ${Wmata.REAL_TIME_QUERIES[0]}`, done => {
    let timed = wmata.addTimestamp({ [Wmata.REAL_TIME_QUERIES[0]]: 'stuff' })
    assert.isOk(timed.ttl)
    assert.equal(timed.ttl, Wmata.TTL)
    done()
  })
})

// const wmata = require('../wmata')
// const wmataCache = require('../wmata_cache')
//
// describe('WMATA API wrapper', () => {
//   it('should have dummy ping function that returns "pong"', done => {
//     assert.equal(typeof(wmata.ping()), 'string')
//     assert.equal(wmata.ping(), 'pong')
{'fraction_non_alphanumeric': 0.1807887543928153, 'fraction_numerical': 0.03299492385786802, 'mean_word_length': 3.0594294770206023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3341088', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1827, 'n_words': 357}