2022-06-02 08:57:42 +00:00
|
|
|
import { createMock } from 'ts-auto-mock';
|
2022-05-27 13:04:54 +00:00
|
|
|
import DocumentHandler from '../../src/lib/document-handler/index'
|
|
|
|
import Generator from '../../src/lib/key-generators/random'
|
|
|
|
import constants from '../../src/constants'
|
2022-06-02 08:57:42 +00:00
|
|
|
import { Store } from '../../src/types/store'
|
|
|
|
import { Config } from '../../src/types/config'
|
|
|
|
|
|
|
|
const store : Store = createMock<Store>();
|
|
|
|
const config : Config = createMock<Config>();
|
2022-05-27 13:04:54 +00:00
|
|
|
|
|
|
|
describe('document-handler', () => {
|
|
|
|
describe('with randomKey', () => {
|
|
|
|
it('should choose a key of the proper length', () => {
|
|
|
|
const gen = new Generator({ type: 'random' })
|
2022-06-02 08:57:42 +00:00
|
|
|
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' })
|
2022-06-02 08:57:42 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|