<commit_before>'use strict'
const { get, post } = require('./support/request')
const db = require('./support/db')
const { asyncWrap } = require('./support/nodeunit')
const app = require('./support/app')
const auth = require('./support/auth')
const rat = require('./support/rat')
const { HTTP_CREATED, HTTP_OK } = require('./support/const')

module.exports = {
  setUp: async function (test) {
    await db.init()
    await app.init()
    test()
  },
  /**
   * @api {post} /rats Create rat
   * @apiName CreateRat
   * @apiGroup Rat
   * 
   * @apiHeader {String} Cookie auth token
   * @apiParam {String} name
   * @apiParam {String} platform
   * @apiPermission user.write
   * @apiSuccess (201) {Object} data Rat data 
   */
  ratCreate: asyncWrap(async function (test) {

    const NUM_TESTS = 5
    test.expect(NUM_TESTS)

    const adminUser = await auth.adminUser()
    const data = {
      name: 'roland',
      platform: 'xb'
    }

    let create = await new post(adminUser, '/rats', data)

    let res = create.body

    test.strictEqual(create.response.statusCode, HTTP_CREATED)
    test.ifError(res.error)

    if (res.data) {
      let { attributes } = res.data
      test.notEqual(res.data.id, null)
      test.strictEqual(attributes.name, data.name)
      test.strictEqual(attributes.platform, data.platform)
    }

  }),
  /**
   * @api {get} /rats/:id Find rat
   * @apiName FindRatById
   * @apiGroup Rat
   * 
   * @apiHeader {String} Cookie auth token
   * @apiParam {String} id rat id
   */
  ratFindById: asyncWrap(async function (test) {
    
    const NUM_TESTS = 5
    test.expect(NUM_TESTS)

    const adminUser = await auth.adminUser()

    const newRat = {
      name: 'roland',
      platform: 'xb'
    }

    const res = await rat.create(adminUser, newRat)

    const find = await get(adminUser, '/rats/' + res.id)

    test.strictEqual(find.response.statusCode, HTTP_OK)
    if (find.body) {
      let { data } = find.body
      test.strictEqual(data.length, 1) // should have only one rat returned
      test.strictEqual(data[0].id, res.id)
      const attr = data[0].attributes
      test.strictEqual(attr.name, newRat.name)
      test.strictEqual(attr.platform, newRat.platform)
    }
  })
}<commit_msg>added rat findByName test<commit_after>'use strict'
const { get, post } = require('./support/request')
const db = require('./support/db')
const { asyncWrap } = require('./support/nodeunit')
const app = require('./support/app')
const auth = require('./support/auth')
const rat = require('./support/rat')
const { HTTP_CREATED, HTTP_OK } = require('./support/const')

module.exports = {
  setUp: async function (test) {
    await db.init()
    await app.init()
    test()
  },
  /**
   * @api {post} /rats Create rat
   * @apiName CreateRat
   * @apiGroup Rat
   * 
   * @apiHeader {String} Cookie auth token
   * @apiParam {String} name
   * @apiParam {String} platform
   * @apiPermission user.write
   * @apiSuccess (201) {Object} data Rat data 
   * 
   * @apiExample
   * POST /rats HTTP/1.1 
   * Cookie: fuelrats:session=<KEY>; path=/; httponly;
   * Content-Type: application/json
   * 
   * {
   *  "name": "roland",
   *  "platform": "xb"
   * }
   */
  ratCreate: asyncWrap(async function (test) {

    const NUM_TESTS = 5
    test.expect(NUM_TESTS)

    const adminUser = await auth.adminUser()
    const data = {
      name: 'roland',
      platform: 'xb'
    }

    let create = await new post(adminUser, '/rats', data)

    let res = create.body

    test.strictEqual(create.response.statusCode, HTTP_CREATED)
    test.ifError(res.error)

    if (res.data) {
      let { attributes } = res.data
      test.notEqual(res.data.id, null)
      test.strictEqual(attributes.name, data.name)
      test.strictEqual(attributes.platform, data.platform)
    }

  }),
  /**
   * @api {get} /rats/:id Find rat
   * @apiName FindRatById
   * @apiGroup Rat
   * 
   * @apiHeader {String} Cookie auth token
   * @apiParam {String} id rat id
   *    
   * @apiExample
   * GET /rats/afd9d83c-3b4b-4ad5-844b-4719850becff HTTP/1.1 
   * Cookie: fuelrats:session=<KEY>; path=/; httponly;
   * Content-Type: application/json
   */
  ratFindById: asyncWrap(async function (test) {
    
    const NUM_TESTS = 5
    test.expect(NUM_TESTS)

    const adminUser = await auth.adminUser()

    const newRat = {
      name: 'roland',
      platform: 'xb'
    }

    const res = await rat.create(adminUser, newRat)

    const find = await get(adminUser, '/rats/' + res.id)

    test.strictEqual(find.response.statusCode, HTTP_OK)
    if (find.body) {
      let { data } = find.body
      test.strictEqual(data.length, 1) // should have only one rat returned
      test.strictEqual(data[0].id, res.id)
      const attr = data[0].attributes
      test.strictEqual(attr.name, newRat.name)
      test.strictEqual(attr.platform, newRat.platform)
    }
  }),
  /**
   * @api {get} /rats Find rat by attribute
   * @apiName FindRat
   * @apiGroup Rat
   * 
   * @apiHeader {String} Cookie auth token
   * 
   * @apiExample
   * GET /rats?name=roland HTTP/1.1 
   * Cookie: fuelrats:session=<KEY>; path=/; httponly;
   * Content-Type: application/json
   * 
   */
  ratFindByName: asyncWrap(async function (test) {
    
    const NUM_TESTS = 5
    test.expect(NUM_TESTS)

    const adminUser = await auth.adminUser()

    const newRat = {
      name: 'roland',
      platform: 'xb'
    }

    const res = await rat.create(adminUser, newRat)

    const find = await get(adminUser, '/rats?name=' + newRat.name)

    test.strictEqual(find.response.statusCode, HTTP_OK)
    if (find.body) {
      let { data } = find.body
      test.strictEqual(data.length, 1) // should have only one rat returned
      test.strictEqual(data[0].id, res.id)
      const attr = data[0].attributes
      test.strictEqual(attr.name, newRat.name)
      test.strictEqual(attr.platform, newRat.platform)
    }
  })
}
{'fraction_non_alphanumeric': 0.13774991528295494, 'fraction_numerical': 0.007285665875974246, 'mean_word_length': 2.7337128399746997, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 6, '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': '6288379', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1965, 'n_words': 460}