mirror of
https://github.com/seejohnrun/haste-server.git
synced 2026-02-10 16:01:32 +00:00
Add tests and fix docker files
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import Generator from '../../src/lib/key-generators/dictionary'
|
||||
|
||||
jest.mock('fs', () => ({
|
||||
readFile: jest.fn().mockImplementation((_, a, callback) =>
|
||||
callback(null, 'cat'),
|
||||
)
|
||||
}))
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
/* eslint-disable jest/no-conditional-expect */
|
||||
import Generator from '../../src/lib/key-generators/phonetic'
|
||||
|
||||
const vowels = 'aeiou';
|
||||
const consonants = 'bcdfghjklmnpqrstvwxyz';
|
||||
|
||||
describe('PhoneticKeyGenerator', () => {
|
||||
describe('generation', () => {
|
||||
it('should return a key of the proper length', () => {
|
||||
const gen = new Generator({ type: 'phonetic'});
|
||||
expect(gen.createKey(6).length).toEqual(6);
|
||||
});
|
||||
|
||||
it('should alternate consonants and vowels', () => {
|
||||
const gen = new Generator({ type: 'phonetic'});
|
||||
const key = gen.createKey(3);
|
||||
// if it starts with a consonant, we expect cvc
|
||||
// if it starts with a vowel, we expect vcv
|
||||
if(consonants.includes(key[0])) {
|
||||
expect(consonants.includes(key[0])).toBeTruthy()
|
||||
expect(consonants.includes(key[2])).toBeTruthy()
|
||||
expect(vowels.includes(key[1])).toBeTruthy()
|
||||
} else {
|
||||
expect(vowels.includes(key[0])).toBeTruthy()
|
||||
expect(vowels.includes(key[2])).toBeTruthy()
|
||||
expect(consonants.includes(key[1])).toBeTruthy()
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import Generator from '../../src/lib/key-generators/random'
|
||||
|
||||
describe('RandomKeyGenerator', () => {
|
||||
describe('generation', () => {
|
||||
it('should return a key of the proper length', () => {
|
||||
const gen = new Generator({ type: 'random' })
|
||||
expect(gen.createKey(6).length).toEqual(6)
|
||||
})
|
||||
|
||||
it('should use a key from the given keyset if given', () => {
|
||||
const gen = new Generator({ type: 'random', keyspace: 'A' })
|
||||
expect(gen.createKey(6)).toEqual('AAAAAA')
|
||||
})
|
||||
|
||||
it('should not use a key from the given keyset if not given', () => {
|
||||
const gen = new Generator({ type: 'random', keyspace: 'A' })
|
||||
expect(gen.createKey(6).includes('B')).toBeFalsy()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user