       done()
 
   it 'should return 404 for status=Slettet', (done) ->
-    doc = data.getTrip('DNT', 'Slettet')
-    req.get(url(doc._id)).expect(404, done)
-
-  it 'should return document when status=Offentlig and tilbyder=DNT', (done) ->
-    req.get(url(trip._id)).expect(200).end (err, res) ->
-      assert.ifError(err)
-      assert.deepEqual res.body, trip
-      done()
-
-  it 'should return document when status=Privat and tilbyder=DNT', (done) ->
-    doc = data.getTrip('DNT', 'Privat')
-    req.get(url(doc._id)).expect(200).end (err, res) ->
-      assert.ifError(err)
-      assert.deepEqual res.body, doc
-      done()
-
-  it 'should return document when status=Offentlig and tilbyder=TURAPP', (done) ->
-    doc = data.getTrip('TURAPP', 'Offentlig')
-    delete doc.privat
-    req.get(url(doc._id)).expect(200).end (err, res) ->
-      assert.ifError(err)
-      assert.deepEqual res.body, doc
-      done()
-
-  it 'should return 404 for status=Privat and tilbyder TURAPP', (done) ->
-    doc = data.getTrip('TURAPP', 'Privat')
-    req.get(url(doc._id)).expect(404, done)
+    req.get(url('52d83333ea10e0fc14c9cecf')).expect(404, done)
+
+  it 'should return document when status=Offentlig and tilbyder=DNT for DNT', (done) ->
+    req.get(url('52407fb375049e5615000469')).expect(200).end (err, res) ->
+      assert.ifError(err)
+      assert.equal res.body.tilbyder, 'DNT'
+      assert.equal res.body.status, 'Offentlig'
+      assert.equal res.body.navn, 'c818b09c3c51eb6f6f4ddc4c87a2a4f3'
+      assert.deepEqual res.body.privat, secret: '21122df6e414ac844a6e80de1faf4871'
+      done()
+
+  it 'should return document when status=Kladd and tilbyder=DNT for DNT', (done) ->
+    req.get(url('52d65048dfb20d629566667c')).expect(200).end (err, res) ->
+      assert.ifError(err)
+      assert.equal res.body.tilbyder, 'DNT'
+      assert.equal res.body.status, 'Kladd'
+      assert.equal res.body.navn, '30f832f2a56d8ccf2e6356e0556d545f'
+      assert.deepEqual res.body.privat, secret: '481d53830054097e48833a810827fc09'
+      done()
+
+  it 'should return document when status=Privat and tilbyder=DNT for DNT', (done) ->
+    req.get(url('52d65b2544db971c94b2d949')).expect(200).end (err, res) ->
+      assert.ifError(err)
+      assert.equal res.body.tilbyder, 'DNT'
+      assert.equal res.body.status, 'Privat'
+      assert.equal res.body.navn, '46793be9a59a0582d6c12376b4abb145'
+      assert.deepEqual res.body.privat, secret: '4b65e2c69472621d4b33dd0e0bd66205'
+      done()
+
+  it 'should return document when status=Offentlig and tilbyder=DNT for not DNT', (done) ->
+    req.get(url('52407fb375049e5615000469', true)).expect(200).end (err, res) ->
+      assert.ifError(err)
+      assert.equal res.body.navn, 'c818b09c3c51eb6f6f4ddc4c87a2a4f3'
+      assert.equal typeof res.body.privat, 'undefined'
+      done()
+
+  it 'should not return document when status=Kladd and tilbyder=DNT for not DNT', (done) ->
+    req.get(url('52d65048dfb20d629566667c', true)).expect(404, done)
+
+  it 'should not return document when status=Privat and tilbyder=DNT for not DNT', (done) ->
+    req.get(url('52d65b2544db971c94b2d949', true)).expect(404, done)
 
   it 'should set X-Cache-Hit header for cache hit', (done) ->
-    req.get(url(trip._id)).expect(200).end (err, res) ->
-      assert.ifError(err)
-      req.get(url(trip._id)).expect(200).expect('X-Cache-Hit', 'true', done)
+    req.get(url('52407fb375049e5615000296')).expect(200).end (err, res) ->
+      assert.ifError(err)
+      req.get(url('52407fb375049e5615000296')).expect(200).expect('X-Cache-Hit', 'true', done)
 
   it 'should set last modified header correctly', (done) ->
-    time = new Date(trip.endret).toUTCString()
-    req.get('/turer/' + trip._id + '?api_key=dnt')
+    req.get(url('52407fb375049e561500038d'))
       .expect(200)
-      .expect('Last-Modified', time, done)
+      .expect('Last-Modified', 'Mon, 16 Dec 2013 14:20:19 GMT', done)
 
   it 'should set Etag header correctly', (done) ->
-    req.get('/turer/' + trip._id + '?api_key=dnt')
-      .expect(200)
-      .end (err, res) ->
-        assert.ifError(err)
-        assert.equal typeof res.header.etag, 'string'
-        done()
-
-  it 'should return 403 when provided with current valid Etag', (done) ->
-    req.get('/turer/' + trip._id + '?api_key=dnt').expect(200).end (err, res) ->
-      assert.ifError(err)
-      req.get('/turer/' + trip._id + '?api_key=dnt')
-        .set('if-none-match', res.header.etag)
-        .expect(304, done)
+    req.get(url('52407fb375049e5615000304')).expect(200).end (err, res) ->
+        assert.ifError(err)
+        assert.equal res.header.etag, 'd23c2905203cbbf4ad3cdb9367da5983'
+        done()
+
+  # Etag / checksum
+  it 'should return 403 when provided with currently valid Etag', (done) ->
+    req.get(url('52407fb375049e56150001bf'))
+      .set('if-none-match', 'ddbe37ead8031e1fe21fc7d51b3920cd')
+      .expect(304, done)
+
+  it 'should return document for invalid Etag', (done) ->
+    req.get(url('52407fb375049e56150001bf'))
+      .set('if-none-match', '1606472306e24cdaf66d11ae808176cb')
+      .expect(200).end (err, res) ->
+        assert.ifError(err)
+        assert.equal res.body.navn, 'd119ff9ec3e34ae5194717b4f228c8bb'
+        done()
 
   it 'should return documents without checksum', (done) ->
-    doc = data.get 'turer', false, 37
-    req.get("/turer/#{doc._id}?api_key=dnt").expect(200).end (err, res) ->
-      assert.ifError(err)
-      assert.deepEqual res.body, doc
+    req.get(url('52d65048dfb20d629566667c')).expect(200).end (err, res) ->
+      assert.ifError(err)
+      assert.equal res.body.navn, '30f832f2a56d8ccf2e6356e0556d545f'
+      assert.equal typeof res.body.checksum, 'undefined'
       done()
 
   it 'should ignore etags for documents without checksum', (done) ->
-    doc = data.get 'turer', false, 37
-    req.get("/turer/#{doc._id}?api_key=dnt").set('if-none-match', 'foobar')
+    req.get(url('52d65048dfb20d629566667c')).set('if-none-match', 'ffa286997064c42f53861d4c945e2815')
       .expect(200).end (err, res) ->
         assert.ifError(err)
-        assert.deepEqual res.body, doc
+        assert.equal res.body.navn, '30f832f2a56d8ccf2e6356e0556d545f'
+        assert.equal typeof res.body.checksum, 'undefined'
+        done()
+
+  # Modified / endret
+  it 'should return 403 when provided with equal modified since date', (done) ->
+    req.get(url('52407fb375049e56150001bf'))
+      .set('if-modified-since', '2013-12-16T14:25:47.966Z')
+      .expect(304, done)
+
+  it 'should return 403 when provided with newer modified since date', (done) ->
+    req.get(url('52407fb375049e56150001bf'))
+      .set('if-modified-since', '2014-12-16T14:25:47.966Z')
+      .expect(304, done)
+
+  it 'should return document for outdated modified since date', (done) ->
+    req.get(url('52407fb375049e56150001bf'))
+      .set('if-modified-since', '2012-12-16T14:25:47.966Z')
+      .expect(200).end (err, res) ->
+        assert.ifError(err)
+        assert.equal res.body.navn, 'd119ff9ec3e34ae5194717b4f228c8bb'
+        done()
+
+  it 'should return newly created document', (done) ->
+    doc = JSON.parse(JSON.stringify(steder[51]))
+    delete doc._id
+    delete doc.tilbyder
+    delete doc.endret
+    delete doc.checksum
+
+    req.post('/steder/?api_key=dnt').send(doc).expect(201).end (err, res) ->
+      assert.ifError(err)
+      req.get(url(res.body.document._id)).expect(200).end (err, res) ->
+        assert.ifError(err)
+        assert.deepEqual res.body[key], val for val, key in doc
         done()
 
   it 'should return newly created document (with id)', (done) ->
-    doc = _id: new ObjectID().toString(), name: 'kristian'
-    req.post('/turer?api_key=dnt').send(doc).expect(201).end (err, res) ->
+    doc = JSON.parse(JSON.stringify(steder[51]))
+    doc._id = new ObjectID()
+    delete doc.tilbyder
+    delete doc.endret
+    delete doc.checksum
+
+    req.post('/steder/?api_key=dnt').send(doc).expect(201).end (err, res) ->
       assert.ifError(err)
       assert.equal res.body.document._id, doc._id
-      req.get('/turer/' + doc._id + '?api_key=dnt')
-        .expect(200)
-        .end (err, res) ->
-          assert.ifError(err)
-          assert.equal res.body.name, doc.name
-          done()
+      req.get(url(doc._id)).expect(200).end (err, res) ->
+        assert.ifError(err)
+        assert.deepEqual res.body[key], val for val, key in doc
+        done()
 
   it 'should handle rapid fire', (done) ->
     this.timeout(5000)
 
-    count = 0
-    limit = data.get('turer', true).length
-    for d in data.get('turer', true)
-      req.get(url(d._id)).end (err, res) ->
-        assert.ifError(err)
-        done() if ++count is limit
+    limit = 100
+    for i in [0..limit]
+      req.get(url(steder[i]._id)).expect(200).end (err, res) ->
+        assert.ifError(err)
+        done() if --limit is 0
 
 describe 'HEAD', ->
   it 'should only get http header for document resource', (done) ->
-    req.head(url(trip._id)).expect(200)
-      .expect('X-Cache-Hit', /^(ture|false)$/)
-      .expect('ETag', /^[0-9a-f]{32}$/)
-      .expect('Last-Modified', /^[a-zA-Z0-9 ,:]+$/)
+    req.head(url('52407fb375049e561500047c')).expect(200)
+      .expect('X-Cache-Hit', 'false')
+      .expect('ETag', 'bfcec6b8b527a8d599ecfcbbea54a7f3')
+      .expect('Last-Modified', 'Mon, 16 Dec 2013 14:34:51 GMT')
       .end (err, res) ->
         assert.ifError(err)
         assert.deepEqual(res.body, {})


request   = require 'supertest'
assert    = require 'assert'
data      = require('./util/data')
ObjectID  = require('mongodb').ObjectID

req = trip = poi = null

before ->
  app = module.parent.exports.app
  req = request(app)

beforeEach ->
  trip  = data.getTrip('DNT', 'Offentlig')
  poi   = data.get('steder')

url = (id, type) -> '/' + (type or 'turer') + '/' + id + '?api_key=dnt'

describe 'OPTIONS', ->
  it 'should return allowed http methods', (done) ->
    req.options(url(trip._id)).expect(200)
      .expect('Access-Control-Allow-Methods', 'HEAD, GET, PUT, PATCH, DELETE', done)

describe 'GET', ->


describe 'POST', ->
  it 'should not be an allowed method', (done) ->
    req.post(url('52407fb375049e561500008f')).expect 405, done

describe 'PUT', ->
  it 'should not be implmented', (done) ->
    req.put(url('52407fb375049e561500008f')).expect 501, done

describe 'PATCH', ->
  it 'should not be implmented', (done) ->
    req.patch(url('52407fb375049e561500008f')).expect 501, done

describe 'DELETE', ->
  it 'should not be implmented', (done) ->
    req.del(url('52407fb375049e561500008f')).expect 501, done

