File tree 3 files changed +12
-7
lines changed
3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ describe('string mapper', () => {
9
9
10
10
it ( 'should work (empty string)' , ( ) => {
11
11
const attributeValue = StringMapper . toDb ( '' )
12
- expect ( attributeValue ) . toBe ( null )
12
+ expect ( attributeValue ) . toStrictEqual ( { S : '' } )
13
13
} )
14
14
15
15
it ( 'should work (null)' , ( ) => {
@@ -28,6 +28,10 @@ describe('string mapper', () => {
28
28
const stringValue = StringMapper . fromDb ( { S : 'myStringValue' } )
29
29
expect ( stringValue ) . toBe ( 'myStringValue' )
30
30
} )
31
+ it ( 'should allow empty string values' , ( ) => {
32
+ const stringValue = StringMapper . fromDb ( { S : '' } )
33
+ expect ( stringValue ) . toBe ( '' )
34
+ } )
31
35
it ( 'should throw if not a string attribute' , ( ) => {
32
36
expect ( ( ) => StringMapper . fromDb ( < any > { N : '8' } ) ) . toThrow ( )
33
37
} )
Original file line number Diff line number Diff line change @@ -5,16 +5,16 @@ import { StringAttribute } from '../type/attribute.type'
5
5
import { MapperForType } from './base.mapper'
6
6
7
7
function stringFromDb ( attributeValue : StringAttribute ) : string {
8
- if ( attributeValue . S ) {
8
+ if ( attributeValue . S || attributeValue . S === '' ) {
9
9
return attributeValue . S
10
10
} else {
11
11
throw new Error ( `there is no S(tring) value defined on given attribute value: ${ JSON . stringify ( attributeValue ) } ` )
12
12
}
13
13
}
14
14
15
15
function 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 ) {
18
18
return null
19
19
} else {
20
20
return { S : modelValue }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ describe('Mapper', () => {
67
67
68
68
it ( 'string (empty)' , ( ) => {
69
69
const attrValue = < StringAttribute > toDbOne ( '' ) !
70
- expect ( attrValue ) . toBeNull ( )
70
+ expect ( attrValue . S ) . toStrictEqual ( '' )
71
71
} )
72
72
73
73
it ( 'number' , ( ) => {
@@ -801,7 +801,7 @@ describe('Mapper', () => {
801
801
// OK
802
802
id : 'myId' ,
803
803
804
- // x -> empty strings are not valid
804
+ // x -> empty strings are valid
805
805
name : '' ,
806
806
807
807
// x -> empty set is not valid
@@ -824,7 +824,8 @@ describe('Mapper', () => {
824
824
expect ( toDbValue . id ) . toBeDefined ( )
825
825
expect ( keyOf ( toDbValue . id ) ) . toBe ( 'S' )
826
826
827
- expect ( toDbValue . name ) . toBeUndefined ( )
827
+ expect ( toDbValue . name ) . toBeDefined ( )
828
+ expect ( keyOf ( toDbValue . name ) ) . toBe ( 'S' )
828
829
829
830
expect ( toDbValue . roles ) . toBeUndefined ( )
830
831
You can’t perform that action at this time.
0 commit comments