Skip to content

Commit

Permalink
test: add tests verifying the optional config object works as expected
Browse files Browse the repository at this point in the history
Resolves: #35
  • Loading branch information
M-Scott-Lassiter committed May 2, 2022
1 parent 8dc230b commit f7f7de6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ describe('Allow Lower Case Dictionaries', () => {
expect(encoder.allowLowerCaseDictionary).toBeFalsy()
}
)

test('Allow lower case dictionaries by using a config object', () => {
encoder = new AlphanumericEncoder({ allowLowerCaseDictionary: true })
expect(encoder.allowLowerCaseDictionary).toBeTruthy()
})
})

describe('Dictionary Validation', () => {
Expand Down Expand Up @@ -128,6 +133,11 @@ describe('Dictionary Validation', () => {
encoder.dictionary = 'abcd'
expect(encoder.dictionary).toBe('ABCD')
})

test('Allow setting dictionaries by using a config object', () => {
encoder = new AlphanumericEncoder({ dictionary: 'abcd' })
expect(encoder.dictionary).toBe('ABCD')
})
})

describe('Valid Dictionaries (allow lower case)', () => {
Expand All @@ -148,6 +158,20 @@ describe('Dictionary Validation', () => {
encoder.dictionary = complexDictionary
expect(encoder.dictionary).toBe('ABCD123abcd')
})

test('Allow setting lower case dictionaries by using a config object', () => {
encoder = new AlphanumericEncoder({
allowLowerCaseDictionary: true,
dictionary: 'abcd'
})
expect(encoder.dictionary).toBe('abcd')
})

test('Class should be configurable using externally defined object', () => {
const configOptions = { allowLowerCaseDictionary: true, dictionary: 'abcd' }
encoder = new AlphanumericEncoder(configOptions)
expect(encoder.dictionary).toBe('abcd')
})
})

describe('Invalid Dictionaries', () => {
Expand All @@ -170,6 +194,12 @@ describe('Dictionary Validation', () => {
}).toThrow(/must be alphanumeric/)
}
)

test('Passing invalid dictionary in options should throw error', () => {
expect(() => {
encoder = new AlphanumericEncoder({ dictionary: 'ABC@#$' })
}).toThrow(/must be alphanumeric/)
})
})
})

Expand Down

0 comments on commit f7f7de6

Please sign in to comment.