-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
155 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
handleLists, | ||
setConfig, | ||
mapMerchProductEvents, | ||
get, | ||
} from '../../../src/integrations/AdobeAnalytics/util'; | ||
|
||
let windowSpy; | ||
|
@@ -176,4 +177,66 @@ describe('AdobeAnalytics Utility functions tests', () => { | |
expect(result).toEqual([]); | ||
}); | ||
}); | ||
describe('get tests', () => { | ||
it('should retrieve a value from a nested object using a dot-separated string', () => { | ||
const context = { | ||
user: { | ||
id: '123', | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}, | ||
}; | ||
const value = 'user.name'; | ||
const result = get(context, value); | ||
expect(result).toBe('John Doe'); | ||
}); | ||
it('should return undefined when the path is an empty string', () => { | ||
const context = { | ||
user: { | ||
id: '123', | ||
name: 'John Doe', | ||
}, | ||
}; | ||
const value = ''; | ||
const result = get(context, value); | ||
expect(result).toBeUndefined(); | ||
}); | ||
it('should return undefined when the key contains dot', () => { | ||
const context = { | ||
user: { | ||
id: '123', | ||
name: 'John Doe', | ||
'keyWith.dot': 'value', | ||
}, | ||
}; | ||
const value = 'user.keyWith.dot'; | ||
const result = get(context, value); | ||
expect(result).toBeUndefined(); | ||
}); | ||
it('should return undefined when the key contains dot', () => { | ||
const context = { | ||
user: { | ||
id: '123', | ||
name: 'John Doe', | ||
'keyWith-dash': 'value', | ||
}, | ||
}; | ||
const value = 'user.keyWith-dash'; | ||
const result = get(context, value); | ||
expect(result).toEqual('value'); | ||
}); | ||
it('should return correct value when the value is an array and provided index', () => { | ||
const context = { | ||
user: { | ||
id: '123', | ||
name: 'John Doe', | ||
'keyWith-dash': 'value', | ||
keyWithArrayVal: ['value1', 'value2'], | ||
}, | ||
}; | ||
const value = 'user.keyWithArrayVal.1'; | ||
const result = get(context, value); | ||
expect(result).toEqual('value2'); | ||
}); | ||
}); | ||
}); |
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