<commit_before>const fse = require('fs-extra');
const isEqual = require('lodash/isEqual');
const path = require('path');
const stringToArrayBuffer = require('string-to-arraybuffer');
const tmp = require('tmp');
const { assert } = require('chai');

const Attachments = require('../../app/attachments');


const PREFIX_LENGTH = 2;
const NUM_SEPARATORS = 1;
const NAME_LENGTH = 64;
const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;

describe('Attachments', () => {
  describe('writeData', () => {
    let TEMPORARY_DIRECTORY = null;
    before(() => {
      TEMPORARY_DIRECTORY = tmp.dirSync().name;
    });

    after(async () => {
      await fse.remove(TEMPORARY_DIRECTORY);
    });

    it('should write file to disk and return path', async () => {
      const input = stringToArrayBuffer('test string');
      const tempDirectory = path.join(TEMPORARY_DIRECTORY, 'Attachments_writeData');

      const outputPath = await Attachments.writeData(tempDirectory)(input);
      const output = await fse.readFile(path.join(tempDirectory, outputPath));

      assert.lengthOf(outputPath, PATH_LENGTH);

      const inputBuffer = Buffer.from(input);
      assert.isTrue(isEqual(inputBuffer, output));
    });

    describe('createName', () => {
      it('should return random file name with correct length', () => {
        assert.lengthOf(Attachments.createName(), NAME_LENGTH);
      });
    });

    describe('getRelativePath', () => {
      it('should return correct path', () => {<commit_msg>:art: Use `camelCase` for mutable variable<commit_after>const fse = require('fs-extra');
const isEqual = require('lodash/isEqual');
const path = require('path');
const stringToArrayBuffer = require('string-to-arraybuffer');
const tmp = require('tmp');
const { assert } = require('chai');

const Attachments = require('../../app/attachments');


const PREFIX_LENGTH = 2;
const NUM_SEPARATORS = 1;
const NAME_LENGTH = 64;
const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;

describe('Attachments', () => {
  describe('writeData', () => {
    let tempRootDirectory = null;
    before(() => {
      tempRootDirectory = tmp.dirSync().name;
    });

    after(async () => {
      await fse.remove(tempRootDirectory);
    });

    it('should write file to disk and return path', async () => {
      const input = stringToArrayBuffer('test string');
      const tempDirectory = path.join(tempRootDirectory, 'Attachments_writeData');

      const outputPath = await Attachments.writeData(tempDirectory)(input);
      const output = await fse.readFile(path.join(tempDirectory, outputPath));

      assert.lengthOf(outputPath, PATH_LENGTH);

      const inputBuffer = Buffer.from(input);
      assert.isTrue(isEqual(inputBuffer, output));
    });

    describe('createName', () => {
      it('should return random file name with correct length', () => {
        assert.lengthOf(Attachments.createName(), NAME_LENGTH);
      });
    });

    describe('getRelativePath', () => {
      it('should return correct path', () => {
{'fraction_non_alphanumeric': 0.14968677876689745, 'fraction_numerical': 0.002637652489284537, 'mean_word_length': 3.957516339869281, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1657220', 'n_tokens_mistral': 922, 'n_tokens_neox': 875, 'n_words': 195}