2022-06-06 17:38:20 +00:00
|
|
|
import Generator from 'src/lib/key-generators/dictionary'
|
2022-05-27 13:04:54 +00:00
|
|
|
|
|
|
|
jest.mock('fs', () => ({
|
2022-06-06 17:38:20 +00:00
|
|
|
readFile: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation((_, a, callback) => callback(null, 'cat'))
|
|
|
|
}))
|
|
|
|
|
2022-05-27 13:04:54 +00:00
|
|
|
describe('DictionaryGenerator', () => {
|
|
|
|
describe('options', () => {
|
|
|
|
it('should throw an error if given no options or path', () => {
|
|
|
|
expect(() => new Generator({ type: '' })).toThrow()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('generation', () => {
|
|
|
|
it('should return a key of the proper number of words from the given dictionary', () => {
|
|
|
|
const path = '/tmp/haste-server-test-dictionary'
|
|
|
|
|
|
|
|
const gen = new Generator({ path, type: '' })
|
|
|
|
|
|
|
|
expect(gen.createKey(3)).toEqual('catcatcat')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|