-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8912a8
commit c351362
Showing
4 changed files
with
107 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const parseTableAttributes = require('../lib/parseTableAttributes') | ||
|
||
let attrs = { | ||
pk: 'string', | ||
sk: 'string' | ||
} | ||
|
||
|
||
describe('parseTableAttributes', () => { | ||
|
||
it('parse simple attributes', async () => { | ||
expect(parseTableAttributes(attrs,'pk','sk')).toEqual({ pk: { type: 'string' }, sk: { type: 'string' } }) | ||
}) | ||
|
||
it('fails when attribute is missing type', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: {} }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'test'. Valid types are 'string', 'boolean', 'number', 'list', 'map', 'binary', and 'set'.`) | ||
}) | ||
|
||
it('fails when partitionKey is an invalid type', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ pk: 'map' }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'pk'. Valid types for partitionKey and sortKey are 'string','number' and 'binary'`) | ||
}) | ||
|
||
it('fails when sortKey is an invalid type', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ sk: 'map' }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'sk'. Valid types for partitionKey and sortKey are 'string','number' and 'binary'`) | ||
}) | ||
|
||
it('fails when attribute is an invalid type', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: 'not-a-type' }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'test'. Valid types are 'string', 'boolean', 'number', 'list', 'map', 'binary', and 'set'.`) | ||
}) | ||
|
||
it('fails when partitionKey is an invalid type (in object config)', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ pk: { type: 'map' } }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'pk'. Valid types for partitionKey and sortKey are 'string','number' and 'binary'`) | ||
}) | ||
|
||
it('fails when sortKey is an invalid type (in object config)', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ sk: { type: 'map' } }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'sk'. Valid types for partitionKey and sortKey are 'string','number' and 'binary'`) | ||
}) | ||
|
||
it('fails when attribute is an invalid type (in an object config)', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: { type: 'not-a-type' } }),'pk','sk') | ||
}).toThrow(`Invalid or missing type for 'test'. Valid types are 'string', 'boolean', 'number', 'list', 'map', 'binary', and 'set'.`) | ||
}) | ||
|
||
it(`fails when attribute contains setType but isn't a set`, async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: { type: 'string', setType: 'string' } }),'pk','sk') | ||
}).toThrow(`'setType' is only valid for type 'set'`) | ||
}) | ||
|
||
it(`fails when attribute contains invalid setType`, async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: { type: 'set', setType: 'invalid' } }),'pk','sk') | ||
}).toThrow(`Invalid 'setType', must be 'string', 'number', or 'binary'`) | ||
}) | ||
|
||
it('fails when attribute has an invalid config option', async () => { | ||
expect(() => { | ||
parseTableAttributes(Object.assign({},attrs,{ test: { type: 'string', invalid: 'invalid' } }),'pk','sk') | ||
}).toThrow(`'invalid' is not a valid property type`) | ||
}) | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const utils = require('../lib/utils') | ||
|
||
describe('utility functions',()=>{ | ||
|
||
test('toBool', ()=>{ | ||
expect(utils.toBool('true')).toBe(true) | ||
expect(utils.toBool(1)).toBe(true) | ||
expect(utils.toBool(true)).toBe(true) | ||
expect(utils.toBool('any')).toBe(true) | ||
expect(utils.toBool(false)).toBe(false) | ||
expect(utils.toBool('false')).toBe(false) | ||
expect(utils.toBool(0)).toBe(false) | ||
expect(utils.toBool('no')).toBe(false) | ||
}) | ||
|
||
test('hasValue', ()=>{ | ||
expect(utils.hasValue('string')).toBe(true) | ||
expect(utils.hasValue(1)).toBe(true) | ||
expect(utils.hasValue(true)).toBe(true) | ||
expect(utils.hasValue({})).toBe(true) | ||
expect(utils.hasValue([])).toBe(true) | ||
expect(utils.hasValue(false)).toBe(true) | ||
expect(utils.hasValue(undefined)).toBe(false) | ||
expect(utils.hasValue(null)).toBe(false) | ||
}) | ||
|
||
test('error', () => { | ||
expect(() => { utils.error('test error') }).toThrow('test error') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters