1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-01 11:31:22 +00:00
haste-server/test/document-handler/index.test.ts

26 lines
988 B
TypeScript
Raw Normal View History

import { createMock } from 'ts-auto-mock';
2022-06-06 17:38:20 +00: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-06 19:36:48 +00:00
import { Store } from 'src/lib/document-stores';
const store : Store = createMock<Store>();
const config : Config = createMock<Config>();
2022-05-27 13:04:54 +00:00
describe('document-handler', () => {
2022-06-06 19:36:48 +00:00
describe('with random key', () => {
2022-05-27 13:04:54 +00:00
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})
2022-05-27 13:04:54 +00:00
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 })
2022-05-27 13:04:54 +00:00
expect(dh.keyLength).toEqual(constants.DEFAULT_KEY_LENGTH);
})
})
})