eventric = require 'eventric'
TingoDbStore = require './tingodb_store'
TingoDB = require('tingodb')().Db

describe 'TingoDB Store Adapter Feature', ->
  tingoDb = null
  tingoDbStore = null
  exampleContext = null

  beforeEach (done) ->
    tingoDb = new TingoDB '.tingodb/eventric', {}
    tingoDb.dropDatabase ->

      eventric.addStore 'tingodb', TingoDbStore
      eventric.set 'default domain events store', 'tingodb'


      tingoDb.collection 'ExampleContext.Projection.ExampleProjection', (err, collection) ->
        collection.insert some: 'thing'

        exampleContext = eventric.context 'ExampleContext'
          .addProjection 'ExampleProjection', ->
            stores: ['tingodb']

        done()


  it 'should clear the projection upon initializing', (done) ->
    exampleContext.initialize ->
      exampleContext.getProjectionStore 'tingodb', 'ExampleProjection', (err, projection) ->
        projection.find (err, cursor) ->
          cursor.toArray (err, results) ->
            done()
