-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-96531 || added unit test for util function
- Loading branch information
1 parent
5fa666c
commit 1d613a9
Showing
1 changed file
with
73 additions
and
0 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,73 @@ | ||
import { separateFromIntoNameAndEmail, combineNameAndEmailToFrom } from './fieldTransformer'; | ||
|
||
describe('separateFromIntoNameAndEmail', () => { | ||
it('should split "from" into "fromName" and "fromEmail" when valid format is provided', () => { | ||
const input = { from: 'John Doe <[email protected]>' }; | ||
const result = separateFromIntoNameAndEmail(input); | ||
expect(result).toEqual({ | ||
fromName: 'John Doe', | ||
fromEmail: '[email protected]', | ||
}); | ||
}); | ||
|
||
it('should set "fromName" and empty "fromEmail" when "from" does not include <email>', () => { | ||
const input = { from: 'John Doe' }; | ||
const result = separateFromIntoNameAndEmail(input); | ||
expect(result).toEqual({ | ||
fromName: 'John Doe', | ||
fromEmail: '', | ||
}); | ||
}); | ||
|
||
it('should set "fromName" and "fromEmail" to empty strings when "from" is not provided', () => { | ||
const input = {}; | ||
const result = separateFromIntoNameAndEmail(input); | ||
expect(result).toEqual({ | ||
fromName: '', | ||
fromEmail: '', | ||
}); | ||
}); | ||
|
||
it('should leave unrelated fields in the object unchanged', () => { | ||
const input = { from: 'John Doe <[email protected]>', otherField: 'value' }; | ||
const result = separateFromIntoNameAndEmail(input); | ||
expect(result).toEqual({ | ||
fromName: 'John Doe', | ||
fromEmail: '[email protected]', | ||
otherField: 'value', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('combineNameAndEmailToFrom', () => { | ||
it('should combine "fromName" and "fromEmail" into "from"', () => { | ||
const input = { fromName: 'John Doe', fromEmail: '[email protected]' }; | ||
const result = combineNameAndEmailToFrom(input); | ||
expect(result).toEqual({ | ||
from: 'John Doe <[email protected]>', | ||
}); | ||
}); | ||
|
||
it('should leave unrelated fields in the object unchanged', () => { | ||
const input = { fromName: 'John Doe', fromEmail: '[email protected]', otherField: 'value' }; | ||
const result = combineNameAndEmailToFrom(input); | ||
expect(result).toEqual({ | ||
from: 'John Doe <[email protected]>', | ||
otherField: 'value', | ||
}); | ||
}); | ||
|
||
it('should not modify the object if "fromName" or "fromEmail" is missing', () => { | ||
const input1 = { fromName: 'John Doe' }; | ||
const input2 = { fromEmail: '[email protected]' }; | ||
const input3 = {}; | ||
|
||
const result1 = combineNameAndEmailToFrom(input1); | ||
const result2 = combineNameAndEmailToFrom(input2); | ||
const result3 = combineNameAndEmailToFrom(input3); | ||
|
||
expect(result1).toEqual({ fromName: 'John Doe' }); | ||
expect(result2).toEqual({ fromEmail: '[email protected]' }); | ||
expect(result3).toEqual({}); | ||
}); | ||
}); |