 ObjectID  = require('mongodb').ObjectID
 request   = require 'supertest'
 assert    = require 'assert'
-data      = require('./util/data')
-Generator = require('./util/fakeData').Generator
-
-req = cache = trip = poi = null
+
+req = cache = steder = null
 
 before ->
-  app = module.parent.exports.app
-  req = request(app)
-  cache = app.get 'cache'
-
-beforeEach ->
-  trip = data.get('turer')
-  poi = data.get('steder')
+  app     = module.parent.exports.app
+  steder  = module.parent.exports.steder
+  req     = request(app)
+  cache   = app.get 'cache'
 
 describe 'OPTIONS', ->
   it 'should return allowed http methods', (done) ->
-    req.options('/turer?api_key=dnt').expect(200)
+    req.options('/steder?api_key=dnt').expect(200)
       .expect('Access-Control-Allow-Methods', 'HEAD, GET, POST, PATCH, PUT', done)
 
 describe 'GET', ->
-  url = '/turer?api_key=dnt'
+  url = '/steder?api_key=dnt'
 
   it 'should get the collection', (done) ->
     req.get(url)

      done()

  it 'should warn about missing status field', (done) ->
    doc = new Generator('turer').gen exclude: ['status']
    req.post('/turer?api_key=dnt').send(doc).expect(201).end (err, res) ->
      assert.ifError(err)
      assert res.body.warnings, [{
        resource: 'turer'
        field: 'status'
        value: 'Kladd'
        code: 'missing_field'

      assert.equal typeof res.body.document._id, 'string'

      id = new ObjectID(res.body.document._id)
      cache.getCol('steder').findOne _id: id, (err, d) ->
        assert.ifError(err)
        assert.equal typeof d, 'object'
        assert.deepEqual d[key], val for key, val of doc
        done()

  it 'should override tilbyder, endret and checksum fields', (done) ->
    doc.tilbyder = 'MINAPP'
    doc.endret   = new Date().toISOString()
    doc.checksum = '332dcf1830ec8e2c9bdc574b29515047'

    req.post(url).send(doc).expect(201).end (err, res) ->
      assert.ifError(err)

      doc._id = new ObjectID(res.body.document._id)
      cache.getCol('steder').findOne _id: doc._id, (err, d) ->
        assert.ifError(err)

        ignore = ['tilbyder', 'endret', 'checksum']
        assert.notEqual d[key], val for key, val of doc when key in ignore
        assert.deepEqual d[key], val for key, val of doc when key not in ignore
        done()

  it 'should handle rapid requests to collection', (done) ->
    this.timeout(5000)

    count = 100
    for i in [0..count]
      doc = JSON.parse(JSON.stringify(steder[i]))
      delete doc._id
      delete doc.tilbyder
      delete doc.endret
      delete doc.checksum

      req.post(url).send(doc).expect(201).end (err, res) ->
        assert.ifError(err)
        assert.equal res.body.count, 1
