diff --git a/modules/core/client/controllers/app.client.controller.js b/modules/core/client/controllers/app.client.controller.js index ba082efaee..b748e6e34b 100644 --- a/modules/core/client/controllers/app.client.controller.js +++ b/modules/core/client/controllers/app.client.controller.js @@ -1,82 +1,91 @@ (function(){ 'use strict'; - /* + /** * Application wide view controller */ - angular.module('core').controller('AppController', ['$scope', '$rootScope', '$window', '$state', 'Authentication', 'SettingsFactory', 'Languages', - function($scope, $rootScope, $window, $state, Authentication, SettingsFactory, Languages) { - - // ViewModel - var vm = this; - - // Exposed to the view - vm.user = Authentication.user; - vm.appSettings = SettingsFactory.get(); - vm.languageNames = Languages.get('object'); - vm.goHome = goHome; - - // Used as a cache buster with ng-include - // Includes a hash of latest git commit - vm.cacheBust = vm.appSettings.commit || ''; - - /** - * Determine where to direct user from "home" links - */ - function goHome() { - if(Authentication.user) { - $state.go('search'); - } - else { - $state.go('home'); - } + angular + .module('core') + .controller('AppController', AppController); + + /* @ngInject */ + function AppController($scope, $rootScope, $window, $state, Authentication, SettingsFactory, Languages) { + + // ViewModel + var vm = this; + + // Exposed to the view + vm.user = Authentication.user; + vm.appSettings = SettingsFactory.get(); + vm.languageNames = Languages.get('object'); + vm.goHome = goHome; + + // Used as a cache buster with ng-include + // Includes a hash of latest git commit + vm.cacheBust = vm.appSettings.commit || ''; + + /** + * Determine where to direct user from "home" links + */ + function goHome() { + if(Authentication.user) { + $state.go('search'); } + else { + $state.go('home'); + } + } - // Receive user changes - $scope.$on('userUpdated', function(){ - vm.user = Authentication.user; - }); + /** + * Snif and apply user changes + */ + $scope.$on('userUpdated', function(){ + vm.user = Authentication.user; + }); - // Before page change - $scope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { + /** + * Before page change + */ + $scope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { - // Redirect away from frontpage if user is authenticated - if(toState.name === 'home' && Authentication.user) { - event.preventDefault(); - $state.go('search'); - } + // Redirect away from frontpage if user is authenticated + if(toState.name === 'home' && Authentication.user) { + event.preventDefault(); + $state.go('search'); + } - // Redirect to login page if no user - if(toState.requiresAuth && !Authentication.user) { - // Cancel stateChange - event.preventDefault(); + // Redirect to login page if no user + if(toState.requiresAuth && !Authentication.user) { + // Cancel stateChange + event.preventDefault(); - // Save previous state - // See modules/users/client/controllers/authentication.client.controller.js for how they're used - $rootScope.signinState = toState.name; - $rootScope.signinStateParams = toParams; - $state.go('signin-continue', {'continue': true}); - } + // Save previous state + // See modules/users/client/controllers/authentication.client.controller.js for how they're used + $rootScope.signinState = toState.name; + $rootScope.signinStateParams = toParams; + $state.go('signin-continue', {'continue': true}); + } - }); + }); - // After page change - $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { + /** + * After page change + */ + $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { - // Reset page scroll on page change - $window.scrollTo(0,0); + // Reset page scroll on page change + $window.scrollTo(0,0); - // Analytics - if (typeof(ga) === 'function') { - ga('send', 'pageview', { - 'page': toState.url, - //'title': '' - }); - } + // Analytics + if (typeof(ga) === 'function') { + ga('send', 'pageview', { + 'page': toState.url, + //'title': '' + }); + } - }); + }); - } - ]); + } })(); diff --git a/modules/core/client/controllers/footer.client.controller.js b/modules/core/client/controllers/footer.client.controller.js index 1f626c03f5..02508738c5 100644 --- a/modules/core/client/controllers/footer.client.controller.js +++ b/modules/core/client/controllers/footer.client.controller.js @@ -1,89 +1,91 @@ (function(){ 'use strict'; - angular.module('core').controller('FooterController', ['$scope', - function($scope) { + angular + .module('core') + .controller('FooterController', FooterController); - // ViewModel - var vm = this; + /* @ngInject */ + function FooterController($scope) { - // Exposed - vm.isTransparent = false; - vm.isHidden = false; - vm.photoCredits = []; + // ViewModel + var vm = this; - /* - * Please try to keep this updated while you add/change/remove images from different pages - */ - var photos = { + // Exposed + vm.isTransparent = false; + vm.isHidden = false; + vm.photoCredits = []; - 'bokehblue': { - 'name': 'Sandra', - 'url': 'https://www.flickr.com/photos/artfullife/3589991695', - 'license': 'CC', - 'license_url': 'https://creativecommons.org/licenses/by-sa/2.0/' - }, - 'sierranevada': { - 'name': 'Simona', - 'url': 'http://www.wanderlust.lt', - 'license': 'CC', - 'license_url': 'http://creativecommons.org/licenses/by-nc-nd/4.0/' - }, - 'hitchroad': { - 'name': 'Andrew W Bugelli', - 'url': 'http://www.containstraces.blogspot.com/' - }, - 'forestpath': { - 'name': 'Johnson', - 'url': 'https://www.flickr.com/photos/54459164@N00/15506455245', - 'license': 'CC', - 'license_url': 'https://creativecommons.org/licenses/by-nc-sa/2.0/' - }, - 'horizonballoon': { - 'name': 'Wesley Stanford', - 'url': 'http://www.dualhorizons.blogspot.co.uk/' - }, - 'rainbowpeople': { - 'name': 'Antonio Fulghieri', - 'url': 'https://aaoutthere.wordpress.com/', - 'license': 'CC', - 'license_url': 'http://creativecommons.org/licenses/by-nc-nd/4.0/' - }, + /* + * Please try to keep this updated while you add/change/remove images from different pages + */ + var photos = { - }; + 'bokehblue': { + 'name': 'Sandra', + 'url': 'https://www.flickr.com/photos/artfullife/3589991695', + 'license': 'CC', + 'license_url': 'https://creativecommons.org/licenses/by-sa/2.0/' + }, + 'sierranevada': { + 'name': 'Simona', + 'url': 'http://www.wanderlust.lt', + 'license': 'CC', + 'license_url': 'http://creativecommons.org/licenses/by-nc-nd/4.0/' + }, + 'hitchroad': { + 'name': 'Andrew W Bugelli', + 'url': 'http://www.containstraces.blogspot.com/' + }, + 'forestpath': { + 'name': 'Johnson', + 'url': 'https://www.flickr.com/photos/54459164@N00/15506455245', + 'license': 'CC', + 'license_url': 'https://creativecommons.org/licenses/by-nc-sa/2.0/' + }, + 'horizonballoon': { + 'name': 'Wesley Stanford', + 'url': 'http://www.dualhorizons.blogspot.co.uk/' + }, + 'rainbowpeople': { + 'name': 'Antonio Fulghieri', + 'url': 'https://aaoutthere.wordpress.com/', + 'license': 'CC', + 'license_url': 'http://creativecommons.org/licenses/by-nc-nd/4.0/' + }, - // Changing footer styles/contents after navigation - $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){ + }; - // Footer is transparent on these pages - vm.isTransparent = (angular.isDefined(toState.footerTransparent) && toState.footerTransparent === true) ? true : false; + // Changing footer styles/contents after navigation + $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){ - // Footer is hidden on these pages - vm.isHidden = (angular.isDefined(toState.footerHidden) && toState.footerHidden === true) ? true : false; + // Footer is transparent on these pages + vm.isTransparent = (angular.isDefined(toState.footerTransparent) && toState.footerTransparent === true) ? true : false; - // Set photo credits for these pages - if( ['home'].indexOf(toState.name) > -1 ) { - vm.photoCredits = [ photos.rainbowpeople, photos.hitchroad ]; - } - else if( ['forgot', 'signin', 'welcome', 'statistics', 'media'].indexOf(toState.name) > -1 ) { - vm.photoCredits = [ photos.bokehblue ]; - } - else if( ['about'].indexOf(toState.name) > -1 ) { - vm.photoCredits = [ photos.bokehblue, photos.forestpath ]; - } - else if( ['foundation', 'donate', 'donate-help', 'donate-policy'].indexOf(toState.name) > -1 ) { - vm.photoCredits = [ photos.forestpath ]; - } - else if( ['faq'].indexOf(toState.name) > -1 ) { - vm.photoCredits = [ photos.horizonballoon ]; - } - else { - vm.photoCredits = []; - } + // Footer is hidden on these pages + vm.isHidden = (angular.isDefined(toState.footerHidden) && toState.footerHidden === true) ? true : false; - }); + // Set photo credits for these pages + if( ['home'].indexOf(toState.name) > -1 ) { + vm.photoCredits = [ photos.rainbowpeople, photos.hitchroad ]; + } + else if( ['forgot', 'signin', 'welcome', 'statistics', 'media'].indexOf(toState.name) > -1 ) { + vm.photoCredits = [ photos.bokehblue ]; + } + else if( ['about'].indexOf(toState.name) > -1 ) { + vm.photoCredits = [ photos.bokehblue, photos.forestpath ]; + } + else if( ['foundation', 'donate', 'donate-help', 'donate-policy'].indexOf(toState.name) > -1 ) { + vm.photoCredits = [ photos.forestpath ]; + } + else if( ['faq'].indexOf(toState.name) > -1 ) { + vm.photoCredits = [ photos.horizonballoon ]; + } + else { + vm.photoCredits = []; + } + }); - } - ]); + } })(); diff --git a/modules/core/client/controllers/header.client.controller.js b/modules/core/client/controllers/header.client.controller.js index 02ea26b7e6..70f0f958c5 100644 --- a/modules/core/client/controllers/header.client.controller.js +++ b/modules/core/client/controllers/header.client.controller.js @@ -1,33 +1,35 @@ (function(){ 'use strict'; - angular.module('core').controller('HeaderController', ['$scope', '$state', - function($scope, $state) { + angular + .module('core') + .controller('HeaderController', HeaderController); - // ViewModel - var vm = this; + /* @ngInject */ + function HeaderController($scope, $state) { - // Exposed - vm.isCollapsed = false; - vm.isHidden = false; - vm.toggleCollapsibleMenu = toggleCollapsibleMenu; + // ViewModel + var vm = this; - function toggleCollapsibleMenu() { - vm.isCollapsed = !vm.isCollapsed; - } + // Exposed + vm.isCollapsed = false; + vm.isHidden = false; + vm.toggleCollapsibleMenu = toggleCollapsibleMenu; - // Perform actions at page change - $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { + function toggleCollapsibleMenu() { + vm.isCollapsed = !vm.isCollapsed; + } - // Collapsing the menu after navigation - vm.isCollapsed = false; + // Perform actions at page change + $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) { - // Hide header at certain pages - vm.isHidden = (angular.isDefined(toState.headerHidden) && toState.headerHidden === true) ? true : false; + // Collapsing the menu after navigation + vm.isCollapsed = false; - }); + // Hide header at certain pages + vm.isHidden = (angular.isDefined(toState.headerHidden) && toState.headerHidden === true) ? true : false; + }); - } - ]); + } })(); diff --git a/modules/core/client/directives/tr-boards.client.directive.js b/modules/core/client/directives/tr-boards.client.directive.js index ff2e5cd8f3..1bd70ea83c 100644 --- a/modules/core/client/directives/tr-boards.client.directive.js +++ b/modules/core/client/directives/tr-boards.client.directive.js @@ -1,17 +1,23 @@ -'use strict'; +(function(){ + 'use strict'; -/* - * Directive that gives random class from provided class array. - * Typically you would rotate board-* classes found from /public/modules/core/less/board.less - * - * Usage: - * - *
- * - * $scope.classes = ['board-sierranevada', 'board-hitchroad']; - */ -angular.module('core').directive('trBoards', [ - function($http) { + /** + * Directive that gives random class from provided class array. + * Typically you would rotate board-* classes found from /modules/core/client/less/board.less + * + * Usage: + * + *
+ * + * When: + * vm.classes = ['board-sierranevada', 'board-hitchroad']; + */ + angular + .module('core') + .directive('trBoards', trBoardsDirective); + + /* @ngInject */ + function trBoardsDirective($http) { return { restrict: 'A', replace: false, @@ -20,9 +26,10 @@ angular.module('core').directive('trBoards', [ }, link: function (scope, elem, attr) { - //Add random background class to selected element + // Add random background class to the element elem.addClass(scope.trBoards[Math.floor(Math.random() * (scope.trBoards.length))]); } }; } -]); + +})(); diff --git a/modules/core/client/directives/tr-location.client.directive.js b/modules/core/client/directives/tr-location.client.directive.js index 641a33ae2b..965e123604 100644 --- a/modules/core/client/directives/tr-location.client.directive.js +++ b/modules/core/client/directives/tr-location.client.directive.js @@ -1,8 +1,12 @@ -'use strict'; +(function(){ + 'use strict'; -angular.module('core').directive('trLocation', [ - '$http', - function($http) { + angular + .module('core') + .directive('trLocation', trLocationDirective); + + /* @ngInject */ + function trLocationDirective($http) { return { replace: true, template: @@ -72,4 +76,5 @@ angular.module('core').directive('trLocation', [ } }; } -]); + +})(); diff --git a/modules/core/client/filters/age.client.filter.js b/modules/core/client/filters/age.client.filter.js index 35b4402bac..21d38fc2cc 100644 --- a/modules/core/client/filters/age.client.filter.js +++ b/modules/core/client/filters/age.client.filter.js @@ -1,24 +1,28 @@ -'use strict'; +(function(){ + 'use strict'; -/** - * Turn mongo date string into years - * - * Input: 1986-05-30T21:00:00.000Z - * Output: 28 years - * - * @link http://stackoverflow.com/a/24883386 - * @link http://stackoverflow.com/a/21984136 - */ -angular.module('core').filter('ageyears', ['$filter', - function($filter) { - return function(dateString) { + /** + * Turn mongo date string into years + * + * Input: 1986-05-30T21:00:00.000Z + * Output: 28 years + * + * @link http://stackoverflow.com/a/24883386 + * @link http://stackoverflow.com/a/21984136 + */ + angular + .module('core') + .filter('ageyears', ageYearsFilter); + /* @ngInject */ + function ageYearsFilter($filter) { + return function(dateString) { var dateObj = new Date( $filter('date')(dateString, 'yyyy-MM-dd') ), ageDifMs = Date.now() - dateObj.getTime(), ageDate = new Date(ageDifMs); // miliseconds from epoch return Math.abs(ageDate.getUTCFullYear() - 1970) + ' years'; - }; } -]); + +})(); diff --git a/modules/core/client/filters/trusted-html.client.filter.js b/modules/core/client/filters/trusted-html.client.filter.js index 019a9d50f6..9d856c5680 100644 --- a/modules/core/client/filters/trusted-html.client.filter.js +++ b/modules/core/client/filters/trusted-html.client.filter.js @@ -1,9 +1,15 @@ -'use strict'; +(function(){ + 'use strict'; -angular.module('core').filter('trustedHtml', ['$sce', - function($sce) { + angular + .module('core') + .filter('trustedHtml', trustedHtmlFilter); + + /* @ngInject */ + function trustedHtmlFilter($sce) { return function(input) { return $sce.trustAsHtml(input); }; } -]); + +})(); diff --git a/modules/core/client/services/languages.client.service.js b/modules/core/client/services/languages.client.service.js index 0d4775b604..a0dff9557c 100644 --- a/modules/core/client/services/languages.client.service.js +++ b/modules/core/client/services/languages.client.service.js @@ -1,21 +1,34 @@ -'use strict'; +(function() { + 'use strict'; -angular.module('core').factory('Languages', ['$window', - function($window) { - var service = {}; + angular + .module('core') + .factory('Languages', LanguagesFactory); - service.get = function (type) { - if (type === 'array'){ - var langs_arr = []; + /* @ngInject */ + function LanguagesFactory($window) { + + var service = { + get: get + }; + + return service; + + function get(type) { + if (type === 'array') { + var langsArr = []; for (var key in $window.languages) { - langs_arr[langs_arr.length] = {key: key, name: $window.languages[key]}; + langsArr[langsArr.length] = {key: key, name: $window.languages[key]}; } - return langs_arr; - } else if (type === 'object'){ - return $window.languages; + return langsArr; } - }; + + // type === 'object': + return $window.languages; + } return service; + } -]); + +})(); diff --git a/modules/core/client/services/maplayers.client.service.js b/modules/core/client/services/maplayers.client.service.js index d8e9fb3d53..3e6474959c 100644 --- a/modules/core/client/services/maplayers.client.service.js +++ b/modules/core/client/services/maplayers.client.service.js @@ -1,14 +1,19 @@ -'use strict'; - -/** - * Service for map layers - * - Streets from Mapbox (fallback from OSM) - * - Satellite from Mapbox (fallback from MapQuest) - * - Other maps: - * - Hitchmap from Mapbox (no fallback) - */ -angular.module('core').factory('MapLayersFactory', ['SettingsFactory', - function(SettingsFactory) { +(function() { + 'use strict'; + + /** + * Service for map layers + * - Streets from Mapbox (fallback from OSM) + * - Satellite from Mapbox (fallback from MapQuest) + * - Other maps: + * - Hitchmap from Mapbox (no fallback) + */ + angular + .module('core') + .factory('MapLayersFactory', MapLayersFactory); + + /* @ngInject */ + function MapLayersFactory(SettingsFactory) { var appSettings = SettingsFactory.get(); @@ -127,4 +132,5 @@ angular.module('core').factory('MapLayersFactory', ['SettingsFactory', return service; } -]); + +})(); diff --git a/modules/core/client/services/socket.client.service.js b/modules/core/client/services/socket.client.service.js deleted file mode 100644 index c06b213d61..0000000000 --- a/modules/core/client/services/socket.client.service.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -// Socket factory that provides the socket service -/* -angular.module('core').factory('Socket', ['socketFactory', '$location', 'SettingsFactory', - function(socketFactory, $location, SettingsFactory) { - - var settings = SettingsFactory.get(); - - return socketFactory({ - prefix: '', - ioSocket: io.connect( $location.protocol() + '://' + $location.host() + ':' + $location.port(), {secure: settings.https} ) - }); - } -]); -*/ diff --git a/modules/messages/client/directives/threads.client.directive.js b/modules/messages/client/directives/threads.client.directive.js index 4cdcb70251..16bbf8ccf4 100644 --- a/modules/messages/client/directives/threads.client.directive.js +++ b/modules/messages/client/directives/threads.client.directive.js @@ -1,15 +1,23 @@ -'use strict'; - -angular.module('messages').directive('threads', function () { - return { - link: function (scope, elem, attr) { - var element = elem[0]; - - elem.bind('scroll', function() { - if (element.scrollTop <= 0) { - scope.$apply(attr.moremessages); - } - }); - } - }; -}); +(function() { + 'use strict'; + + angular + .module('messages') + .directive('threads', threadsDirective); + + /* @ngInject */ + function threadsDirective() { + return { + link: function (scope, elem, attr) { + var element = elem[0]; + + elem.bind('scroll', function() { + if (element.scrollTop <= 0) { + scope.$apply(attr.moremessages); + } + }); + } + }; + } + +})(); diff --git a/modules/messages/client/services/messages-read.client.service.js b/modules/messages/client/services/messages-read.client.service.js new file mode 100644 index 0000000000..d584ee9dbf --- /dev/null +++ b/modules/messages/client/services/messages-read.client.service.js @@ -0,0 +1,22 @@ +(function() { + 'use strict'; + + // MessagesRead service used for communicating with the messages REST endpoints + angular + .module('messages') + .factory('MessagesRead', MessagesRead); + + /* @ngInject */ + function MessagesRead($resource) { + return $resource('/api/messages-read', { + messageIds: '@messageIds' + }, { + query: { + method: 'POST', + isArray: false, + cache: false + } + }); + } + +})(); diff --git a/modules/messages/client/services/messages.client.service.js b/modules/messages/client/services/messages.client.service.js index 8357b590f8..818777e705 100644 --- a/modules/messages/client/services/messages.client.service.js +++ b/modules/messages/client/services/messages.client.service.js @@ -1,8 +1,13 @@ -'use strict'; +(function() { + 'use strict'; -//Messages service used for communicating with the messages REST endpoints -angular.module('messages').factory('Messages', ['$resource', - function($resource) { + // Messages service used for communicating with the messages REST endpoints + angular + .module('messages') + .factory('Messages', Messages); + + /* @ngInject */ + function Messages($resource) { function MessageHandler() { // Control flow variable; Prevents multiple identical ajax calls @@ -25,9 +30,9 @@ angular.module('messages').factory('Messages', ['$resource', } }, /** - * Fetches messages and sets up pagination environment - * Takes additional query params passed in as key , value pairs - */ + * Fetches messages and sets up pagination environment + * Takes additional query params passed in as key , value pairs + */ fetchMessages: function(param) { var that = this; var query = (this.nextPage) ? angular.extend(this.nextPage, param): param; @@ -37,13 +42,13 @@ angular.module('messages').factory('Messages', ['$resource', return(this.ajaxCall.query( query, - //Successful callback + // Successful callback function(data, headers){ that.nextPage = that.parseHeaders(headers().link); that.resolved = true; that.paginationTimeout = false; }, - //Error callback + // Error callback function(){ that.paginationTimeout = false; that.resolved = false; @@ -58,18 +63,5 @@ angular.module('messages').factory('Messages', ['$resource', }; return MessageHandler; } -]); -angular.module('messages').factory('MessagesRead', ['$resource', - function($resource) { - return $resource('/api/messages-read', { - messageIds: '@messageIds' - }, { - query: { - method: 'POST', - isArray: false, - cache: false - } - }); - } -]); +})(); diff --git a/modules/messages/tests/server/message.server.routes.tests.js b/modules/messages/tests/server/message.server.routes.tests.js new file mode 100644 index 0000000000..592f36b513 --- /dev/null +++ b/modules/messages/tests/server/message.server.routes.tests.js @@ -0,0 +1,147 @@ +'use strict'; + +var should = require('should'), + request = require('supertest'), + path = require('path'), + mongoose = require('mongoose'), + User = mongoose.model('User'), + Message = mongoose.model('Message'), + Thread = mongoose.model('Thread'), + express = require(path.resolve('./config/lib/express')); + +/** + * Globals + */ +var app, agent, credentials, userFrom, userTo, userFromId, userToId, message, thread; + +/** + * Message routes tests + */ +describe('Message CRUD tests', function() { + before(function(done) { + // Get application + app = express.init(mongoose); + agent = request.agent(app); + + done(); + }); + + beforeEach(function(done) { + // Create userFrom credentials + credentials = { + username: 'username1', + password: 'password123' + }; + + // Create a new user + userFrom = new User({ + firstName: 'Full', + lastName: 'Name', + displayName: 'Full Name', + email: 'test1@test.com', + username: credentials.username, + password: credentials.password, + provider: 'local' + }); + + userTo = new User({ + firstName: 'Full', + lastName: 'Name', + displayName: 'Full Name', + email: 'test2@test.com', + username: 'username2', + password: 'password123', + provider: 'local' + }); + + // Save users to the test db and create new message + userFrom.save(function() { + userTo.save(function() { + // Check id for userTo + User.findOne({'username': userTo.username}, function(err, userTo) { + + // Get id + userToId = userTo._id; + + // Create message + message = { + content: 'Message content', + userTo: userToId, + read: false + }; + done(); + }); + + }); + }); + }); + + it('should not be able to send message if not logged in', function(done) { + agent.post('/api/messages') + .send(message) + .expect(403) + .end(function(messageSaveErr, messageSaveRes) { + // Call the assertion callback + done(messageSaveErr); + }); + }); + + it('should be able to send an message if logged in', function(done) { + agent.post('/api/auth/signin') + .send(credentials) + .expect(200) + .end(function(signinErr, signinRes) { + // Handle signin error + if (signinErr) done(signinErr); + + // Get user id + var userFromId = signinRes.body._id; + + // Save a new message + agent.post('/api/messages') + .send(message) + .expect(200) + .end(function(messageSaveErr, messageSaveRes) { + // Handle message save error + if (messageSaveErr) done(messageSaveErr); + + // Get a list of messages + agent.get('/api/messages/' + userToId) + .end(function(messagesGetErr, messagesGetRes) { + // Handle message save error + if (messagesGetErr) done(messagesGetErr); + + // Get messages list + var thread = messagesGetRes.body; + + console.log('thread:'); + console.log(thread); + + if(!thread[0] || thread[0].content) { + done(new Error('Missing messages from the message thread.')); + } + else { + + // Set assertions + (thread[0].userFrom._id).should.equal(userFromId); + (thread[0].userTo._id).should.equal(userToId); + (thread[0].content).should.match('Message content'); + + // Call the assertion callback + done(); + } + + }); + }); + }); + }); + + afterEach(function(done) { + // Uggggly pyramid revenge! + User.remove().exec(function() { + Message.remove().exec(function() { + Thread.remove().exec(done); + }); + }); + }); +}); diff --git a/modules/offers/client/controllers/view-offers.client.controller.js b/modules/offers/client/controllers/view-offers.client.controller.js index 01862f2f9a..bd9905863d 100644 --- a/modules/offers/client/controllers/view-offers.client.controller.js +++ b/modules/offers/client/controllers/view-offers.client.controller.js @@ -6,7 +6,7 @@ .controller('ViewOffersController', ViewOffersController); /* @ngInject */ - function ViewOffersController($scope, $state, $location, $timeout, OffersBy, Authentication, leafletData, MapLayersFactory) { + function ViewOffersController($scope, $state, $location, OffersBy, Authentication, leafletData, MapLayersFactory) { // ViewModel var vm = this; @@ -114,8 +114,6 @@ userId: $scope.profileCtrl.profile._id }, function(offer){ if(offer && offer.location) { - console.log('offer location'); - console.log(offer); var offerLocation = { lat: parseFloat(offer.location[0]), lng: parseFloat(offer.location[1]) diff --git a/modules/offers/client/services/offers-by.client.service.js b/modules/offers/client/services/offers-by.client.service.js new file mode 100644 index 0000000000..f8b701200c --- /dev/null +++ b/modules/offers/client/services/offers-by.client.service.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + // OffersBy service used for communicating with the offers REST endpoints + // Read offers by userId + angular + .module('offers') + .factory('OffersBy', OffersBy); + + /* @ngInject */ + function OffersBy($resource) { + return $resource('/api/offers-by/:userId', { + userId: '@id' + }, { + update: { + method: 'PUT' + } + }); + } + +})(); diff --git a/modules/offers/client/services/offers.client.service.js b/modules/offers/client/services/offers.client.service.js index 01dae233db..c8a6794ab1 100644 --- a/modules/offers/client/services/offers.client.service.js +++ b/modules/offers/client/services/offers.client.service.js @@ -1,24 +1,14 @@ -'use strict'; +(function() { + 'use strict'; -//Offers service used for communicating with the offers REST endpoints + // Offers service used for communicating with the offers REST endpoints + // Read offer by offerId + angular + .module('offers') + .factory('Offers', Offers); -// Read offers by userId -angular.module('offers').factory('OffersBy', ['$resource', - function($resource) { - return $resource('/api/offers-by/:userId', { - userId: '@id' - }, { - update: { - method: 'PUT' - } - }); - } -]); - - -// Read offer by offerId -angular.module('offers').factory('Offers', ['$resource', - function($resource) { + /* @ngInject */ + function Offers($resource) { return $resource('/api/offers/:offerId', { offerId:'@id' }, { @@ -27,4 +17,5 @@ angular.module('offers').factory('Offers', ['$resource', } }); } -]); + +})();