| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | // this test currently needs to talk to the redis database.
 | 
					
						
							|  |  |  | // get the redis config info from root directory's config.json:
 | 
					
						
							|  |  |  | var winston = require('winston'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | process.on('uncaughtException', function (err) { | 
					
						
							|  |  |  | 	winston.error('Encountered error while running test suite: ' + err.message); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var	assert = require('assert'), | 
					
						
							| 
									
										
										
										
											2014-09-24 13:52:49 -04:00
										 |  |  | 	db = require('./mocks/databasemock'); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | var User = require('../src/user'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('User', function() { | 
					
						
							|  |  |  | 	var	userData; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	beforeEach(function(){ | 
					
						
							|  |  |  | 		userData = { | 
					
						
							| 
									
										
										
										
											2014-03-06 14:51:43 -05:00
										 |  |  | 			username: 'John Smith', | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 			password: 'swordfish', | 
					
						
							|  |  |  | 			email: 'john@example.com', | 
					
						
							|  |  |  | 			callback: undefined | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('when created', function() { | 
					
						
							| 
									
										
										
										
											2014-03-06 14:51:43 -05:00
										 |  |  | 		it('should be created properly', function(done) { | 
					
						
							|  |  |  | 			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); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 12:41:35 -05:00
										 |  |  | 		it('should have a valid email, if using an email', function() { | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 			assert.throws( | 
					
						
							| 
									
										
										
										
											2014-03-06 14:51:43 -05:00
										 |  |  | 				User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function(){}), | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 				Error, | 
					
						
							|  |  |  | 				'does not validate email' | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	after(function() { | 
					
						
							| 
									
										
										
										
											2013-12-06 13:21:21 -05:00
										 |  |  | 		db.flushdb(); | 
					
						
							| 
									
										
										
										
											2013-11-04 01:32:31 +02:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | }); |