Skip to content

Commit

Permalink
More specs for base service
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko committed Jan 27, 2014
1 parent aa2e352 commit b783356
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/coffee/services/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class BaseService
###
fetch: ->
deferred = Q.defer()
@_rest @_projectEndpoint, (e, r, b)->
@_rest.GET @_projectEndpoint, (e, r, b)->
# TODO: wrap / handle responses generally
if e
deferred.reject e
else
Expand Down
24 changes: 22 additions & 2 deletions src/spec/services/base.spec.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Q = require('q')
BaseService = require('../../lib/services/base')

describe 'BaseService', ->

beforeEach ->
@restMock =
config: {}
GET: ->
GET: (endpoint, callback)->
POST: ->
PUT: ->
DELETE: ->
Expand All @@ -20,4 +21,23 @@ describe 'BaseService', ->
expect(base).toBeDefined()
expect(base._projectEndpoint).toBe '/'

xit 'should return promise on fetch', ->
it 'should return promise on fetch', ->
base = new BaseService @restMock
promise = base.fetch()
expect(Q.isPromise(promise)).toBe true

it 'should resolve the promise on fetch', (done)->
spyOn(@restMock, 'GET').andCallFake((endpoint, callback)-> callback(null, {statusCode: 200}, '{"foo": "bar"}'))
base = new BaseService @restMock
base.fetch().then (result)->
expect(result).toEqual foo: 'bar'
done()

it 'should reject the promise on fetch', (done)->
spyOn(@restMock, 'GET').andCallFake((endpoint, callback)-> callback('foo', null, null))
base = new BaseService @restMock
base.fetch().then (result)->
expect(result).not.toBeDefined()
.fail (e)->
expect(e).toBe 'foo'
done()

0 comments on commit b783356

Please sign in to comment.