From 13d8f51f6a0dcbe9ec599486d98ace8c01f276a0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 12 Oct 2013 11:06:43 -0400 Subject: [PATCH] added test file for categories (incomplete) re: issue #391 --- package.json | 6 +++++ tests/categories.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/categories.js diff --git a/package.json b/package.json index bf5ecce935..3fbfcca32e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "url": "https://github.com/designcreateplay/NodeBB/" }, "main": "app.js", + "scripts": { + "test": "mocha ./tests" + }, "dependencies": { "socket.io": "~0.9.16", "redis": "0.8.3", @@ -44,6 +47,9 @@ "optionalDependencies": { "hiredis": "~0.1.15" }, + "devDependencies": { + "mocha": "~1.13.0" + }, "bugs": { "url": "https://github.com/designcreateplay/NodeBB/issues" }, diff --git a/tests/categories.js b/tests/categories.js new file mode 100644 index 0000000000..81d97c5f61 --- /dev/null +++ b/tests/categories.js @@ -0,0 +1,54 @@ +var assert = require('assert'), + RDB = require('../src/redis'), + Categories = require('../src/categories'); + +describe('Categories', function() { + var categoryObj; + + describe('.create', function() { + it('should create a new category', function(done) { + Categories.create({ + name: 'Test Category', + description: 'Test category created by testing script', + icon: 'icon-ok', + blockclass: 'category-blue', + order: '5' + }, function(err, category) { + categoryObj = category; + done.apply(arguments); + }); + }); + }); + + describe('.getCategoryById', function() { + it('should retrieve a newly created category by its ID', function(done) { + Categories.getCategoryById(categoryObj.cid, 0, function(err, categoryData) { + assert(categoryData); + assert.equal(categoryObj.name, categoryData.category_name); + assert.equal(categoryObj.description, categoryData.category_description); + + done(); + }); + }); + }); + + describe('.getCategoryTopics', function() { + it('should return a list of topics', function(done) { + Categories.getCategoryTopics(categoryObj.cid, 0, 10, 0, function(topics) { + assert(Array.isArray(topics)); + assert(topics.every(function(topic) { + return topic instanceof Object; + })); + + done(); + }); + }); + }); + + after(function() { + RDB.multi() + .del('category:'+categoryObj.cid) + .rpop('categories:cid') + .exec(); + }); +}); \ No newline at end of file