Commit 5d70b114 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement Comments#getById.

parent afed223f
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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.
+29 −1
Original line number Diff line number Diff line
@@ -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();