<commit_before>import test from "ava"

import {FormData, File} from "formdata-node"

import {BodyFileDataItem} from "./BodyFileDataItem"
import {Body, BodyRawEntries} from "./Body"
import {BodyField} from "./BodyField"

interface Developer {
  name: string,
  isHireable: boolean
  skills: [string, ...string[]]
  dates: {
    createdAt: string
    updatedAt: string
    deletedAt?: string
  }
}

test("Creates an empty Body", t => {
  const body = new Body([])

  t.is(body.length, 0)
})

test("Creates Body with scalar field", t => {
  const body = new Body([
    [["field"], "value"]
  ])

  const [actual] = [...body.values()]

  t.true(actual instanceof BodyField)
  t.is((actual as BodyField).valueOf(), "value")
})

test("Creates Body with a BodyFileDataItem", t => {
  const file = new BodyFileDataItem({
    file: new File(["Some content"], "file.txt"),
    path: "/path/to/a/file"
  })

  const body = new Body([[["file"], file]])

  const [actual] = [...body.values()]

  t.true(actual instanceof BodyFileDataItem)
})<commit_msg>Add few more tests for Body<commit_after>import test from "ava"

import {FormData, File} from "formdata-node"

import {BodyFileDataItem} from "./BodyFileDataItem"
import {Body, BodyRawEntries} from "./Body"
import {BodyField} from "./BodyField"

interface Developer {
  name: string,
  isHireable: boolean
  skills: [string, ...string[]]
  dates: {
    createdAt: string
    updatedAt: string
    deletedAt?: string
  }
}

test("Creates an empty Body", t => {
  const body = new Body([])

  t.is(body.length, 0)
})

test("Empty body can be converted to an object", t => {
  const body = new Body([])

  t.deepEqual(body.json(), {})
})

test("Empty body can be converted to a FormData", t => {
  const body = new Body([])

  const actual = body.formData()

  t.true(actual instanceof FormData, "Must be a FormData instance")
  t.deepEqual([...actual], [], "Must be empty")
})

test("Creates Body with scalar field", t => {
  const body = new Body([
    [["field"], "value"]
  ])

  const [actual] = [...body.values()]

  t.true(actual instanceof BodyField)
  t.is((actual as BodyField).valueOf(), "value")
})

test("Creates Body with a BodyFileDataItem", t => {
  const file = new BodyFileDataItem({
    file: new File(["Some content"], "file.txt"),
    path: "/path/to/a/file"
  })

  const body = new Body([[["file"], file]])

  const [actual] = [...body.values()]

  t.true(actual instanceof BodyFileDataItem)
})
{'fraction_non_alphanumeric': 0.1691116544417278, 'fraction_numerical': 0.0008149959250203749, 'mean_word_length': 3.7211538461538463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2831915', 'n_tokens_mistral': 817, 'n_tokens_neox': 812, 'n_words': 245}