1
0
mirror of https://github.com/seejohnrun/haste-server.git synced 2026-02-10 16:01:32 +00:00

fix code, readme and lint

This commit is contained in:
Yusuf Yilmaz
2022-06-08 11:26:32 +02:00
parent 42c60c64c2
commit 350abbdf3b
14 changed files with 158 additions and 153 deletions

View File

@@ -1,25 +1,35 @@
import { createMock } from 'ts-auto-mock';
import { createMock } from 'ts-auto-mock'
import DocumentHandler from 'src/lib/document-handler/index'
import Generator from 'src/lib/key-generators/random'
import constants from 'src/constants'
import { Config } from 'src/types/config'
import { Store } from 'src/lib/document-stores';
import { Store } from 'src/lib/document-stores'
const store : Store = createMock<Store>();
const config : Config = createMock<Config>();
const store: Store = createMock<Store>()
const config: Config = createMock<Config>()
describe('document-handler', () => {
describe('with random key', () => {
it('should choose a key of the proper length', () => {
const gen = new Generator({ type: 'random' })
const dh = new DocumentHandler({ keyLength: 6, keyGenerator: gen, store, config})
expect(dh.acceptableKey()?.length).toEqual(6);
const dh = new DocumentHandler({
keyLength: 6,
keyGenerator: gen,
store,
config
})
expect(dh.acceptableKey()?.length).toEqual(6)
})
it('should choose a default key length', () => {
const gen = new Generator({ type: 'random' })
const dh = new DocumentHandler({ keyGenerator: gen, maxLength: 1, store, config })
expect(dh.keyLength).toEqual(constants.DEFAULT_KEY_LENGTH);
const dh = new DocumentHandler({
keyGenerator: gen,
maxLength: 1,
store,
config
})
expect(dh.keyLength).toEqual(constants.DEFAULT_KEY_LENGTH)
})
})
})

View File

@@ -14,7 +14,7 @@ describe('Redis document store', () => {
it('should be able to set a key and have an expiration set', async () => {
store = new RedisDocumentStore({
expire: 10,
type: StoreNames.redis
type: StoreNames.Redis
})
return store.set('hello1', 'world', async () => {
const res = await store.client?.ttl('hello1')
@@ -25,7 +25,7 @@ describe('Redis document store', () => {
it('should not set an expiration when told not to', async () => {
store = new RedisDocumentStore({
expire: 10,
type: StoreNames.redis
type: StoreNames.Redis
})
store.set(
@@ -41,7 +41,7 @@ describe('Redis document store', () => {
it('should not set an expiration when expiration is off', async () => {
store = new RedisDocumentStore({
type: StoreNames.redis
type: StoreNames.Redis
})
store.set('hello3', 'world', async () => {

View File

@@ -1,22 +1,22 @@
/* eslint-disable jest/no-conditional-expect */
import Generator from 'src/lib/key-generators/phonetic'
const vowels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';
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);
});
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);
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])) {
if (consonants.includes(key[0])) {
expect(consonants.includes(key[0])).toBeTruthy()
expect(consonants.includes(key[2])).toBeTruthy()
expect(vowels.includes(key[1])).toBeTruthy()
@@ -25,6 +25,6 @@ describe('PhoneticKeyGenerator', () => {
expect(vowels.includes(key[2])).toBeTruthy()
expect(consonants.includes(key[1])).toBeTruthy()
}
});
});
});
})
})
})