<commit_before>'use strict'

const assert = require('assert')

describe('api.services.FootprintService', () => {
  let FootprintService
  before(() => {
    FootprintService = global.app.services.FootprintService
  })
  describe('#create', () => {
    it('should insert a record', () => {
      return FootprintService.create('Role', {name: 'createtest'})
        .then(role => {
          assert.equal(role.name, 'createtest')
        })
    })
    // TODO Insert RECORD with CHILD
    // it('should insert a record with child', () => {
    //   return FootprintService.create('User', {name: 'userTest', roles: [{name: 'roleTest'}]}, {populate: 'roles'})
    //     .then(user => {
    //       console.log(user)
    //       assert.equal(user.name, 'userTest')
    //       assert.equal(user.roles.length, 1)
    //       assert.equal(user.roles[0].name, 'roleTest')
    //     })
    // })
    it('should return a not found error', () => {
      return FootprintService.create('UnknowModel', {name: 'userTest'})
        .catch(err => {
          assert.equal(err.code, 'E_NOT_FOUND')
          assert.equal(err.message, 'UnknowModel can\'t be found')
          assert.equal(err.name, 'Model error')
        })
    })
    it('should return a validation error', () => {
      return FootprintService.create('User', {roles: [{name: 'roleTest'}]}, {populate: 'roles'})
        .catch(err => {
          assert.equal(err.code, 'E_VALIDATION')
          assert.equal(err.message, 'notNull Violation: name cannot be null')
          assert.equal(err.errors[0].path, 'name')
          assert.equal(err.errors[0].message, 'name cannot be null')
          assert.equal(err.errors[0].type, 'notNull Violation')
          assert.equal(err.name, 'Model error')
        })
    })
  })
  describe('#find', () => {
    it('should find a single record', () => {
      return FootprintService.create('Role', {name: 'findtest'})
        .then(role => {
          console.log(role)
          assert.equal(role.name, 'findtest')
          assert(role.id)
          return FootprintService.find('Role', role.id)
        })
        .then(role => {
          assert(!role.length)
          assert.equal(role.name, 'findtest')
        })
    })
    it('should find a set of records', () => {
      return FootprintService.create('Role', {name: 'findtest'})
        .then(role => {
          assert.equal(role.name, 'findtest')<commit_msg>remove console<commit_after>'use strict'

const assert = require('assert')

describe('api.services.FootprintService', () => {
  let FootprintService
  before(() => {
    FootprintService = global.app.services.FootprintService
  })
  describe('#create', () => {
    it('should insert a record', () => {
      return FootprintService.create('Role', {name: 'createtest'})
        .then(role => {
          assert.equal(role.name, 'createtest')
        })
    })
    // TODO Insert RECORD with CHILD
    // it('should insert a record with child', () => {
    //   return FootprintService.create('User', {name: 'userTest', roles: [{name: 'roleTest'}]}, {populate: 'roles'})
    //     .then(user => {
    //       console.log(user)
    //       assert.equal(user.name, 'userTest')
    //       assert.equal(user.roles.length, 1)
    //       assert.equal(user.roles[0].name, 'roleTest')
    //     })
    // })
    it('should return a not found error', () => {
      return FootprintService.create('UnknowModel', {name: 'userTest'})
        .catch(err => {
          assert.equal(err.code, 'E_NOT_FOUND')
          assert.equal(err.message, 'UnknowModel can\'t be found')
          assert.equal(err.name, 'Model error')
        })
    })
    it('should return a validation error', () => {
      return FootprintService.create('User', {roles: [{name: 'roleTest'}]}, {populate: 'roles'})
        .catch(err => {
          assert.equal(err.code, 'E_VALIDATION')
          assert.equal(err.message, 'notNull Violation: name cannot be null')
          assert.equal(err.errors[0].path, 'name')
          assert.equal(err.errors[0].message, 'name cannot be null')
          assert.equal(err.errors[0].type, 'notNull Violation')
          assert.equal(err.name, 'Model error')
        })
    })
  })
  describe('#find', () => {
    it('should find a single record', () => {
      return FootprintService.create('Role', {name: 'findtest'})
        .then(role => {
          assert.equal(role.name, 'findtest')
          assert(role.id)
          return FootprintService.find('Role', role.id)
        })
        .then(role => {
          assert(!role.length)
          assert.equal(role.name, 'findtest')
        })
    })
    it('should find a set of records', () => {
      return FootprintService.create('Role', {name: 'findtest'})
        .then(role => {
          assert.equal(role.name, 'findtest')
{'fraction_non_alphanumeric': 0.17585848074921956, 'fraction_numerical': 0.002081165452653486, 'mean_word_length': 2.423076923076923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '3090938', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1479, 'n_words': 287}