 {expect} = require 'chai'
+{Connection} = require '../../lib/client'
 {Doc}    = require '../../lib/client/doc'
 textType = require('ot-text').type
 

      @doc.unsubscribe =>
        expect(@doc.subscribed).to.be.false
        done()
      sendMessage c: 'notes', d: 'music', a: 'unsub'

    it 'emits unsubscribe', (done)->
      @doc.on('unsubscribe', done)
      sendMessage c: 'notes', d: 'music', a: 'unsub'

    it 'sends unsubscription message', ->
      @doc.unsubscribe()
      expect(connection.sent[0]).to.deep.equal {c: 'notes', d: 'music', a: 'unsub'}

    it 'calls subscribe callbacks', (done)->
      @doc.subscribe(done)
      @doc.unsubscribe()
      sendMessage c: 'notes', d: 'music', a: 'unsub'


  describe '#fetch', ->

    it 'sends fetch message', ->
      @doc.fetch()
      expect(connection.sent[0]).to.deep.equal {c: 'notes', d: 'music', a: 'fetch'}

    it 'sets snapshot', ->
      @doc.fetch()
      sendMessage c: 'notes', d: 'music', a: 'fetch', data: { data: 'cool' , v: 0, type: 'text'}
      expect(@doc.snapshot).to.equal 'cool'

    it 'gets ready', (done)->

        @doc.create textType, 'a note on music'
        @doc.flush()
        expect(@doc.state).to.equal 'floating'
        @doc._onMessage {c: 'notes', d: 'music', a: 'ack', error: 'rejected'}
        expect(@doc.state).to.be.null

      it "when we're ready and the server rejects the op"

      it "when the doc is floating and the document already exists on the server"

    describe 'operation', ->

