diff --git a/tests/core/core.js b/tests/core/core.js index 2742bf583..3dbe8b783 100644 --- a/tests/core/core.js +++ b/tests/core/core.js @@ -3,6 +3,11 @@ import SearchConfig from '../../src/core/models/searchconfig'; import Storage from '../../src/core/storage/storage'; import StorageKeys from '../../src/core/storage/storagekeys'; +jest.mock('../../src/core/utils/uuid'); +const uuid = require('../../src/core/utils/uuid'); +// uuid is a mock function +uuid.generateUUID = jest.fn(() => '42'); + describe('Search requests are created properly', () => { window.performance.mark = jest.fn(); const context = { @@ -41,6 +46,44 @@ describe('Search requests are created properly', () => { }); }); +describe('sessionId is passed properly', () => { + it('sessionId is passed in universal search', () => { + const mockCore = getMockCore(); + mockCore.storage.set(StorageKeys.SESSIONS_OPT_IN, { value: true }); + mockCore.search(); + expect(mockCore._coreLibrary.universalSearch).toHaveBeenCalledWith( + expect.objectContaining({ sessionId: '42' }) + ); + }); + + it('sessionId is passed in vertical search', () => { + const mockCore = getMockCore(); + mockCore.storage.set(StorageKeys.SESSIONS_OPT_IN, { value: true }); + mockCore.verticalSearch(); + expect(mockCore._coreLibrary.verticalSearch).toHaveBeenCalledWith( + expect.objectContaining({ sessionId: '42' }) + ); + }); + + it('sessionId is not passed in universal search', () => { + const mockCore = getMockCore(); + mockCore.storage.set(StorageKeys.SESSIONS_OPT_IN, { value: false }); + mockCore.search(); + expect(mockCore._coreLibrary.universalSearch).toHaveBeenCalledWith( + expect.objectContaining({ sessionId: null }) + ); + }); + + it('sessionId is not passed in vertical search', () => { + const mockCore = getMockCore(); + mockCore.storage.set(StorageKeys.SESSIONS_OPT_IN, { value: false }); + mockCore.verticalSearch(); + expect(mockCore._coreLibrary.verticalSearch).toHaveBeenCalledWith( + expect.objectContaining({ sessionId: null }) + ); + }); +}); + function getMockCore () { const core = new Core({ storage: new Storage().init()