<commit_before>import storeFactory from 'shared/vuex/baseStore';
import { File } from 'shared/data/resources';
import client from 'shared/client';

jest.mock('shared/client');
jest.mock('shared/vuex/connectionPlugin');

const contentnode = 'testnode';

const testFile = {
  original_filename: 'document.pdf',
  url: 'path/to/document.pdf',
  file_size: 100,
  preset: 'document',
  contentnode,
};

const userId = 'some user';

describe('file store', () => {
  let store;
  let id;
  beforeEach(() => {
    return File.put(testFile).then(newId => {
      id = newId;
      store = storeFactory();
      store.commit('file/ADD_FILE', { id, ...testFile });
      store.state.session.currentUser.id = userId;
    });
  });
  afterEach(() => {
    return File.table.toCollection().delete();
  });
  describe('file getters', () => {
    it('getContentNodeFileById', () => {
      const file = store.getters['file/getContentNodeFileById'](contentnode, id);
      expect(file.id).toEqual(id);
      expect(file.preset.id).toBe('document');
    });
    it('contentNodesTotalSize', () => {
      let file = {
        id: 'test',
        preset: 'document_thumbnail',
        file_size: 100,
        contentnode,
      };
      let file2 = {
        id: 'test2',
        preset: 'epub',
        file_size: 100,
        contentnode,
      };
      store.commit('file/REMOVE_FILE', { id, ...testFile });
      store.commit('file/ADD_FILES', [file, file2]);
      expect(store.getters['file/contentNodesTotalSize']([contentnode])).toBe(200);
    });
  });
  describe('file actions', () => {
    describe('loadFile action', () => {
      it('should call File.get', () => {
        const getSpy = jest.spyOn(File, 'get');
        return store.dispatch('file/loadFile', id).then(() => {<commit_msg>Add returned promises to non-async tests to attempt to prevent async errors.<commit_after>import storeFactory from 'shared/vuex/baseStore';
import { File } from 'shared/data/resources';
import client from 'shared/client';

jest.mock('shared/client');
jest.mock('shared/vuex/connectionPlugin');

const contentnode = 'testnode';

const testFile = {
  original_filename: 'document.pdf',
  url: 'path/to/document.pdf',
  file_size: 100,
  preset: 'document',
  contentnode,
};

const userId = 'some user';

describe('file store', () => {
  let store;
  let id;
  beforeEach(() => {
    return File.put(testFile).then(newId => {
      id = newId;
      store = storeFactory();
      store.commit('file/ADD_FILE', { id, ...testFile });
      store.state.session.currentUser.id = userId;
    });
  });
  afterEach(() => {
    return File.table.toCollection().delete();
  });
  describe('file getters', () => {
    it('getContentNodeFileById', () => {
      const file = store.getters['file/getContentNodeFileById'](contentnode, id);
      expect(file.id).toEqual(id);
      expect(file.preset.id).toBe('document');
      return Promise.resolve();
    });
    it('contentNodesTotalSize', () => {
      let file = {
        id: 'test',
        preset: 'document_thumbnail',
        file_size: 100,
        contentnode,
      };
      let file2 = {
        id: 'test2',
        preset: 'epub',
        file_size: 100,
        contentnode,
      };
      store.commit('file/REMOVE_FILE', { id, ...testFile });
      store.commit('file/ADD_FILES', [file, file2]);
      expect(store.getters['file/contentNodesTotalSize']([contentnode])).toBe(200);
      return Promise.resolve();
    });
  });
  describe('file actions', () => {
    describe('loadFile action', () => {
      it('should call File.get', () => {
        const getSpy = jest.spyOn(File, 'get');
        return store.dispatch('file/loadFile', id).then(() => {
{'fraction_non_alphanumeric': 0.1782714711460309, 'fraction_numerical': 0.00812787862367922, 'mean_word_length': 3.0217864923747277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4674210', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1169, 'n_words': 219}