2014-01-24 00:42:34 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-30 01:03:45 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								var winston = require('winston');
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-13 15:10:19 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								process.on('uncaughtException', function (err) {
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-16 14:08:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									winston.error('Encountered error while running test suite: ' + err.message);
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-13 15:10:19 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								var	assert = require('assert'),
							 | 
						
					
						
							
								
									
										
										
										
											2014-09-24 13:52:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									db = require('./mocks/databasemock');
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-16 14:08:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								var Categories = require('../src/categories');
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe('Categories', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var	categoryObj;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									describe('.create', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										it('should create a new category', function(done) {
							 | 
						
					
						
							
								
									
										
										
										
											2013-12-06 13:21:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											Categories.create({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												name: 'Test Category',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												description: 'Test category created by testing script',
							 | 
						
					
						
							
								
									
										
										
										
											2013-11-26 14:25:46 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												icon: 'fa-check',
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												blockclass: 'category-blue',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												order: '5'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}, function(err, category) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												categoryObj = category;
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 13:50:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												done.apply(this, arguments);
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									describe('.getCategoryById', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										it('should retrieve a newly created category by its ID', function(done) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-25 19:19:25 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											Categories.getCategoryById(categoryObj.cid, 0, -1, 0, function(err, categoryData) {
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												assert(categoryData);
							 | 
						
					
						
							
								
									
										
										
										
											2014-02-26 16:43:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												assert.equal(categoryObj.name, categoryData.name);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												assert.equal(categoryObj.description, categoryData.description);
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									describe('.getCategoryTopics', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										it('should return a list of topics', function(done) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											Categories.getCategoryTopics(categoryObj.cid, 0, 10, 0, function(err, result) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												assert(Array.isArray(result.topics));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												assert(result.topics.every(function(topic) {
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													return topic instanceof Object;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									after(function() {
							 | 
						
					
						
							
								
									
										
										
										
											2013-12-06 13:21:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										db.delete('category:' + categoryObj.cid);
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-08 17:21:04 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										db.sortedSetRemove('categories:cid', categoryObj.cid);
							 | 
						
					
						
							
								
									
										
										
										
											2013-10-12 11:06:43 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							
								
									
										
										
										
											2014-01-24 00:42:34 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								});
							 |