// 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 . */ (function() { describe('Persistence', function() { var _this = this; beforeEach(module('News')); beforeEach(module(function($provide) { _this.req = { get: jasmine.createSpy('get'), "delete": jasmine.createSpy('delete'), post: jasmine.createSpy('post') }; _this.config = { itemBatchSize: 3 }; _this.feedLoading = { increase: jasmine.createSpy('feedLoading increase'), decrease: jasmine.createSpy('feedLoading decrease') }; $provide.value('Request', _this.req); $provide.value('Config', _this.config); $provide.value('FeedLoading', _this.feedLoading); })); beforeEach(inject(function(Persistence) { _this.Persistence = Persistence; })); /* ITEM CONTROLLER */ it('should send a autopaging request', function() { var expected, params; params = { data: { type: 2, id: 5, limit: _this.config.itemBatchSize, offset: 3 }, onSuccess: function() {} }; _this.Persistence.getItems(params.data.type, params.data.id, params.data.offset, params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function), data: { type: 2, id: 5, limit: _this.config.itemBatchSize, offset: 3 } }; return expect(_this.req.get).toHaveBeenCalledWith('news_items', expected); }); it('send a correct star item request', function() { var params; params = { routeParams: { feedId: 2, guidHash: 'dfdfdf' } }; _this.Persistence.starItem(params.routeParams.feedId, params.routeParams.guidHash); return expect(_this.req.post).toHaveBeenCalledWith('news_items_star', params); }); it('send a correct unstar item request', function() { var params; params = { routeParams: { feedId: 2, guidHash: 'dfdfdf' } }; _this.Persistence.unstarItem(params.routeParams.feedId, params.routeParams.guidHash); return expect(_this.req.post).toHaveBeenCalledWith('news_items_unstar', params); }); it('send a correct read item request', function() { var params; params = { routeParams: { itemId: 2 } }; _this.Persistence.readItem(params.routeParams.itemId); return expect(_this.req.post).toHaveBeenCalledWith('news_items_read', params); }); it('send a correct unread item request', function() { var params; params = { routeParams: { itemId: 2 } }; _this.Persistence.unreadItem(params.routeParams.itemId); return expect(_this.req.post).toHaveBeenCalledWith('news_items_unread', params); }); it('shoud send a correct request for marking all items read', function() { var params; params = { data: { highestItemId: 4 } }; return _this.Persistence.setAllRead(params.data.highestItemId); }); /* FEED CONTROLLER */ it('should get all feeds', function() { var expected, params; params = { onSuccess: function() {} }; _this.Persistence.getAllFeeds(params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function) }; return expect(_this.req.get).toHaveBeenCalledWith('news_feeds', expected); }); it('should not show loading sign if disabled', function() { var success; success = function() {}; _this.Persistence.getAllFeeds(success, false); return expect(_this.feedLoading.increase).not.toHaveBeenCalled(); }); it('create a correct request for moving a feed', function() { var params; params = { data: { parentFolderId: 4 }, routeParams: { feedId: 3 } }; _this.Persistence.moveFeed(params.routeParams.feedId, params.data.parentFolderId); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_move', params); }); it('shoud send a correct request for marking all items of a feed read', function() { var params; params = { data: { highestItemId: 4 }, routeParams: { feedId: 3 } }; _this.Persistence.setFeedRead(params.routeParams.feedId, params.data.highestItemId); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_read', params); }); it('send a correct feed update request', function() { var params; params = { routeParams: { feedId: 3 } }; _this.Persistence.updateFeed(params.routeParams.feedId); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_update', params); }); it('send a correct get active feed request', function() { var expected, params; params = { onSuccess: function() {} }; _this.Persistence.getActiveFeed(params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function) }; return expect(_this.req.get).toHaveBeenCalledWith('news_feeds_active', expected); }); it('send a correct feed delete request', function() { var params; params = { routeParams: { feedId: 3 } }; _this.Persistence.deleteFeed(params.routeParams.feedId); return expect(_this.req["delete"]).toHaveBeenCalledWith('news_feeds_delete', params); }); it('send a correct feed restore request', function() { var params; params = { onSuccess: function() {}, routeParams: { feedId: 3 } }; _this.Persistence.restoreFeed(params.routeParams.feedId, params.onSuccess); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_restore', params); }); it('send a correct feed create request', function() { var params; params = { data: { parentFolderId: 5, url: 'http://google.de' }, onSuccess: function() {}, onFailure: function() {} }; _this.Persistence.createFeed(params.data.url, params.data.parentFolderId, params.onSuccess, params.onFailure); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_create', params); }); it('should do a proper import google reader request', function() { var params; params = { data: { json: { "some": "json" } }, onSuccess: function() {} }; _this.Persistence.importGoogleReader(params.data.json, params.onSuccess); return expect(_this.req.post).toHaveBeenCalledWith('news_feeds_import_googlereader', params); }); /* FOLDER CONTROLLER */ it('should do a proper get all folders request', function() { var expected, params; params = { onSuccess: function() {} }; _this.Persistence.getAllFolders(params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function) }; return expect(_this.req.get).toHaveBeenCalledWith('news_folders', expected); }); it('send a correct collapse folder request', function() { var params; params = { routeParams: { folderId: 3 } }; _this.Persistence.collapseFolder(params.routeParams.folderId); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_collapse', params); }); it('send a correct open folder request', function() { var params; params = { routeParams: { folderId: 3 } }; _this.Persistence.openFolder(params.routeParams.folderId); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_open', params); }); it('should do a proper folder create request', function() { var params; params = { data: { folderName: 'check', parentFolderId: 4 }, onSuccess: function() { return 1; }, onFailure: function() { return 2; } }; _this.Persistence.createFolder(params.data.folderName, params.data.parentFolderId, params.onSuccess, params.onFailure); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_create', params); }); it('should do a proper folder delete request', function() { var params; params = { routeParams: { folderId: 2 } }; _this.Persistence.deleteFolder(params.routeParams.folderId); return expect(_this.req["delete"]).toHaveBeenCalledWith('news_folders_delete', params); }); it('send a correct folder restore request', function() { var params; params = { onSuccess: function() {}, routeParams: { folderId: 3 } }; _this.Persistence.restoreFolder(params.routeParams.folderId, params.onSuccess); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_restore', params); }); it('should do a proper folder rename request', function() { var params; params = { routeParams: { folderId: 2 }, data: { folderName: 'host' } }; _this.Persistence.renameFolder(params.routeParams.folderId, params.data.folderName); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_rename', params); }); it('shoud send a correct request for marking all items of a folders read', function() { var params; params = { data: { highestItemId: 4 }, routeParams: { folderId: 3 } }; _this.Persistence.setFolderRead(params.routeParams.folderId, params.data.highestItemId); return expect(_this.req.post).toHaveBeenCalledWith('news_folders_read', params); }); /* EXPORT CONTROLLER */ it('should have an export request', function() { _this.Persistence.exportOPML(); return expect(_this.req.get).toHaveBeenCalledWith('news_export_opml'); }); /* USERSETTINGS CONTROLLER */ it('should do a proper get user settings read request', function() { var expected, params; params = { onSuccess: function() {} }; _this.Persistence.userSettingsRead(params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function) }; return expect(_this.req.get).toHaveBeenCalledWith('news_usersettings_read', expected); }); it('should do a proper user settings read show request', function() { var params; params = { onSuccess: function() {} }; _this.Persistence.userSettingsReadShow(params.onSuccess); return expect(_this.req.post).toHaveBeenCalledWith('news_usersettings_read_show', params); }); it('should do a proper user settings read hide request', function() { var params; params = { onSuccess: function() {} }; _this.Persistence.userSettingsReadHide(params.onSuccess); return expect(_this.req.post).toHaveBeenCalledWith('news_usersettings_read_hide', params); }); return it('should do a proper user settings language request', function() { var expected, params; params = { onSuccess: function() {} }; _this.Persistence.userSettingsLanguage(params.onSuccess); expected = { onSuccess: jasmine.any(Function), onFailure: jasmine.any(Function) }; return expect(_this.req.get).toHaveBeenCalledWith('news_usersettings_language', expected); }); }); }).call(this);