<commit_before>'use strict'

const hoodie = {
  account: {
    on: function () {}
  },
  store: {
    find: function () {
      const error = new Error('not found')
      error.status = 404
      return Promise.reject(error)
    },
    updateOrAdd: function (doc) {
      return Promise.resolve(doc)
    },
    on: function () {},
    off: function () {},
    one: function () {}
  }
}

test('import is a function that adds the cryptoStore to hoodie', () => {
  expect(hoodie.cryptoStore).toBeUndefined()

  require('hoodie-plugin-store-crypto')(hoodie)

  expect(hoodie.cryptoStore).toBeTruthy()
})

test('cryptoStore and its methods exists', () => {
  expect(typeof hoodie.cryptoStore).toBe('object')

  expect(typeof hoodie.cryptoStore.setPassword).toBe('function')
  expect(typeof hoodie.cryptoStore.changePassword).toBe('function')

  expect(typeof hoodie.cryptoStore.add).toBe('function')
  expect(typeof hoodie.cryptoStore.find).toBe('function')
  expect(typeof hoodie.cryptoStore.findOrAdd).toBe('function')
  expect(typeof hoodie.cryptoStore.findAll).toBe('function')
  expect(typeof hoodie.cryptoStore.update).toBe('function')
  expect(typeof hoodie.cryptoStore.updateOrAdd).toBe('function')
  expect(typeof hoodie.cryptoStore.updateAll).toBe('function')
  expect(typeof hoodie.cryptoStore.remove).toBe('function')
  expect(typeof hoodie.cryptoStore.removeAll).toBe('function')

  expect(typeof hoodie.cryptoStore.on).toBe('function')
  expect(typeof hoodie.cryptoStore.off).toBe('function')
  expect(typeof hoodie.cryptoStore.one).toBe('function')

  expect(typeof hoodie.cryptoStore.withIdPrefix).toBe('function')
  expect(typeof hoodie.cryptoStore.withPassword).toBe('function')
})

test('cryptoStore requires to be unlocked', async () => {
  const salt = await hoodie.cryptoStore.setPassword('<PASSWORD>')

  expect(typeof salt).toBe('string')
  expect(salt.length).toBe(32)<commit_msg>test(cryptoStore): change tests for v2<commit_after>'use strict'

let storeData = {}

const hoodie = {
  account: {
    on: function () {}
  },

  store: {
    find: function (id) {
      if (Array.isArray(id)) {
        return Promise.all(
          id.map(
            aID => hoodie.store.find(aID).catch(() => ({ status: 404 }))
          )
        )
      }

      const doc = storeData[id]
      if (doc != null) {
        return Promise.resolve(doc)
      }

      const error = new Error('not found')
      error.status = 404
      return Promise.reject(error)
    },

    updateOrAdd: function (doc) {
      const newDoc = Object.assign(storeData[doc._id] || {}, doc)
      storeData[doc._id] = newDoc
      return Promise.resolve(newDoc)
    },

    pull: function (ids) {
      return Promise.all(ids.map(id => hoodie.store.find(id))).catch(() => [])
    },

    on: function () {},
    off: function () {},
    one: function () {}
  }
}

test('import is a function that adds the cryptoStore to hoodie', () => {
  expect(hoodie.cryptoStore).toBeUndefined()

  require('hoodie-plugin-store-crypto')(hoodie)

  expect(hoodie.cryptoStore).toBeTruthy()
})

test('cryptoStore and its methods exists', () => {
  expect(typeof hoodie.cryptoStore).toBe('object')

  expect(typeof hoodie.cryptoStore.setup).toBe('function')
  expect(typeof hoodie.cryptoStore.unlock).toBe('function')
  expect(typeof hoodie.cryptoStore.changePassword).toBe('function')

  expect(typeof hoodie.cryptoStore.add).toBe('function')
  expect(typeof hoodie.cryptoStore.find).toBe('function')
  expect(typeof hoodie.cryptoStore.findOrAdd).toBe('function')
  expect(typeof hoodie.cryptoStore.findAll).toBe('function')
  expect(typeof hoodie.cryptoStore.update).toBe('function')
  expect(typeof hoodie.cryptoStore.updateOrAdd).toBe('function')
  expect(typeof hoodie.cryptoStore.updateAll).toBe('function')
  expect(typeof hoodie.cryptoStore.remove).toBe('function')
  expect(typeof hoodie.cryptoStore.removeAll).toBe('function')

  expect(typeof hoodie.cryptoStore.on).toBe('function')
  expect(typeof hoodie.cryptoStore.off).toBe('function')
  expect(typeof hoodie.cryptoStore.one).toBe('function')

  expect(typeof hoodie.cryptoStore.withIdPrefix).toBe('function')
  expect(typeof hoodie.cryptoStore.withPassword).toBe('function')
})

test('cryptoStore requires to be unlocked', async () => {
  await hoodie.cryptoStore.setup('test')
  await hoodie.cryptoStore.unlock('test')
{'fraction_non_alphanumeric': 0.15326286764705882, 'fraction_numerical': 0.0027573529411764708, 'mean_word_length': 4.308536585365854, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, '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': '2334526', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1309, 'n_words': 224}