<commit_before>/* eslint-env jest */

import { filter } from 'lodash/collection'
import { clean } from 'require-clean'

import { fixturesA } from '../test-utils/ExampleModel'
import { fixturesRangeKeyA } from '../test-utils/ExampleModelRangeKey'
import {
  DatabaseOperation,
  setMockDBResponse,
  setModelPermissions
} from '../../test-utils'
import {
  UnauthorizedQueryException
} from '../../../utils/exceptions'

var ExampleModel = require('../test-utils/ExampleModel').default
var ExampleModelRangeKey = require('../test-utils/ExampleModelRangeKey').default

jest.mock('../../databaseClient')

const user = {
  id: '45bbefbf-63d1-4d36-931e-212fbe2bc3d9',
  username: 'MyName',
  emailVerified: true
}

describe('BaseModel queries', () => {
  afterEach(() => {
    jest.clearAllMocks()

    // For some reason, jest.resetModules is failing with
    // ExampleModel (even when using CommonJS requires), so just
    // clean the requires manually.
    clean('../test-utils/ExampleModel')
    clean('../test-utils/ExampleModelRangeKey')
  })

  it('correctly fetches with `getAll` method', async () => {
    setModelPermissions(ExampleModel, {
      getAll: () => true
    })
<commit_msg>Revert "Cleaner test cleanup."<commit_after>/* eslint-env jest */

import { filter } from 'lodash/collection'
import ExampleModel, { fixturesA } from '../test-utils/ExampleModel'
import ExampleModelRangeKey, {
  fixturesRangeKeyA
} from '../test-utils/ExampleModelRangeKey'
import {
  DatabaseOperation,
  setMockDBResponse,
  setModelPermissions
} from '../../test-utils'
import {
  UnauthorizedQueryException
} from '../../../utils/exceptions'

jest.mock('../../databaseClient')

const user = {
  id: '45bbefbf-63d1-4d36-931e-212fbe2bc3d9',
  username: 'MyName',
  emailVerified: true
}

describe('BaseModel queries', () => {
  afterEach(() => {
    jest.clearAllMocks()

    // For some reason, jest.resetModules is failing with
    // ExampleModel (even when using CommonJS requires), so just
    // reset permissions manually.
    setModelPermissions(ExampleModel, {
      get: () => false,
      getAll: () => false,
      update: () => false,
      create: () => false
    })
  })

  it('correctly fetches with `getAll` method', async () => {
    setModelPermissions(ExampleModel, {
      getAll: () => true
    })

{'fraction_non_alphanumeric': 0.15304798962386512, 'fraction_numerical': 0.014699524427150886, 'mean_word_length': 3.501945525291829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '128550', 'n_tokens_mistral': 727, 'n_tokens_neox': 712, 'n_words': 157}