summaryrefslogtreecommitdiffstats
path: root/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/build/tests/services/businesslayer/feedbusinesslayerSpec.js')
-rw-r--r--js/build/tests/services/businesslayer/feedbusinesslayerSpec.js478
1 files changed, 478 insertions, 0 deletions
diff --git a/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js b/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js
new file mode 100644
index 000000000..592b90057
--- /dev/null
+++ b/js/build/tests/services/businesslayer/feedbusinesslayerSpec.js
@@ -0,0 +1,478 @@
+// Generated by CoffeeScript 1.6.3
+/*
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+(function() {
+ describe('FeedBusinessLayer', function() {
+ var _this = this;
+ beforeEach(module('News'));
+ beforeEach(module(function($provide) {
+ _this.setFeedReadSpy = jasmine.createSpy('setFeedRead');
+ _this.getItemsSpy = jasmine.createSpy('Get Items');
+ _this.persistence = {
+ setFeedRead: _this.setFeedReadSpy,
+ getItems: _this.getItemsSpy,
+ createFeed: function() {},
+ test: 'feedbusinesslayer'
+ };
+ _this.imagePath = jasmine.createSpy('imagePath');
+ _this.utils = {
+ imagePath: _this.imagePath
+ };
+ $provide.value('Persistence', _this.persistence);
+ $provide.value('Utils', _this.utils);
+ }));
+ beforeEach(inject(function(FeedBusinessLayer, FeedModel, ItemModel, FeedType, ShowAll, ActiveFeed, _ExistsError, $timeout, NewestItem, $rootScope) {
+ _this.FeedBusinessLayer = FeedBusinessLayer;
+ _this.FeedModel = FeedModel;
+ _this.ItemModel = ItemModel;
+ _this.FeedType = FeedType;
+ _this.ShowAll = ShowAll;
+ _this.ActiveFeed = ActiveFeed;
+ _this._ExistsError = _ExistsError;
+ _this.$timeout = $timeout;
+ _this.NewestItem = NewestItem;
+ _this.$rootScope = $rootScope;
+ _this.ShowAll.setShowAll(false);
+ return _this.ActiveFeed.handle({
+ type: _this.FeedType.Folder,
+ id: 0
+ });
+ }));
+ it('should delete feeds', function() {
+ var data;
+ data = null;
+ _this.$rootScope.$on('undoMessage', function(scope, data) {
+ return data = data;
+ });
+ _this.FeedModel.removeById = jasmine.createSpy('remove').andCallFake(function() {
+ return {
+ id: 3,
+ title: 'test'
+ };
+ });
+ _this.persistence.deleteFeed = jasmine.createSpy('deletequery');
+ _this.FeedBusinessLayer["delete"](3);
+ expect(_this.FeedModel.removeById).toHaveBeenCalledWith(3);
+ return expect(_this.persistence.deleteFeed).toHaveBeenCalledWith(3);
+ });
+ it('should return the number of unread feeds', function() {
+ var count;
+ _this.FeedModel.add({
+ id: 3,
+ unreadCount: 134,
+ url: 'a1'
+ });
+ count = _this.FeedBusinessLayer.getUnreadCount(3);
+ return expect(count).toBe(134);
+ });
+ it('should return all feeds of a folder', function() {
+ var feed1, feed2, feed3, feeds;
+ feed1 = {
+ id: 3,
+ unreadCount: 134,
+ url: 'a1',
+ folderId: 3
+ };
+ feed2 = {
+ id: 4,
+ unreadCount: 134,
+ url: 'a2',
+ folderId: 2
+ };
+ feed3 = {
+ id: 5,
+ unreadCount: 134,
+ url: 'a3',
+ folderId: 3
+ };
+ _this.FeedModel.add(feed1);
+ _this.FeedModel.add(feed2);
+ _this.FeedModel.add(feed3);
+ feeds = _this.FeedBusinessLayer.getFeedsOfFolder(3);
+ expect(feeds).toContain(feed1);
+ return expect(feeds).toContain(feed3);
+ });
+ it('should get the correct unread count for folders', function() {
+ var count;
+ _this.FeedModel.add({
+ id: 3,
+ unreadCount: 134,
+ folderId: 3,
+ url: 'a1'
+ });
+ _this.FeedModel.add({
+ id: 5,
+ unreadCount: 2,
+ folderId: 2,
+ url: 'a2'
+ });
+ _this.FeedModel.add({
+ id: 1,
+ unreadCount: 12,
+ folderId: 5,
+ url: 'a3'
+ });
+ _this.FeedModel.add({
+ id: 2,
+ unreadCount: 35,
+ folderId: 3,
+ url: 'a4'
+ });
+ count = _this.FeedBusinessLayer.getFolderUnreadCount(3);
+ return expect(count).toBe(169);
+ });
+ it('should not mark feed read when no highest item id', function() {
+ _this.FeedModel.add({
+ id: 5,
+ unreadCount: 2,
+ folderId: 2,
+ url: 'a1'
+ });
+ _this.persistence.setFeedRead = jasmine.createSpy('setFeedRead');
+ _this.FeedBusinessLayer.markRead(5);
+ return expect(_this.persistence.setFeedRead).not.toHaveBeenCalled();
+ });
+ it('should mark feed as read', function() {
+ var item1, item2;
+ _this.NewestItem.handle(25);
+ _this.ActiveFeed.handle({
+ type: _this.FeedType.Feed,
+ id: 5
+ });
+ _this.persistence.setFeedRead = jasmine.createSpy('setFeedRead');
+ _this.FeedModel.add({
+ id: 5,
+ unreadCount: 2,
+ folderId: 2,
+ url: 'a1'
+ });
+ item1 = {
+ id: 3,
+ feedId: 5,
+ guidHash: 'a3',
+ status: 0
+ };
+ _this.ItemModel.add(item1);
+ item1.setUnread();
+ item2 = {
+ id: 2,
+ feedId: 3,
+ guidHash: 'a3',
+ status: 0
+ };
+ _this.ItemModel.add(item2);
+ item2.setUnread();
+ _this.FeedBusinessLayer.markRead(5);
+ expect(_this.persistence.setFeedRead).toHaveBeenCalledWith(5, 25);
+ expect(_this.FeedModel.getById(5).unreadCount).toBe(0);
+ expect(item1.isRead()).toBe(true);
+ return expect(item2.isRead()).toBe(false);
+ });
+ it('should get the correct unread count for subscribtions', function() {
+ var count;
+ _this.FeedModel.add({
+ id: 3,
+ unreadCount: 134,
+ url: 'a1'
+ });
+ _this.FeedModel.add({
+ id: 5,
+ unreadCount: 2,
+ url: 'a2'
+ });
+ count = _this.FeedBusinessLayer.getAllUnreadCount();
+ return expect(count).toBe(136);
+ });
+ it('should return the correct number of feeds', function() {
+ var count;
+ _this.FeedModel.add({
+ id: 3,
+ unreadCount: 134,
+ url: 'a1'
+ });
+ _this.FeedModel.add({
+ id: 5,
+ unreadCount: 2,
+ url: 'a2'
+ });
+ count = _this.FeedBusinessLayer.getNumberOfFeeds();
+ return expect(count).toBe(2);
+ });
+ it('should be visible if its active', function() {
+ _this.ActiveFeed.handle({
+ type: _this.FeedType.Feed,
+ id: 3
+ });
+ return expect(_this.FeedBusinessLayer.isVisible(3)).toBe(true);
+ });
+ it('should be visible if show all is true', function() {
+ expect(_this.FeedBusinessLayer.isVisible(3)).toBe(false);
+ _this.ShowAll.setShowAll(true);
+ return expect(_this.FeedBusinessLayer.isVisible(3)).toBe(true);
+ });
+ it('should be visible if unreadcount bigger than 0', function() {
+ _this.FeedModel.add({
+ id: 2,
+ unreadCount: 134,
+ url: 'a1'
+ });
+ return expect(_this.FeedBusinessLayer.isVisible(2)).toBe(true);
+ });
+ it('should not move the feed to a new folder', function() {
+ _this.persistence.moveFeed = jasmine.createSpy('Move feed');
+ _this.FeedModel.add({
+ id: 2,
+ unreadCount: 134,
+ url: 'a1',
+ folderId: 3
+ });
+ _this.FeedBusinessLayer.move(2, 4);
+ expect(_this.persistence.moveFeed).toHaveBeenCalledWith(2, 4);
+ return expect(_this.FeedModel.getById(2).folderId).toBe(4);
+ });
+ it('should not move the feed to the same folder', function() {
+ _this.persistence.moveFeed = jasmine.createSpy('Move feed');
+ _this.FeedModel.add({
+ id: 2,
+ unreadCount: 134,
+ url: 'a1',
+ folderId: 3
+ });
+ _this.FeedBusinessLayer.move(2, 3);
+ return expect(_this.persistence.moveFeed).not.toHaveBeenCalled();
+ });
+ it('should set the show all setting', function() {
+ _this.persistence.userSettingsReadShow = jasmine.createSpy('Show All');
+ _this.FeedBusinessLayer.setShowAll(true);
+ return expect(_this.persistence.userSettingsReadShow).toHaveBeenCalled();
+ });
+ it('should set the hide read setting', function() {
+ _this.persistence.userSettingsReadHide = jasmine.createSpy('Hide Read');
+ _this.FeedBusinessLayer.setShowAll(false);
+ return expect(_this.persistence.userSettingsReadHide).toHaveBeenCalled();
+ });
+ it('should return all feeds', function() {
+ var item1, item2;
+ item1 = {
+ id: 2,
+ unreadCount: 134,
+ url: 'a1',
+ folderId: 3
+ };
+ item2 = {
+ id: 4,
+ unreadCount: 134,
+ url: 'a2',
+ folderId: 3
+ };
+ _this.FeedModel.add(item1);
+ _this.FeedModel.add(item2);
+ expect(_this.FeedBusinessLayer.getAll()).toContain(item1);
+ return expect(_this.FeedBusinessLayer.getAll()).toContain(item2);
+ });
+ it('should return if ShowAll is set', function() {
+ _this.persistence.userSettingsReadShow = jasmine.createSpy('Show All');
+ expect(_this.FeedBusinessLayer.isShowAll()).toBe(false);
+ _this.FeedBusinessLayer.setShowAll(true);
+ return expect(_this.FeedBusinessLayer.isShowAll()).toBe(true);
+ });
+ it('should return all feeds of a folder', function() {
+ var folders, item1, item2, item3;
+ item1 = {
+ id: 2,
+ unreadCount: 134,
+ url: 'a1',
+ folderId: 3
+ };
+ item2 = {
+ id: 4,
+ unreadCount: 134,
+ url: 'a2',
+ folderId: 2
+ };
+ item3 = {
+ id: 5,
+ unreadCount: 134,
+ url: 'a3',
+ folderId: 3
+ };
+ _this.FeedModel.add(item1);
+ _this.FeedModel.add(item2);
+ _this.FeedModel.add(item3);
+ folders = _this.FeedBusinessLayer.getFeedsOfFolder(3);
+ expect(folders).toContain(item1);
+ return expect(folders).toContain(item3);
+ });
+ it('should return the correct feed link', function() {
+ var item2;
+ item2 = {
+ id: 4,
+ unreadCount: 134,
+ url: 'a2',
+ folderId: 3,
+ link: 'test.com'
+ };
+ _this.FeedModel.add(item2);
+ return expect(_this.FeedBusinessLayer.getFeedLink(4)).toBe('test.com');
+ });
+ it('should not create a feed if it already exists', function() {
+ var item1;
+ item1 = {
+ url: 'http://john'
+ };
+ _this.FeedModel.add(item1);
+ expect(function() {
+ return _this.FeedBusinessLayer.create('john');
+ }).toThrow(new _this._ExistsError('Exists already'));
+ return expect(function() {
+ return _this.FeedBusinessLayer.create('johns');
+ }).not.toThrow(new _this._ExistsError('Exists already'));
+ });
+ it('should not create feeds that are empty', function() {
+ return expect(function() {
+ return _this.FeedBusinessLayer.create(' ');
+ }).toThrow(new Error('Url must not be empty'));
+ });
+ it('should create a feed before theres a response from the server', function() {
+ _this.FeedBusinessLayer.create('johns');
+ return expect(_this.FeedModel.size()).toBe(1);
+ });
+ it('should set a title and an url to the newly created feed', function() {
+ var feed, url;
+ url = 'www.google.de';
+ _this.FeedBusinessLayer.create(url);
+ feed = _this.FeedModel.getByUrl('http://' + url);
+ expect(feed.title).toBe('http://www.google.de');
+ expect(feed.url).toBe('http://' + url);
+ expect(feed.folderId).toBe(0);
+ expect(feed.unreadCount).toBe(0);
+ return expect(_this.imagePath).toHaveBeenCalledWith('core', 'loading.gif');
+ });
+ it('should not add http when it already is at the start of created feed', function() {
+ var feed, url;
+ url = 'https://www.google.de';
+ _this.FeedBusinessLayer.create(url);
+ feed = _this.FeedModel.getByUrl(url);
+ return expect(feed.url).toBe(url);
+ });
+ it('should make a create feed request', function() {
+ _this.persistence.createFeed = jasmine.createSpy('add feed');
+ _this.FeedBusinessLayer.create(' johns ');
+ return expect(_this.persistence.createFeed).toHaveBeenCalledWith('http://johns', 0, jasmine.any(Function));
+ });
+ it('should call the onSuccess function on response status ok', function() {
+ var onSuccess;
+ onSuccess = jasmine.createSpy('Success');
+ _this.persistence.createFeed = jasmine.createSpy('add feed');
+ _this.persistence.createFeed.andCallFake(function(folderName, parentId, success) {
+ _this.response = {
+ status: 'ok',
+ data: 'hi'
+ };
+ return success(_this.response);
+ });
+ _this.FeedBusinessLayer.create(' johns ', 0, onSuccess);
+ return expect(onSuccess).toHaveBeenCalledWith(_this.response.data);
+ });
+ it('should call the handle a response error when creating a folder', function() {
+ var onFailure, onSuccess;
+ onSuccess = jasmine.createSpy('Success');
+ onFailure = jasmine.createSpy('Failure');
+ _this.persistence.createFeed = jasmine.createSpy('add feed');
+ _this.persistence.createFeed.andCallFake(function(folderName, parentId, success) {
+ _this.response = {
+ status: 'error',
+ msg: 'this is an error'
+ };
+ return success(_this.response);
+ });
+ _this.FeedBusinessLayer.create(' johns ', 0, onSuccess, onFailure);
+ expect(onSuccess).not.toHaveBeenCalled();
+ expect(onFailure).toHaveBeenCalled();
+ return expect(_this.FeedModel.getByUrl('http://johns').error).toBe(_this.response.msg);
+ });
+ it('should mark a feed error as read by removing it', function() {
+ _this.FeedModel.add({
+ id: 3,
+ url: 'john'
+ });
+ _this.FeedBusinessLayer.markErrorRead('john');
+ expect(_this.FeedModel.size()).toBe(0);
+ return expect(_this.FeedModel.getByUrl('john')).toBe(void 0);
+ });
+ it('should not import google reader json', function() {
+ var imported, json;
+ _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
+ json = {
+ "test": "hi"
+ };
+ _this.FeedBusinessLayer.importGoogleReader(json);
+ imported = _this.FeedModel.getByUrl('http://owncloud/googlereader');
+ expect(imported.title).toBe('Google Reader');
+ expect(imported.folderId).toBe(0);
+ return expect(imported.unreadCount).toBe(0);
+ });
+ it('should not create a google reader feed if it already exists', function() {
+ var imported, json;
+ _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
+ _this.FeedModel.add({
+ id: 3,
+ url: 'http://owncloud/googlereader'
+ });
+ json = {
+ "test": "hi"
+ };
+ _this.FeedBusinessLayer.importGoogleReader(json);
+ imported = _this.FeedModel.getByUrl('http://owncloud/googlereader');
+ return expect(imported.folderId).not.toBeDefined();
+ });
+ return it('should create an import google reader request', function() {
+ var json, returned;
+ returned = {
+ data: {
+ feeds: [
+ {
+ id: 3,
+ url: 'hi'
+ }
+ ]
+ }
+ };
+ _this.persistence.getItems = jasmine.createSpy('importGoogleReader');
+ _this.persistence.importGoogleReader = jasmine.createSpy('importGoogleReader');
+ _this.persistence.importGoogleReader.andCallFake(function(data, onSuccess) {
+ _this.FeedModel.handle(returned.data.feeds);
+ return onSuccess(returned);
+ });
+ json = {
+ "test": "hi"
+ };
+ _this.FeedBusinessLayer.importGoogleReader(json);
+ expect(_this.persistence.importGoogleReader).toHaveBeenCalledWith(json, jasmine.any(Function));
+ expect(_this.persistence.getItems).toHaveBeenCalledWith(_this.FeedType.Feed, returned.data.feeds[0].id, 0);
+ expect(_this.ActiveFeed.getId()).toBe(returned.data.feeds[0].id);
+ return expect(_this.ActiveFeed.getType()).toBe(_this.FeedType.Feed);
+ });
+ });
+
+}).call(this);