| 
									
										
										
										
											2015-01-03 20:07:09 -05:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 11:59:01 -05:00
										 |  |  | var assert = require('assert'); | 
					
						
							| 
									
										
										
										
											2016-10-16 21:51:42 +03:00
										 |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | var path = require('path'); | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | var nconf = require('nconf'); | 
					
						
							| 
									
										
										
										
											2016-11-10 16:55:22 +03:00
										 |  |  | var request = require('request'); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | var db = require('./mocks/databasemock'); | 
					
						
							| 
									
										
										
										
											2016-10-16 21:51:42 +03:00
										 |  |  | var User = require('../src/user'); | 
					
						
							|  |  |  | var Topics = require('../src/topics'); | 
					
						
							|  |  |  | var Categories = require('../src/categories'); | 
					
						
							|  |  |  | var Meta = require('../src/meta'); | 
					
						
							|  |  |  | var Password = require('../src/password'); | 
					
						
							| 
									
										
										
										
											2016-11-22 18:21:57 +03:00
										 |  |  | var groups = require('../src/groups'); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | var helpers = require('./helpers'); | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | var meta = require('../src/meta'); | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | var plugins = require('../src/plugins'); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | describe('User', function () { | 
					
						
							| 
									
										
										
										
											2016-10-16 21:51:42 +03:00
										 |  |  | 	var userData; | 
					
						
							|  |  |  | 	var testUid; | 
					
						
							|  |  |  | 	var testCid; | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	before(function (done) { | 
					
						
							| 
									
										
										
										
											2016-09-14 21:00:41 +03:00
										 |  |  | 		groups.resetCache(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 		Categories.create({ | 
					
						
							|  |  |  | 			name: 'Test Category', | 
					
						
							|  |  |  | 			description: 'A test', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			order: 1, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		}, function (err, categoryObj) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return done(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 			testCid = categoryObj.cid; | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	beforeEach(function () { | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 		userData = { | 
					
						
							| 
									
										
										
										
											2014-03-06 14:51:43 -05:00
										 |  |  | 			username: 'John Smith', | 
					
						
							| 
									
										
										
										
											2015-05-07 13:43:06 -04:00
										 |  |  | 			fullname: 'John Smith McNamara', | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 			password: 'swordfish', | 
					
						
							|  |  |  | 			email: 'john@example.com', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			callback: undefined, | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('.create(), when created', function () { | 
					
						
							|  |  |  | 		it('should be created properly', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: userData.username, password: userData.password, email: userData.email }, function (error, userId) { | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 				assert.equal(error, null, 'was created with error'); | 
					
						
							|  |  |  | 				assert.ok(userId); | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				testUid = userId; | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should have a valid email, if using an email', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: userData.username, password: userData.password, email: 'fakeMail' }, function (err) { | 
					
						
							| 
									
										
										
										
											2015-10-19 11:45:07 -04:00
										 |  |  | 				assert(err); | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-email]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-24 10:33:38 -06:00
										 |  |  | 	describe('.uniqueUsername()', function () { | 
					
						
							| 
									
										
										
										
											2017-03-23 16:00:22 -06:00
										 |  |  | 		it('should deal with collisions', function (done) { | 
					
						
							|  |  |  | 			var users = []; | 
					
						
							|  |  |  | 			for (var i = 0; i < 10; i += 1) { | 
					
						
							|  |  |  | 				users.push({ | 
					
						
							|  |  |  | 					username: 'Jane Doe', | 
					
						
							|  |  |  | 					password: 'abcdefghi', | 
					
						
							|  |  |  | 					email: 'jane.doe' + i + '@example.com', | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			async.series([ | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					async.eachSeries(users, function (user, next) { | 
					
						
							|  |  |  | 						User.create(user, next); | 
					
						
							|  |  |  | 					}, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2017-03-24 10:33:38 -06:00
										 |  |  | 					User.uniqueUsername({ | 
					
						
							| 
									
										
										
										
											2017-03-23 16:00:22 -06:00
										 |  |  | 						username: 'Jane Doe', | 
					
						
							|  |  |  | 						userslug: 'jane-doe', | 
					
						
							|  |  |  | 					}, function (err, username) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						assert.strictEqual(username, 'Jane Doe 9'); | 
					
						
							| 
									
										
										
										
											2017-05-13 21:45:50 -04:00
										 |  |  | 						next(); | 
					
						
							| 
									
										
										
										
											2017-03-23 16:00:22 -06:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('.isModerator()', function () { | 
					
						
							|  |  |  | 		it('should return false', function (done) { | 
					
						
							|  |  |  | 			User.isModerator(testUid, testCid, function (err, isModerator) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2014-12-02 15:33:23 -05:00
										 |  |  | 				assert.equal(isModerator, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return two false results', function (done) { | 
					
						
							|  |  |  | 			User.isModerator([testUid, testUid], testCid, function (err, isModerator) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2014-12-02 15:33:23 -05:00
										 |  |  | 				assert.equal(isModerator[0], false); | 
					
						
							|  |  |  | 				assert.equal(isModerator[1], false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return two false results', function (done) { | 
					
						
							|  |  |  | 			User.isModerator(testUid, [testCid, testCid], function (err, isModerator) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2014-12-02 15:33:23 -05:00
										 |  |  | 				assert.equal(isModerator[0], false); | 
					
						
							|  |  |  | 				assert.equal(isModerator[1], false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('.isReadyToPost()', function () { | 
					
						
							|  |  |  | 		it('should error when a user makes two posts in quick succession', function (done) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 			Meta.config = Meta.config || {}; | 
					
						
							|  |  |  | 			Meta.config.postDelay = '10'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			async.series([ | 
					
						
							|  |  |  | 				async.apply(Topics.post, { | 
					
						
							|  |  |  | 					uid: testUid, | 
					
						
							|  |  |  | 					title: 'Topic 1', | 
					
						
							|  |  |  | 					content: 'lorem ipsum', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					cid: testCid, | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 				}), | 
					
						
							|  |  |  | 				async.apply(Topics.post, { | 
					
						
							|  |  |  | 					uid: testUid, | 
					
						
							|  |  |  | 					title: 'Topic 2', | 
					
						
							|  |  |  | 					content: 'lorem ipsum', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					cid: testCid, | 
					
						
							|  |  |  | 				}), | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			], function (err) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 				assert(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should allow a post if the last post time is > 10 seconds', function (done) { | 
					
						
							|  |  |  | 			User.setUserField(testUid, 'lastposttime', +new Date() - (11 * 1000), function () { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 				Topics.post({ | 
					
						
							|  |  |  | 					uid: testUid, | 
					
						
							|  |  |  | 					title: 'Topic 3', | 
					
						
							|  |  |  | 					content: 'lorem ipsum', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					cid: testCid, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				}, function (err) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should error when a new user posts if the last post time is 10 < 30 seconds', function (done) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 			Meta.config.newbiePostDelay = 30; | 
					
						
							|  |  |  | 			Meta.config.newbiePostDelayThreshold = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			User.setUserField(testUid, 'lastposttime', +new Date() - (20 * 1000), function () { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 				Topics.post({ | 
					
						
							|  |  |  | 					uid: testUid, | 
					
						
							|  |  |  | 					title: 'Topic 4', | 
					
						
							|  |  |  | 					content: 'lorem ipsum', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					cid: testCid, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				}, function (err) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 					assert(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should not error if a non-newbie user posts if the last post time is 10 < 30 seconds', function (done) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 			User.setUserFields(testUid, { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 				lastposttime: +new Date() - (20 * 1000), | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				reputation: 10, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function () { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 				Topics.post({ | 
					
						
							|  |  |  | 					uid: testUid, | 
					
						
							|  |  |  | 					title: 'Topic 5', | 
					
						
							|  |  |  | 					content: 'lorem ipsum', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					cid: testCid, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				}, function (err) { | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('.search()', function () { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:58:13 +03:00
										 |  |  | 		var socketUser = require('../src/socket.io/user'); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return an object containing an array of matching users', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.search({ query: 'john' }, function (err, searchData) { | 
					
						
							| 
									
										
										
										
											2014-12-31 17:20:28 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(Array.isArray(searchData.users) && searchData.users.length > 0, true); | 
					
						
							|  |  |  | 				assert.equal(searchData.users[0].username, 'John Smith'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:58:13 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should search user', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.search({ uid: testUid }, { query: 'john' }, function (err, searchData) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:58:13 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(searchData.users[0].username, 'John Smith'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error for guest', function (done) { | 
					
						
							|  |  |  | 			Meta.config.allowGuestUserSearching = 0; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.search({ uid: 0 }, { query: 'john' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:58:13 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:not-logged-in]]'); | 
					
						
							|  |  |  | 				Meta.config.allowGuestUserSearching = 1; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error with invalid data', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.search({ uid: testUid }, null, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:58:13 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 17:20:28 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('.delete()', function () { | 
					
						
							| 
									
										
										
										
											2015-01-22 14:18:19 -05:00
										 |  |  | 		var uid; | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'usertodelete', password: '123456', email: 'delete@me.com' }, function (err, newUid) { | 
					
						
							| 
									
										
										
										
											2015-01-22 14:18:19 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				uid = newUid; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should delete a user account', function (done) { | 
					
						
							|  |  |  | 			User.delete(1, uid, function (err) { | 
					
						
							| 
									
										
										
										
											2015-01-22 14:18:19 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				User.existsBySlug('usertodelete', function (err, exists) { | 
					
						
							| 
									
										
										
										
											2015-01-22 14:18:19 -05:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(exists, false); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('passwordReset', function () { | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | 		var uid; | 
					
						
							|  |  |  | 		var code; | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'resetuser', password: '123456', email: 'reset@me.com' }, function (err, newUid) { | 
					
						
							| 
									
										
										
										
											2015-02-17 18:11:30 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				uid = newUid; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('.generate() should generate a new reset code', function (done) { | 
					
						
							|  |  |  | 			User.reset.generate(uid, function (err, _code) { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(_code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				code = _code; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('.validate() should ensure that this new code is valid', function (done) { | 
					
						
							|  |  |  | 			User.reset.validate(code, function (err, valid) { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(valid, true); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('.validate() should correctly identify an invalid code', function (done) { | 
					
						
							|  |  |  | 			User.reset.validate(code + 'abcdef', function (err, valid) { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(valid, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('.send() should create a new reset code and reset password', function (done) { | 
					
						
							| 
									
										
										
										
											2017-05-13 21:45:50 -04:00
										 |  |  | 			User.reset.send('reset@me.com', function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-16 06:03:02 +03:00
										 |  |  | 				if (err) { | 
					
						
							|  |  |  | 					console.log(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-02-17 18:11:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('.commit() should update the user\'s password', function (done) { | 
					
						
							|  |  |  | 			User.reset.commit(code, 'newpassword', function (err) { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2015-02-17 18:11:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.getObjectField('user:' + uid, 'password', function (err, newPassword) { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 					Password.compare('newpassword', newPassword, function (err, match) { | 
					
						
							| 
									
										
										
										
											2015-02-17 18:11:30 -05:00
										 |  |  | 						assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2015-04-02 20:27:43 -04:00
										 |  |  | 						assert(match); | 
					
						
							|  |  |  | 						done(); | 
					
						
							| 
									
										
										
										
											2015-02-17 18:11:30 -05:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('hash methods', function () { | 
					
						
							|  |  |  | 		it('should return uid from email', function (done) { | 
					
						
							|  |  |  | 			User.getUidByEmail('john@example.com', function (err, uid) { | 
					
						
							| 
									
										
										
										
											2015-05-07 13:43:06 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(parseInt(uid, 10), parseInt(testUid, 10)); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return uid from username', function (done) { | 
					
						
							|  |  |  | 			User.getUidByUsername('John Smith', function (err, uid) { | 
					
						
							| 
									
										
										
										
											2015-05-07 13:43:06 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(parseInt(uid, 10), parseInt(testUid, 10)); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return uid from userslug', function (done) { | 
					
						
							|  |  |  | 			User.getUidByUserslug('john-smith', function (err, uid) { | 
					
						
							| 
									
										
										
										
											2015-05-07 13:43:06 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(parseInt(uid, 10), parseInt(testUid, 10)); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 	describe('not logged in', function () { | 
					
						
							|  |  |  | 		var jar; | 
					
						
							|  |  |  | 		var io; | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							|  |  |  | 			helpers.initSocketIO(function (err, _jar, _io) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				jar = _jar; | 
					
						
							|  |  |  | 				io = _io; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return error if not logged in', function (done) { | 
					
						
							|  |  |  | 			io.emit('user.updateProfile', {}, function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-uid]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('profile methods', function () { | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 		var uid; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 		var jar; | 
					
						
							|  |  |  | 		var io; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'updateprofile', email: 'update@me.com', password: '123456' }, function (err, newUid) { | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				uid = newUid; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				helpers.loginUser('updateprofile', '123456', function (err, _jar, _io) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					jar = _jar; | 
					
						
							|  |  |  | 					io = _io; | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return error if data is invalid', function (done) { | 
					
						
							|  |  |  | 			io.emit('user.updateProfile', null, function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return error if data is missing uid', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.updateProfile', { username: 'bip', email: 'bop' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should update a user\'s profile', function (done) { | 
					
						
							|  |  |  | 			var data = { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				uid: uid, | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 				username: 'updatedUserName', | 
					
						
							|  |  |  | 				email: 'updatedEmail@me.com', | 
					
						
							|  |  |  | 				fullname: 'updatedFullname', | 
					
						
							|  |  |  | 				website: 'http://nodebb.org', | 
					
						
							|  |  |  | 				location: 'izmir', | 
					
						
							|  |  |  | 				groupTitle: 'testGroup', | 
					
						
							|  |  |  | 				birthday: '01/01/1980', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				signature: 'nodebb is good', | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 			io.emit('user.updateProfile', data, function (err, result) { | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 14:42:15 -07:00
										 |  |  | 				assert.equal(result.username, 'updatedUserName'); | 
					
						
							|  |  |  | 				assert.equal(result.userslug, 'updatedusername'); | 
					
						
							|  |  |  | 				assert.equal(result.email, 'updatedEmail@me.com'); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 				db.getObject('user:' + uid, function (err, userData) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					Object.keys(data).forEach(function (key) { | 
					
						
							|  |  |  | 						assert.equal(data[key], userData[key]); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should change a user\'s password', function (done) { | 
					
						
							| 
									
										
										
										
											2017-03-15 12:49:08 +03:00
										 |  |  | 			var socketUser = require('../src/socket.io/user'); | 
					
						
							|  |  |  | 			User.create({ username: 'changepassword', password: '123456' }, function (err, uid) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-03-15 12:49:08 +03:00
										 |  |  | 				socketUser.changePassword({ uid: uid }, { uid: uid, newPassword: '654321', currentPassword: '123456' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-03-15 12:49:08 +03:00
										 |  |  | 					User.isPasswordCorrect(uid, '654321', function (err, correct) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert(correct); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should change username', function (done) { | 
					
						
							| 
									
										
										
										
											2017-03-15 12:49:08 +03:00
										 |  |  | 			io.emit('user.changeUsernameEmail', { uid: uid, username: 'updatedAgain', password: '123456' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getObjectField('user:' + uid, 'username', function (err, username) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(username, 'updatedAgain'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should change email', function (done) { | 
					
						
							| 
									
										
										
										
											2017-03-15 12:49:08 +03:00
										 |  |  | 			io.emit('user.changeUsernameEmail', { uid: uid, email: 'updatedAgain@me.com', password: '123456' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getObjectField('user:' + uid, 'email', function (err, email) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(email, 'updatedAgain@me.com'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should update cover image', function (done) { | 
					
						
							|  |  |  | 			var imageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA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fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAACcJJREFUeNqMl9tvnNV6xn/f+s5z8DCeg88Zj+NYdhJH4KShFoJAIkzVphLVJnsDaiV6gUKaC2qQUFVATbnoValAakuQYKMqBKUUJCgI9XBBSmOROMqGoCStHbA9sWM7nrFn/I3n9B17kcwoabfarj9gvet53+d9nmdJAwMDAAgh8DyPtbU1XNfFMAwkScK2bTzPw/M8dF1/SAhxKAiCxxVF2aeqqqTr+q+Af+7o6Ch0d3f/69TU1KwkSRiGwbFjx3jmmWd47rnn+OGHH1BVFYX/5QRBkPQ87xeSJP22YRi/oapqStM0PM/D931kWSYIgnHf98cXFxepVqtomjZt2/Zf2bb990EQ4Pv+PXfeU1CSpGYhfN9/TgjxQTQaJQgCw
 | 
					
						
							|  |  |  | 			var position = '50.0301% 19.2464%'; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.updateCover', { uid: uid, imageData: imageData, position: position }, function (err, result) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(result.url); | 
					
						
							|  |  |  | 				db.getObjectFields('user:' + uid, ['cover:url', 'cover:position'], function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(data['cover:url'], result.url); | 
					
						
							|  |  |  | 					assert.equal(data['cover:position'], position); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 		it('should upload cropped profile picture', function (done) { | 
					
						
							|  |  |  | 			var imageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAgCAYAAAABtRhCAAAACXBIWXMAAC4jAAAuIwF4pT92AAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUii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4Pv+PXfeU1CSpGYhfN9/TgjxQTQaJQgCw
 | 
					
						
							|  |  |  | 			var socketUser = require('../src/socket.io/user'); | 
					
						
							| 
									
										
										
										
											2017-02-18 19:14:39 -07:00
										 |  |  | 			socketUser.uploadCroppedPicture({ uid: uid }, { uid: uid, imageData: imageData }, function (err, result) { | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(result.url); | 
					
						
							|  |  |  | 				db.getObjectFields('user:' + uid, ['uploadedpicture', 'picture'], function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(result.url, data.uploadedpicture); | 
					
						
							|  |  |  | 					assert.equal(result.url, data.picture); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 		it('should remove cover image', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.removeCover', { uid: uid }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:38:42 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getObjectField('user:' + uid, 'cover:url', function (err, url) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(url, null); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should set user status', function (done) { | 
					
						
							|  |  |  | 			io.emit('user.setStatus', 'away', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(data.uid, uid); | 
					
						
							|  |  |  | 				assert.equal(data.status, 'away'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should fail for invalid status', function (done) { | 
					
						
							|  |  |  | 			io.emit('user.setStatus', '12345', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-user-status]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should get user status', function (done) { | 
					
						
							|  |  |  | 			io.emit('user.checkStatus', uid, function (err, status) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(status, 'away'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should change user picture', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.changePicture', { type: 'default', uid: uid }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.getUserField(uid, 'picture', function (err, picture) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(picture, ''); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should upload profile picture', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 			helpers.copyFile( | 
					
						
							|  |  |  | 				path.join(nconf.get('base_dir'), 'test/files/test.png'), | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				path.join(nconf.get('base_dir'), 'test/files/test_copy.png'), | 
					
						
							|  |  |  | 				function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 					var picture = { | 
					
						
							|  |  |  | 						path: path.join(nconf.get('base_dir'), 'test/files/test_copy.png'), | 
					
						
							|  |  |  | 						size: 7189, | 
					
						
							|  |  |  | 						name: 'test_copy.png', | 
					
						
							|  |  |  | 						type: 'image/png', | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 					User.uploadPicture(uid, picture, function (err, uploadedPicture) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-03-15 20:09:07 -07:00
										 |  |  | 						assert.equal(uploadedPicture.url, '/assets/uploads/profile/' + uid + '-profileavatar.png'); | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 						assert.equal(uploadedPicture.path, path.join(nconf.get('base_dir'), 'public', 'uploads', 'profile', uid + '-profileavatar.png')); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 		it('should return error if profile image uploads disabled', function (done) { | 
					
						
							|  |  |  | 			meta.config.allowProfileImageUploads = 0; | 
					
						
							|  |  |  | 			var picture = { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 				path: path.join(nconf.get('base_dir'), 'test/files/test.png'), | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				size: 7189, | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 				name: 'test.png', | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				type: 'image/png', | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadPicture(uid, picture, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:profile-image-uploads-disabled]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 		it('should return error if profile image is too big', function (done) { | 
					
						
							|  |  |  | 			meta.config.allowProfileImageUploads = 1; | 
					
						
							|  |  |  | 			var picture = { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 				path: path.join(nconf.get('base_dir'), 'test/files/test.png'), | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				size: 265000, | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 				name: 'test.png', | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				type: 'image/png', | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadPicture(uid, picture, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:file-too-big, 256]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 		it('should return error if profile image has no mime type', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 			var picture = { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:27:56 +03:00
										 |  |  | 				path: path.join(nconf.get('base_dir'), 'test/files/test.png'), | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				size: 7189, | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				name: 'test', | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadPicture(uid, picture, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-29 23:16:23 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-image-extension]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 		it('should return error if no plugins listening for filter:uploadImage when uploading from url', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 			var url = nconf.get('url') + '/assets/logo.png'; | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadFromUrl(uid, url, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:no-plugin]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 		it('should return error if the extension is invalid when uploading from url', function (done) { | 
					
						
							|  |  |  | 			var url = nconf.get('url') + '/favicon.ico'; | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			function filterMethod(data, callback) { | 
					
						
							|  |  |  | 				callback(null, data); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			plugins.registerHook('test-plugin', { hook: 'filter:uploadImage', method: filterMethod }); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadFromUrl(uid, url, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-image-extension]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 		it('should return error if the file is too big when uploading from url', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 			var url = nconf.get('url') + '/assets/logo.png'; | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			meta.config.maximumProfileImageSize = 1; | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			function filterMethod(data, callback) { | 
					
						
							|  |  |  | 				callback(null, data); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			plugins.registerHook('test-plugin', { hook: 'filter:uploadImage', method: filterMethod }); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 20:27:58 +03:00
										 |  |  | 			User.uploadFromUrl(uid, url, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 				assert.equal(err.message, '[[error:file-too-big, ' + meta.config.maximumProfileImageSize + ']]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-20 21:58:35 +03:00
										 |  |  | 		it('should error with invalid data', function (done) { | 
					
						
							|  |  |  | 			var socketUser = require('../src/socket.io/user'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.uploadProfileImageFromUrl({ uid: uid }, { uid: uid, url: '' }, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:58:35 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 		it('should upload picture when uploading from url', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-20 21:58:35 +03:00
										 |  |  | 			var socketUser = require('../src/socket.io/user'); | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 			var url = nconf.get('url') + '/assets/logo.png'; | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			meta.config.maximumProfileImageSize = ''; | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			function filterMethod(data, callback) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				callback(null, { url: url }); | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			plugins.registerHook('test-plugin', { hook: 'filter:uploadImage', method: filterMethod }); | 
					
						
							| 
									
										
										
										
											2017-02-18 01:27:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.uploadProfileImageFromUrl({ uid: uid }, { uid: uid, url: url }, function (err, uploadedPicture) { | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-20 21:58:35 +03:00
										 |  |  | 				assert.equal(uploadedPicture, url); | 
					
						
							| 
									
										
										
										
											2016-12-30 00:51:22 +00:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should get profile pictures', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.getProfilePictures', { uid: uid }, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(data); | 
					
						
							|  |  |  | 				assert(Array.isArray(data)); | 
					
						
							|  |  |  | 				assert.equal(data[0].type, 'uploaded'); | 
					
						
							|  |  |  | 				assert.equal(data[0].text, '[[user:uploaded_picture]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove uploaded picture', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			io.emit('user.removeUploadedPicture', { uid: uid }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.getUserField(uid, 'uploadedpicture', function (err, uploadedpicture) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(uploadedpicture, ''); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-10 16:55:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 17:11:26 +03:00
										 |  |  | 		it('should load profile page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/api/user/updatedagain', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-10 17:11:26 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-10 16:55:22 +03:00
										 |  |  | 		it('should load settings page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/api/user/updatedagain/settings', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-10 16:55:22 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body.settings); | 
					
						
							|  |  |  | 				assert(body.languages); | 
					
						
							|  |  |  | 				assert(body.homePageRoutes); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-22 18:21:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-24 11:02:53 +03:00
										 |  |  | 		it('should load edit page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/api/user/updatedagain/edit', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-24 11:02:53 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should load edit/email page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/api/user/updatedagain/edit/email', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-24 11:02:53 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-22 18:21:57 +03:00
										 |  |  | 		it('should load user\'s groups page', function (done) { | 
					
						
							|  |  |  | 			groups.create({ | 
					
						
							|  |  |  | 				name: 'Test', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				description: 'Foobar!', | 
					
						
							| 
									
										
										
										
											2016-11-22 18:21:57 +03:00
										 |  |  | 			}, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				groups.join('Test', uid, function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 					request(nconf.get('url') + '/api/user/updatedagain/groups', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-22 18:21:57 +03:00
										 |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 						assert(Array.isArray(body.groups)); | 
					
						
							|  |  |  | 						assert.equal(body.groups[0].name, 'Test'); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-10-14 11:51:33 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-13 21:45:50 -04:00
										 |  |  | 	describe('user info', function () { | 
					
						
							|  |  |  | 		it('should return error if there is no ban reason', function (done) { | 
					
						
							|  |  |  | 			User.getLatestBanInfo(123, function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, 'no-ban-info'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should get history from set', function (done) { | 
					
						
							|  |  |  | 			var now = Date.now(); | 
					
						
							|  |  |  | 			db.sortedSetAdd('user:' + testUid + ':usernames', now, 'derp:' + now, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.getHistory('user:' + testUid + ':usernames', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(data[0].value, 'derp'); | 
					
						
							|  |  |  | 					assert.equal(data[0].timestamp, now); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 11:59:01 -05:00
										 |  |  | 		it('should return the correct ban reason', function (done) { | 
					
						
							|  |  |  | 			async.series([ | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					User.ban(testUid, 0, '', function (err) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						next(err); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					User.getModerationHistory(testUid, function (err, data) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.equal(data.bans.length, 1, 'one ban'); | 
					
						
							|  |  |  | 						assert.equal(data.bans[0].reason, '[[user:info.banned-no-reason]]', 'no ban reason'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						next(err); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-11-02 11:59:01 -05:00
										 |  |  | 			], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.unban(testUid, function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 	describe('digests', function () { | 
					
						
							|  |  |  | 		var uid; | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'digestuser', email: 'test@example.com' }, function (err, _uid) { | 
					
						
							| 
									
										
										
										
											2016-11-23 15:52:35 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 				uid = _uid; | 
					
						
							| 
									
										
										
										
											2016-11-23 15:52:35 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 		it('should send digests', function (done) { | 
					
						
							|  |  |  | 			User.updateDigestSetting(uid, 'day', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 02:38:03 -07:00
										 |  |  | 				User.digest.execute('day', function (err) { | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('socket methods', function () { | 
					
						
							|  |  |  | 		var socketUser = require('../src/socket.io/user'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should fail with invalid data', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.exists({ uid: testUid }, null, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return true if user/group exists', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.exists({ uid: testUid }, { username: 'registered-users' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(exists); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return true if user/group exists', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.exists({ uid: testUid }, { username: 'John Smith' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(exists); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return false if user/group does not exists', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.exists({ uid: testUid }, { username: 'doesnot exist' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(!exists); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 		it('should delete user', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'tobedeleted' }, function (err, _uid) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				socketUser.deleteAccount({ uid: _uid }, {}, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 					socketUser.exists({ uid: testUid }, { username: 'doesnot exist' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-01 18:59:24 +03:00
										 |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert(!exists); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should fail if data is invalid', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.emailExists({ uid: testUid }, null, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return true if email exists', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.emailExists({ uid: testUid }, { email: 'john@example.com' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(exists); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return false if email does not exist', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.emailExists({ uid: testUid }, { email: 'does@not.exist' }, function (err, exists) { | 
					
						
							| 
									
										
										
										
											2016-12-02 16:10:07 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(!exists); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if requireEmailConfirmation is disabled', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.emailConfirm({ uid: testUid }, {}, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:email-confirmations-are-disabled]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should send email confirm', function (done) { | 
					
						
							|  |  |  | 			Meta.config.requireEmailConfirmation = 1; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.emailConfirm({ uid: testUid }, {}, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				Meta.config.requireEmailConfirmation = 0; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should send reset email', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.reset.send({ uid: 0 }, 'john@example.com', function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return invalid-data error', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.reset.send({ uid: 0 }, null, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should not error', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.reset.send({ uid: 0 }, 'doestnot@exist.com', function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should commit reset', function (done) { | 
					
						
							|  |  |  | 			db.getObject('reset:uid', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				var code = Object.keys(data)[0]; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				socketUser.reset.commit({ uid: 0 }, { code: code, password: 'swordfish' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should save user settings', function (done) { | 
					
						
							|  |  |  | 			var data = { | 
					
						
							|  |  |  | 				uid: 1, | 
					
						
							|  |  |  | 				settings: { | 
					
						
							|  |  |  | 					bootswatchSkin: 'default', | 
					
						
							|  |  |  | 					homePageRoute: 'none', | 
					
						
							|  |  |  | 					homePageCustom: '', | 
					
						
							|  |  |  | 					openOutgoingLinksInNewTab: 0, | 
					
						
							|  |  |  | 					scrollToMyPost: 1, | 
					
						
							|  |  |  | 					delayImageLoading: 1, | 
					
						
							|  |  |  | 					userLang: 'en-GB', | 
					
						
							|  |  |  | 					usePagination: 1, | 
					
						
							|  |  |  | 					topicsPerPage: '10', | 
					
						
							|  |  |  | 					postsPerPage: '5', | 
					
						
							|  |  |  | 					showemail: 1, | 
					
						
							|  |  |  | 					showfullname: 1, | 
					
						
							|  |  |  | 					restrictChat: 0, | 
					
						
							|  |  |  | 					followTopicsOnCreate: 1, | 
					
						
							|  |  |  | 					followTopicsOnReply: 1, | 
					
						
							|  |  |  | 					notificationSound: '', | 
					
						
							|  |  |  | 					incomingChatSound: '', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					outgoingChatSound: '', | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketUser.saveSettings({ uid: testUid }, data, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-05-08 21:28:06 -04:00
										 |  |  | 				User.getSettings(testUid, function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(data.usePagination, true); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should set moderation note', function (done) { | 
					
						
							| 
									
										
										
										
											2017-05-13 22:12:52 -04:00
										 |  |  | 			var adminUid; | 
					
						
							|  |  |  | 			async.waterfall([ | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					User.create({ username: 'noteadmin' }, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (_adminUid, next) { | 
					
						
							|  |  |  | 					adminUid = _adminUid; | 
					
						
							|  |  |  | 					groups.join('administrators', adminUid, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'this is a test user' }, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					setTimeout(next, 50); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					socketUser.setModerationNote({ uid: adminUid }, { uid: testUid, note: 'second moderation note' }, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function (next) { | 
					
						
							|  |  |  | 					User.getModerationNotes(testUid, 0, -1, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			], function (err, notes) { | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-05-13 22:12:52 -04:00
										 |  |  | 				assert.equal(notes[0].note, 'second moderation note'); | 
					
						
							|  |  |  | 				assert.equal(notes[0].uid, adminUid); | 
					
						
							|  |  |  | 				assert(notes[0].timestamp); | 
					
						
							|  |  |  | 				done(); | 
					
						
							| 
									
										
										
										
											2016-12-02 17:05:46 +03:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-23 17:15:31 +03:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 	describe('approval queue', function () { | 
					
						
							|  |  |  | 		var socketAdmin = require('../src/socket.io/admin'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var oldRegistrationType; | 
					
						
							|  |  |  | 		var adminUid; | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							|  |  |  | 			oldRegistrationType = Meta.config.registrationType; | 
					
						
							|  |  |  | 			Meta.config.registrationType = 'admin-approval'; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			User.create({ username: 'admin', password: '123456' }, function (err, uid) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				adminUid = uid; | 
					
						
							|  |  |  | 				groups.join('administrators', uid, done); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		after(function (done) { | 
					
						
							|  |  |  | 			Meta.config.registrationType = oldRegistrationType; | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should add user to approval queue', function (done) { | 
					
						
							|  |  |  | 			helpers.registerUser({ | 
					
						
							|  |  |  | 				username: 'rejectme', | 
					
						
							|  |  |  | 				password: '123456', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				email: 'reject@me.com', | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 			}, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				helpers.loginUser('admin', '123456', function (err, jar) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 					request(nconf.get('url') + '/api/admin/manage/registration', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.equal(body.users[0].username, 'rejectme'); | 
					
						
							|  |  |  | 						assert.equal(body.users[0].email, 'reject@me.com'); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should reject user registration', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			socketAdmin.user.rejectRegistration({ uid: adminUid }, { username: 'rejectme' }, function (err) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.getRegistrationQueue(0, -1, function (err, users) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(users.length, 0); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should accept user registration', function (done) { | 
					
						
							|  |  |  | 			helpers.registerUser({ | 
					
						
							|  |  |  | 				username: 'acceptme', | 
					
						
							|  |  |  | 				password: '123456', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				email: 'accept@me.com', | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 			}, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				socketAdmin.user.acceptRegistration({ uid: adminUid }, { username: 'acceptme' }, function (err, uid) { | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					User.exists(uid, function (err, exists) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert(exists); | 
					
						
							|  |  |  | 						User.getRegistrationQueue(0, -1, function (err, users) { | 
					
						
							|  |  |  | 							assert.ifError(err); | 
					
						
							|  |  |  | 							assert.equal(users.length, 0); | 
					
						
							|  |  |  | 							done(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 	describe('invites', function () { | 
					
						
							|  |  |  | 		var socketUser = require('../src/socket.io/user'); | 
					
						
							|  |  |  | 		var inviterUid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							|  |  |  | 			User.create({ | 
					
						
							|  |  |  | 				username: 'inviter', | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				email: 'inviter@nodebb.org', | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 			}, function (err, uid) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				inviterUid = uid; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error with invalid data', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, null, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should eror if forum is not invite only', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:forum-not-invite-only]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if user is not admin and type is admin-invite-only', function (done) { | 
					
						
							|  |  |  | 			meta.config.registrationType = 'admin-invite-only'; | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:no-privileges]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should send invitation email', function (done) { | 
					
						
							|  |  |  | 			meta.config.registrationType = 'invite-only'; | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if ouf of invitations', function (done) { | 
					
						
							|  |  |  | 			meta.config.maximumInvites = 1; | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'invite2@test.com', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invite-maximum-met, ' + 1 + ', ' + 1 + ']]'); | 
					
						
							|  |  |  | 				meta.config.maximumInvites = 5; | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if email exists', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'inviter@nodebb.org', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:email-taken]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should send invitation email', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketUser.invite({ uid: inviterUid }, 'invite2@test.com', function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should get user\'s invites', function (done) { | 
					
						
							|  |  |  | 			User.getInvites(inviterUid, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-21 15:18:01 +03:00
										 |  |  | 				assert.notEqual(data.indexOf('invite1@test.com'), -1); | 
					
						
							|  |  |  | 				assert.notEqual(data.indexOf('invite2@test.com'), -1); | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should get all invites', function (done) { | 
					
						
							|  |  |  | 			User.getAllInvites(function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-21 15:18:01 +03:00
										 |  |  | 				assert.equal(data[0].uid, inviterUid); | 
					
						
							|  |  |  | 				assert.notEqual(data[0].invitations.indexOf('invite1@test.com'), -1); | 
					
						
							|  |  |  | 				assert.notEqual(data[0].invitations.indexOf('invite2@test.com'), -1); | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should fail to verify invitation with invalid data', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			User.verifyInvitation({ token: '', email: '' }, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should fail to verify invitation with invalid email', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			User.verifyInvitation({ token: 'test', email: 'doesnotexist@test.com' }, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-token]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should verify installation with no errors', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			var email = 'invite1@test.com'; | 
					
						
							|  |  |  | 			db.get('invitation:email:' + email, function (err, token) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 				User.verifyInvitation({ token: token, email: 'invite1@test.com' }, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error with invalid username', function (done) { | 
					
						
							|  |  |  | 			User.deleteInvitation('doesnotexist', 'test@test.com', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-username]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should delete invitation', function (done) { | 
					
						
							|  |  |  | 			var socketAdmin = require('../src/socket.io/admin'); | 
					
						
							| 
									
										
										
										
											2017-02-23 18:31:49 -07:00
										 |  |  | 			socketAdmin.user.deleteInvitation({ uid: inviterUid }, { invitedBy: 'inviter', email: 'invite1@test.com' }, function (err) { | 
					
						
							| 
									
										
										
										
											2017-02-21 15:08:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.isSetMember('invitation:uid:' + inviterUid, 'invite1@test.com', function (err, isMember) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(isMember, false); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should delete invitation key', function (done) { | 
					
						
							|  |  |  | 			User.deleteInvitationKey('invite2@test.com', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.isSetMember('invitation:uid:' + inviterUid, 'invite2@test.com', function (err, isMember) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.equal(isMember, false); | 
					
						
							|  |  |  | 					db.isSetMember('invitation:uids', inviterUid, function (err, isMember) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.equal(isMember, false); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-02 14:05:54 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-11 16:43:19 +03:00
										 |  |  | 	describe('email confirm', function () { | 
					
						
							|  |  |  | 		it('should error with invalid code', function (done) { | 
					
						
							|  |  |  | 			User.email.confirm('asdasda', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should confirm email of user', function (done) { | 
					
						
							|  |  |  | 			var email = 'confirm@me.com'; | 
					
						
							|  |  |  | 			User.create({ | 
					
						
							|  |  |  | 				username: 'confirme', | 
					
						
							|  |  |  | 				email: email, | 
					
						
							|  |  |  | 			}, function (err, uid) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				User.email.sendValidationEmail(uid, email, function (err, code) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					User.email.confirm(code, function (err) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						async.parallel({ | 
					
						
							|  |  |  | 							confirmed: function (next) { | 
					
						
							|  |  |  | 								db.getObjectField('user:' + uid, 'email:confirmed', next); | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							isMember: function (next) { | 
					
						
							|  |  |  | 								db.isSortedSetMember('users:notvalidated', uid, next); | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 						}, function (err, results) { | 
					
						
							|  |  |  | 							assert.ifError(err); | 
					
						
							|  |  |  | 							assert.equal(results.confirmed, 1); | 
					
						
							|  |  |  | 							assert.equal(results.isMember, false); | 
					
						
							|  |  |  | 							done(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-08 22:10:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	after(function (done) { | 
					
						
							| 
									
										
										
										
											2016-10-17 23:34:09 +03:00
										 |  |  | 		db.emptydb(done); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-11-02 11:59:01 -05:00
										 |  |  | }); |