@missive/ndex
Version:
Ndex is an indexedDB wrapper
62 lines (47 loc) • 2.38 kB
text/coffeescript
Adapter = require('../../lib/ndex/adapter')
Connection = require('../../lib/ndex/connection')
{ simple, expect } = require('../spec_helper.coffee')
describe 'Adapter', ->
beforeEach ->
= new Connection('foo', {})
= new Adapter()
it 'defines connection API methods', ->
connectionMethods = (k for k, v of when typeof v is 'function')
for method in connectionMethods
expect([method]).to.be.defined
it 'defines object stores namespace', ->
.proxyObjectStoresNamespace(['foo', 'bar'])
expect(.foo).to.be.defined
for method in .getMethodsForObjectStore()
expect(.foo[method]).to.be.defined
it 'defines index methods', ->
methods = .index('foo', 'bar')
expect(Object.keys(methods)).to.deep.equal(.getMethodsForIndex())
describe '#handleMethod', ->
beforeEach -> simple.mock(, 'handleMethod', ->)
it 'proxy connection', ->
.add('foo', { id: 1 })
expect(.handleMethod.calls.length).to.equal(1)
expect(.handleMethod.calls[0].args).to.deep.equal(['add', 'foo', { id: 1 }])
.index('foo', 'bar').get({ id: 1 })
expect(.handleMethod.calls.length).to.equal(2)
expect(.handleMethod.calls[1].args).to.deep.equal(['get', 'foo', { id: 1 }, 'bar'])
describe '#handleLog', ->
describe 'when handler is console', ->
beforeEach ->
simple.mock(console, 'groupCollapsed', ->)
simple.mock(console, 'log', ->)
simple.mock(console, 'groupEnd', ->)
.handler = console
it 'group-logs to console', ->
.handleLog({ type: 'transaction.start', data: 'Group' })
.handleLog({ type: 'request', data: 'Log 1' })
.handleLog({ type: 'request', data: 'Log 2' })
.handleLog({ type: 'transaction.end' })
expect(console.groupCollapsed.calls.length).to.equal(1)
expect(console.groupCollapsed.calls[0].arg).to.equal('Group')
expect(console.log.calls.length).to.equal(2)
expect(console.log.calls[0].arg).to.equal('Log 1')
expect(console.log.calls[1].arg).to.equal('Log 2')
expect(console.groupEnd.calls.length).to.equal(1)
expect(console.groupEnd.calls[0].arg).to.equal()