File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ describe('string mapper', () => {
99
1010 it ( 'should work (empty string)' , ( ) => {
1111 const attributeValue = StringMapper . toDb ( '' )
12- expect ( attributeValue ) . toBe ( null )
12+ expect ( attributeValue ) . toStrictEqual ( { S : '' } )
1313 } )
1414
1515 it ( 'should work (null)' , ( ) => {
@@ -28,6 +28,10 @@ describe('string mapper', () => {
2828 const stringValue = StringMapper . fromDb ( { S : 'myStringValue' } )
2929 expect ( stringValue ) . toBe ( 'myStringValue' )
3030 } )
31+ it ( 'should allow empty string values' , ( ) => {
32+ const stringValue = StringMapper . fromDb ( { S : '' } )
33+ expect ( stringValue ) . toBe ( '' )
34+ } )
3135 it ( 'should throw if not a string attribute' , ( ) => {
3236 expect ( ( ) => StringMapper . fromDb ( < any > { N : '8' } ) ) . toThrow ( )
3337 } )
Original file line number Diff line number Diff line change @@ -5,16 +5,16 @@ import { StringAttribute } from '../type/attribute.type'
55import { MapperForType } from './base.mapper'
66
77function stringFromDb ( attributeValue : StringAttribute ) : string {
8- if ( attributeValue . S ) {
8+ if ( attributeValue . S || attributeValue . S === '' ) {
99 return attributeValue . S
1010 } else {
1111 throw new Error ( `there is no S(tring) value defined on given attribute value: ${ JSON . stringify ( attributeValue ) } ` )
1212 }
1313}
1414
1515function stringToDb ( modelValue : string ) : StringAttribute | null {
16- // an empty string is not a valid value for string attribute
17- if ( modelValue === '' || modelValue === null || modelValue === undefined ) {
16+ // an empty string is valid for a string attribute
17+ if ( modelValue === null || modelValue === undefined ) {
1818 return null
1919 } else {
2020 return { S : modelValue }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ describe('Mapper', () => {
6767
6868 it ( 'string (empty)' , ( ) => {
6969 const attrValue = < StringAttribute > toDbOne ( '' ) !
70- expect ( attrValue ) . toBeNull ( )
70+ expect ( attrValue . S ) . toStrictEqual ( '' )
7171 } )
7272
7373 it ( 'number' , ( ) => {
@@ -801,7 +801,7 @@ describe('Mapper', () => {
801801 // OK
802802 id : 'myId' ,
803803
804- // x -> empty strings are not valid
804+ // x -> empty strings are valid
805805 name : '' ,
806806
807807 // x -> empty set is not valid
@@ -824,7 +824,8 @@ describe('Mapper', () => {
824824 expect ( toDbValue . id ) . toBeDefined ( )
825825 expect ( keyOf ( toDbValue . id ) ) . toBe ( 'S' )
826826
827- expect ( toDbValue . name ) . toBeUndefined ( )
827+ expect ( toDbValue . name ) . toBeDefined ( )
828+ expect ( keyOf ( toDbValue . name ) ) . toBe ( 'S' )
828829
829830 expect ( toDbValue . roles ) . toBeUndefined ( )
830831
You can’t perform that action at this time.
0 commit comments