<commit_before>/**
 * Test dependencies.
 */
const Coral = require('../../lib/coral')
const db = require('../helper/db')
const express = require('express')
const request = require('supertest')
const bodyParser = require('body-parser')
const app = express()

describe('Coral subDoc post tests', () => {
  // require to get req body parameters
  app.use(bodyParser.json())

  beforeEach((done) => {
    db.connect()
    db.initialise(done)
  })

  afterEach((done) => {
    db.disconnect(done)
  })

  it('subDoc post - must create proper post route and return matching record', (done) => {
    // config to pass router find method
    const config = {
      path: '/localhost/articles/:name/comments',
      model: db.getModel('Article'),
      methods: ['POST'],
      conditions: {
        name: 'article-one'
      },
      subDoc: {
        path: 'comments'
      }
    }

    // data to be pass into post request
    const data = {
      'name': 'comment-three',
      'body': 'Article One Third Comment',
      'replies': [{
        'name': 'reply-one',
        'body': 'Article One Third Comment First Reply'
      }]
    }

    // call router get with the config
    app.use(new Coral(config))

    // invoke path with supertest
    request(app)
      .post('/localhost/articles/article-one/comments')
      .set('accept', 'application/json')
      .send(data)
      .expect(200)
      .end((err, res) => {
        res.body.name.should.equal('comment-three')
        console.log(err)
        done(err) // pass err so that fail expect errors will get caught
      })
  })

  it('sub subDoc post - must create proper post route and return matching record', (done) => {
    // config to pass router find method
    const config = {
      path: '/localhost/articles/:articleName/comments/:commentName/replies',
      model: db.getModel('Article'),
      methods: ['POST'],
      conditions: {
        name: 'article-one'
      },
      subDoc: {
        path: 'comments',
        idAttribute: 'name',<commit_msg>unit tests<commit_after>/**
 * Test dependencies.
 */
const Coral = require('../../lib/coral')
const db = require('../helper/db')
const express = require('express')
const request = require('supertest')
const bodyParser = require('body-parser')
const app = express()

describe('Coral subDoc post tests', () => {
  // require to get req body parameters
  app.use(bodyParser.json())

  beforeEach((done) => {
    db.connect()
    db.initialise(done)
  })

  afterEach((done) => {
    db.disconnect(done)
  })

  it('subDoc post - must create proper post route and return matching record', (done) => {
    // config to pass router find method
    const config = {
      path: '/localhost/articles/:name/comments',
      model: db.getModel('Article'),
      methods: ['POST'],
      conditions: {
        name: 'article-one'
      },
      subDoc: {
        path: 'comments'
      }
    }

    // data to be pass into post request
    const data = {
      'name': 'comment-three',
      'body': 'Article One Third Comment',
      'replies': [{
        'name': 'reply-one',
        'body': 'Article One Third Comment First Reply'
      }]
    }

    // call router get with the config
    app.use(new Coral(config))

    // invoke path with supertest
    request(app)
      .post('/localhost/articles/article-one/comments')
      .set('accept', 'application/json')
      .send(data)
      .expect(200)
      .end((err, res) => {
        res.body.name.should.equal('comment-three')
        done(err) // pass err so that fail expect errors will get caught
      })
  })

  xit('sub subDoc post - must create proper post route and return matching record', (done) => {
    // config to pass router find method
    const config = {
      path: '/localhost/articles/:articleName/comments/:commentName/replies',
      model: db.getModel('Article'),
      methods: ['POST'],
      conditions: {
        name: 'article-one'
      },
      subDoc: {
        path: 'comments',
        idAttribute: 'name',
{'fraction_non_alphanumeric': 0.14963777167124656, 'fraction_numerical': 0.0014988758431176618, 'mean_word_length': 2.422222222222222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6708727', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1167, 'n_words': 325}