Skip to content

Commit

Permalink
fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
cjiang2000 committed Jul 14, 2021
1 parent 3c4b5d3 commit dc8379a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dc8379a

Please sign in to comment.