Loading comments/comments.js +20 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,26 @@ module.exports = (function(){ } Comments.prototype = { /** * Finds a single comment by ID. * Excludes deleted comments. * * @param {Number} id The ID of the comment to find. * @param {Function} callback Called with the result. * @param {Object} callback.comment The comment found or undefined. */ getById: function(id, callback) { var sql = [ 'SELECT *', 'FROM full_visible_comments', 'WHERE domain = ? AND id = ?' ]; this.query(sql, [this.domain, id], function(rows) { callback(rows[0]); }); }, /** * Finds list of all comments for a particular target. * Excludes deleted comments. Loading comments/comments.spec.js +29 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,35 @@ describe("Comments", function() { connection.end(); }); it("#find returns comments for a target", function(done) { it("#getById returns comment with given ID", function(done) { comments.getById(7, function(com) { expect(com.id).toEqual(7); done(); }); }); it("#getById returns undefined when no comment with such ID", function(done) { comments.getById(123456, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#getById returns undefined when ID exists in other domain.", function(done) { comments.getById(30, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#getById returns undefined when comment with ID is deleted", function(done) { comments.getById(6, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#find returns all undeleted comments for a target", function(done) { comments.find({type: "class", cls: "Ext", member: ""}, function(rows) { expect(rows.length).toEqual(5); done(); Loading Loading
comments/comments.js +20 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,26 @@ module.exports = (function(){ } Comments.prototype = { /** * Finds a single comment by ID. * Excludes deleted comments. * * @param {Number} id The ID of the comment to find. * @param {Function} callback Called with the result. * @param {Object} callback.comment The comment found or undefined. */ getById: function(id, callback) { var sql = [ 'SELECT *', 'FROM full_visible_comments', 'WHERE domain = ? AND id = ?' ]; this.query(sql, [this.domain, id], function(rows) { callback(rows[0]); }); }, /** * Finds list of all comments for a particular target. * Excludes deleted comments. Loading
comments/comments.spec.js +29 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,35 @@ describe("Comments", function() { connection.end(); }); it("#find returns comments for a target", function(done) { it("#getById returns comment with given ID", function(done) { comments.getById(7, function(com) { expect(com.id).toEqual(7); done(); }); }); it("#getById returns undefined when no comment with such ID", function(done) { comments.getById(123456, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#getById returns undefined when ID exists in other domain.", function(done) { comments.getById(30, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#getById returns undefined when comment with ID is deleted", function(done) { comments.getById(6, function(com) { expect(com).toEqual(undefined); done(); }); }); it("#find returns all undeleted comments for a target", function(done) { comments.find({type: "class", cls: "Ext", member: ""}, function(rows) { expect(rows.length).toEqual(5); done(); Loading