-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-96901 || Merge develop to org
- Loading branch information
Showing
29 changed files
with
449 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function combineNameAndEmailToFrom(inputObj) { | ||
const obj = { ...inputObj }; | ||
if (obj.fromName && obj.fromEmail) { | ||
obj.from = `${obj.fromName} <${obj.fromEmail}>`; | ||
delete obj.fromName; | ||
delete obj.fromEmail; | ||
} else { | ||
obj.from = obj.fromName || obj.fromEmail; | ||
delete obj.fromName; | ||
delete obj.fromEmail; | ||
} | ||
return obj; | ||
} | ||
|
||
export function separateFromIntoNameAndEmail(inputObj) { | ||
const obj = { ...inputObj }; | ||
if (obj.from) { | ||
const match = obj.from.match(/^(.*) <(.*)>$/); | ||
if (match) { | ||
obj.fromName = match[1]; | ||
obj.fromEmail = match[2]; | ||
} else if (obj.from.includes('@')) { | ||
obj.fromName = ''; | ||
obj.fromEmail = obj.from; | ||
} else { | ||
obj.fromName = obj.from; | ||
obj.fromEmail = ''; | ||
} | ||
delete obj.from; | ||
} else { | ||
obj.fromName = ''; | ||
obj.fromEmail = ''; | ||
} | ||
return obj; | ||
} |
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 set "from" to "fromName" or "fromEmail" if only one is provided', () => { | ||
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({ from: 'John Doe' }); | ||
expect(result2).toEqual({ from: '[email protected]' }); | ||
expect(result3).toEqual({}); | ||
}); | ||
}); |
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
Oops, something went wrong.