diff options
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/services/bl/feedblSpec.coffee | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/js/tests/services/bl/feedblSpec.coffee b/js/tests/services/bl/feedblSpec.coffee index c8ba1ec34..2b355d871 100644 --- a/js/tests/services/bl/feedblSpec.coffee +++ b/js/tests/services/bl/feedblSpec.coffee @@ -32,10 +32,11 @@ describe 'FeedBl', -> @persistence = { setFeedRead: @setFeedReadSpy getItems: @getItemsSpy + createFeed: -> } beforeEach inject (@FeedBl, @FeedModel, @ItemModel, @FeedType, - @ShowAll, @ActiveFeed) => + @ShowAll, @ActiveFeed, @_ExistsError) => @ShowAll.setShowAll(false) @ActiveFeed.handle({type: @FeedType.Folder, id:0}) @@ -213,4 +214,97 @@ describe 'FeedBl', -> link: 'test.com' @FeedModel.add(item2) - expect(@FeedBl.getFeedLink(4)).toBe('test.com')
\ No newline at end of file + expect(@FeedBl.getFeedLink(4)).toBe('test.com') + + + + it 'should not create a feed if it already exists', => + item1 = {urlHash: hex_md5('john')} + @FeedModel.add(item1) + + expect => + @FeedBl.create('john') + .toThrow(new @_ExistsError()) + + expect => + @FeedBl.create('johns') + .not.toThrow(new @_ExistsError()) + + + it 'should not create feeds that are empty', => + expect => + @FeedBl.create(' ') + .toThrow(new Error()) + + + it 'should create a feed before theres a response from the server', => + @FeedBl.create('johns') + expect(@FeedModel.size()).toBe(1) + + + it 'should set a title and an url hash to the newly crated feed', => + url = 'www.google.de' + @FeedBl.create(url) + hash = hex_md5(url) + + feed = @FeedModel.getByUrlHash(hash) + + expect(feed.title).toBe('google.de') + expect(feed.url).toBe(url) + expect(feed.urlHash).toBe(hash) + + + it 'should transform urls correctly', => + urls = [ + 'www.google.de' + 'www.google.de/' + 'google.de' + 'http://google.de' + 'http://www.google.de/' + ] + for url in urls + @FeedModel.clear() + @FeedBl.create(url) + hash = hex_md5(url) + feed = @FeedModel.getByUrlHash(hash) + expect(feed.title).toBe('google.de') + + + it 'should make a create feed request', => + @persistence.createFeed = jasmine.createSpy('add feed') + + @FeedBl.create(' johns ') + expect(@persistence.createFeed).toHaveBeenCalledWith('johns', 0, + jasmine.any(Function)) + + + it 'should call the onSuccess function on response status ok', => + onSuccess = jasmine.createSpy('Success') + @persistence.createFeed = jasmine.createSpy('add feed') + @persistence.createFeed.andCallFake (folderName, parentId, success) => + response = + status: 'ok' + success(response) + + @FeedBl.create(' johns ', 0, onSuccess) + + expect(onSuccess).toHaveBeenCalled() + + + it 'should call the handle a response error when creating a folder', => + onSuccess = jasmine.createSpy('Success') + onFailure = jasmine.createSpy('Failure') + @persistence.createFeed = jasmine.createSpy('add feed') + @persistence.createFeed.andCallFake (folderName, parentId, success) => + @response = + status: 'error' + msg: 'this is an error' + success(@response) + + @FeedBl.create(' johns ', 0, onSuccess, onFailure) + + expect(onSuccess).not.toHaveBeenCalled() + expect(onFailure).toHaveBeenCalled() + + expect(@FeedModel.getByUrlHash(hex_md5('johns')).error).toBe( + @response.msg)
\ No newline at end of file |