haste-server/test/document-handler/index.test.ts

36 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-06-08 11:26:32 +02:00
import { createMock } from 'ts-auto-mock'
2022-06-06 19:38:20 +02:00
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'
2022-06-08 11:26:32 +02:00
import { Store } from 'src/lib/document-stores'
2022-06-08 11:26:32 +02:00
const store: Store = createMock<Store>()
const config: Config = createMock<Config>()
2022-05-27 15:04:54 +02:00
describe('document-handler', () => {
2022-06-06 21:36:48 +02:00
describe('with random key', () => {
2022-05-27 15:04:54 +02:00
it('should choose a key of the proper length', () => {
const gen = new Generator({ type: 'random' })
2022-06-08 11:26:32 +02:00
const dh = new DocumentHandler({
keyLength: 6,
keyGenerator: gen,
store,
config
})
expect(dh.acceptableKey()?.length).toEqual(6)
2022-05-27 15:04:54 +02:00
})
it('should choose a default key length', () => {
const gen = new Generator({ type: 'random' })
2022-06-08 11:26:32 +02:00
const dh = new DocumentHandler({
keyGenerator: gen,
maxLength: 1,
store,
config
})
expect(dh.keyLength).toEqual(constants.DEFAULT_KEY_LENGTH)
2022-05-27 15:04:54 +02:00
})
})
})