<commit_before>var setup = require(require('root-path')('test/setup'))
var CommentController = require(require('root-path')('api/controllers/CommentController'))

describe('CommentController', function () {
  var fixtures, req, res

  before(function (done) {
    setup.clearDb().then(function () {
      return Promise.props({
        u1: new User({name: 'U1', email: 'a<EMAIL>'}).save(),
        u2: new User({name: 'U2', email: 'b@b.c'}).save(),
        u3: new User({name: 'U3', email: 'c<EMAIL>'}).save(),
        p1: new Post({name: 'P1', active: true}).save(),
        c1: new Community({name: 'C1', slug: 'c1'}).save()
      })
    })
      .then(function (props) {
        fixtures = props
        done()
      })
  })

  describe('#create', function () {
    before(function () {
      req = {
        session: {userId: fixtures.u1.id}
      }
    })

    it('creates a comment', function () {
      var commentText = format('<p>Hey <a data-user-id="%s">U2</a> and <a data-user-id="%s">U3</a>! )</p>',
          fixtures.u2.id, fixtures.u3.id)
      var responseData

      req.param = function (name) {
        if (name === 'text') return commentText
      }

      res = {
        locals: {post: fixtures.p1},
        serverError: spy(console.error),
        ok: spy(function (x) { responseData = x })
      }

      return CommentController.create(req, res)
        .then(function () {
          expect(res.ok).to.have.been.called()
          expect(res.serverError).not.to.have.been.called()
          expect(responseData).to.exist
          expect(responseData.user).to.exist
          expect(responseData.text).to.equal(commentText)
          return fixtures.p1.load('comments')
        })
        .then(post => {
          var comment = post.relations.comments.first()

          var job = require('kue').getJobs()[0]
          expect(job).to.exist
          expect(job.type).to.equal('classMethod')
          expect(job.data).to.deep.equal({
            className: 'Comment',
            methodName: 'sendNotifications',
            commentId: comment.id
          })
        })<commit_msg>fix comment controller test<commit_after>var setup = require(require('root-path')('test/setup'))
var CommentController = require(require('root-path')('api/controllers/CommentController'))

describe('CommentController', function () {
  var fixtures, req, res

  before(function (done) {
    setup.clearDb().then(function () {
      return Promise.props({
        u1: new User({name: 'U1', email: 'a@b.c'}).save(),
        u2: new User({name: 'U2', email: 'b@b.c'}).save(),
        u3: new User({name: 'U3', email: 'c<EMAIL>'}).save(),
        p1: new Post({name: 'P1', active: true}).save(),
        c1: new Community({name: 'C1', slug: 'c1'}).save()
      })
    })
      .then(function (props) {
        fixtures = props
        done()
      })
  })

  describe('#create', function () {
    before(function () {
      req = {
        session: {userId: fixtures.u1.id}
      }
    })

    it('creates a comment', function () {
      var commentText = format('<p>Hey <a data-user-id="%s">U2</a> and <a data-user-id="%s">U3</a>! )</p>',
          fixtures.u2.id, fixtures.u3.id)
      var responseData

      req.param = function (name) {
        if (name === 'text') return commentText
      }

      res = {
        locals: {post: fixtures.p1},
        serverError: spy(console.error),
        ok: spy(function (x) { responseData = x })
      }

      return CommentController.create(req, res)
        .then(function () {
          expect(res.ok).to.have.been.called()
          expect(res.serverError).not.to.have.been.called()
          expect(responseData).to.exist
          expect(responseData.user).to.exist
          expect(responseData.text).to.equal(commentText)
          return fixtures.p1.load('comments')
        })
        .then(post => {
          var comment = post.relations.comments.first()

          var job = _.find(require('kue').getJobs(), job => job.data.commentId === comment.id)
          expect(job).to.exist
          expect(job.type).to.equal('classMethod')
          expect(job.data).to.deep.equal({
            className: 'Comment',
            methodName: 'sendNotifications',
            commentId: comment.id
          })
        })
{'fraction_non_alphanumeric': 0.1736078614880674, 'fraction_numerical': 0.008656995788488536, 'mean_word_length': 2.298611111111111, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4325120', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1335, 'n_words': 250}