-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(1022): Avoid serializing empty strings for Expressions, Loadbalan…
…cers and dataformat fields
- Loading branch information
1 parent
724bb94
commit 6372d1e
Showing
9 changed files
with
83 additions
and
7 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
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
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
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
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
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
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,61 @@ | ||
import { getSerializedModel } from './get-serialized-model'; | ||
|
||
describe('getSerializedModel', () => { | ||
let inputValue: Record<string, unknown>; | ||
|
||
it('should get an object with empty string value unserialized', () => { | ||
inputValue = { | ||
name: 'test', | ||
type: 'test', | ||
builderClass: '', | ||
constructors: { | ||
testConstructor: 'test', | ||
}, | ||
destroyMethod: ' test ', | ||
factoryBean: '', | ||
properties: { | ||
testProperty: {}, | ||
}, | ||
}; | ||
|
||
const expectedOutputValue = { | ||
name: 'test', | ||
type: 'test', | ||
constructors: { | ||
testConstructor: 'test', | ||
}, | ||
destroyMethod: ' test ', | ||
properties: { | ||
testProperty: {}, | ||
}, | ||
}; | ||
const serializedModel = getSerializedModel(inputValue); | ||
expect(serializedModel).toEqual(expectedOutputValue); | ||
}); | ||
|
||
it('should get a object with empty string value with whitespaces unserialized', () => { | ||
inputValue = { | ||
id: 'test', | ||
allowJmsType: true, | ||
library: '', | ||
collectionType: ' ', | ||
timezone: 'test ', | ||
}; | ||
|
||
const expectedOutputValue = { | ||
id: 'test', | ||
allowJmsType: true, | ||
timezone: 'test ', | ||
}; | ||
const serializedModel = getSerializedModel(inputValue); | ||
expect(serializedModel).toEqual(expectedOutputValue); | ||
}); | ||
|
||
it('should get a empty object serialized', () => { | ||
inputValue = {}; | ||
|
||
const expectedOutputValue = {}; | ||
const serializedModel = getSerializedModel(inputValue); | ||
expect(serializedModel).toEqual(expectedOutputValue); | ||
}); | ||
}); |
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,9 @@ | ||
export const getSerializedModel = (model: Record<string, unknown>): Record<string, unknown> => { | ||
Object.keys(model).forEach((key) => { | ||
if (typeof model[key] === 'string' && (model[key] as string).trim() === '') { | ||
delete model[key]; | ||
} | ||
}); | ||
|
||
return model; | ||
}; |
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