<commit_before>#
# test/api/tests.coffee
#
# Copyright (c) 2012 <NAME> <<EMAIL>>
# MIT Licensed
#
dork = require 'dork'
should = require 'should'
require '../options'




request = (options={}, callback) ->
  if process.env.C9_USER?
    #options.host ?= "#{process.env.C9_PROJECT}.#{process.env.C9_USER}.c9.io"
    options.port ?= process.env.C9_PORT
  else
    options.port ?= 3003
  options.host ?= 'localhost'
  options.path ?= '/'
  options.method ?= 'GET'
  options.headers ?= {}
  options.headers.Connection ?= 'close'
  
  http = require 'http'
  req = http.request options, (res) ->
    data = ''
    res.setEncoding 'utf-8'
    res.on 'data', (chunk) ->
      data += chunk
    res.on 'end', () ->
      callback null, res, data
    res.on 'error', (error) ->
      callback error, res, data
  req.end JSON.stringify options.data



describe 'Test Submission', ->
  server = undefined
  
  
  before_all (done) ->
    server = require '../../lib/server'
    server.main.start undefined, done
  
  
  it 'should accept source', (done) ->
    
    request
      path: '/api/tests'
      method: 'POST'
      headers:
        'Content-Type': 'application/json'
      data:
        source: 'foo'
      
      (err, res, data) ->
        data = JSON.parse data
        
        res.statusCode.should.equal 200
        data.should.eql id: 1
        
        done()
  
  
  it 'should fail with badly formatted requests', (done) ->
    
    request
      path: '/api/tests'
      method: 'POST'
      headers:
        'Content-Type': 'application/json'
      data: {}
      
      (err, res, data) ->
        if err then throw err
        
        res.statusCode.should.equal 400
        data.should.equal 'Missing required argument "source".'
        
        done()
  
  
  
  after_all ->
    server.main.end()
  




if require.main is module then dork.run()<commit_msg>Cleaned it up further by moving it all onto one line. (and it fits within 80 chars!)<commit_after>#
# test/api/tests.coffee
#
# Copyright (c) 2012 <NAME> <<EMAIL>>
# MIT Licensed
#
dork = require 'dork'
should = require 'should'
require '../options'




request = (options={}, callback) ->
  options.host ?= 'localhost'
  options.port ?= if not process.env.C9_PORT? then 3003 else process.env.C9_PORT
  options.path ?= '/'
  options.method ?= 'GET'
  options.headers ?= {}
  options.headers.Connection ?= 'close'
  
  http = require 'http'
  req = http.request options, (res) ->
    data = ''
    res.setEncoding 'utf-8'
    res.on 'data', (chunk) ->
      data += chunk
    res.on 'end', () ->
      callback null, res, data
    res.on 'error', (error) ->
      callback error, res, data
  req.end JSON.stringify options.data



describe 'Test Submission', ->
  server = undefined
  
  
  before_all (done) ->
    server = require '../../lib/server'
    server.main.start undefined, done
  
  
  it 'should accept source', (done) ->
    
    request
      path: '/api/tests'
      method: 'POST'
      headers:
        'Content-Type': 'application/json'
      data:
        source: 'foo'
      
      (err, res, data) ->
        data = JSON.parse data
        
        res.statusCode.should.equal 200
        data.should.eql id: 1
        
        done()
  
  
  it 'should fail with badly formatted requests', (done) ->
    
    request
      path: '/api/tests'
      method: 'POST'
      headers:
        'Content-Type': 'application/json'
      data: {}
      
      (err, res, data) ->
        if err then throw err
        
        res.statusCode.should.equal 400
        data.should.equal 'Missing required argument "source".'
        
        done()
  
  
  
  after_all ->
    server.main.end()
  




if require.main is module then dork.run()
{'fraction_non_alphanumeric': 0.1319693094629156, 'fraction_numerical': 0.010485933503836318, 'mean_word_length': 1.7581100141043724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, 'https://': 0, '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': '4854309', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1225, 'n_words': 314}