Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/contact-center/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"deploy:npm": "yarn npm publish"
},
"dependencies": {
"@webex/contact-center": "3.10.0-next.20",
"@webex/contact-center": "3.10.0-next.33",
"mobx": "6.13.5",
"typescript": "5.6.3"
},
Expand Down
66 changes: 41 additions & 25 deletions packages/contact-center/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,49 @@ class Store implements IStore {
reject(new Error('Webex SDK failed to initialize'));
}, 6000);

//@ts-expect-error To be fixed in SDK - https://jira-eng-sjc12.cisco.com/jira/browse/CAI-6762
const webex = Webex.init({
config: options.webexConfig,
credentials: {
access_token: options.access_token,
},
});
try {
//@ts-expect-error To be fixed in SDK - https://jira-eng-sjc12.cisco.com/jira/browse/CAI-6762
const webex = Webex.init({
config: options.webexConfig,
credentials: {
access_token: options.access_token,
},
});

webex.once('ready', () => {
setupEventListeners(webex.cc);
clearTimeout(timer);
this.registerCC(webex)
.then(() => {
this.logger.log('CC-Widgets: Store init(): store initialization complete', {
module: 'cc-store#store.ts',
method: 'init',
});
resolve();
})
.catch((error) => {
this.logger.error(`CC-Widgets: Store init(): registration failed - ${error}`, {
module: 'cc-store#store.ts',
method: 'init',
});
webex.once('ready', () => {
try {
setupEventListeners(webex.cc);
clearTimeout(timer);
this.registerCC(webex)
.then(() => {
this.logger.log('CC-Widgets: Store init(): store initialization complete', {
module: 'cc-store#store.ts',
method: 'init',
});
resolve();
})
.catch((error) => {
this.logger.error(`CC-Widgets: Store init(): registration failed - ${error}`, {
module: 'cc-store#store.ts',
method: 'init',
});
reject(error);
});
} catch (error) {
clearTimeout(timer);
if (this.logger) {
this.logger.error(`CC-Widgets: Store init(): setupEventListeners failed - ${error}`, {
module: 'cc-store#store.ts',
method: 'init',
});
}
reject(error);
});
});
}
});
} catch (error) {
clearTimeout(timer);
reject(error);
}
});
}
}
Expand Down
10 changes: 9 additions & 1 deletion packages/contact-center/store/src/storeEventsWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,15 @@ class StoreWrapper implements IStoreWrapper {
};

init(options: InitParams): Promise<void> {
return this.store.init(options, this.setupIncomingTaskHandler);
return this.store.init(options, this.setupIncomingTaskHandler).catch((error) => {
const err = error instanceof Error ? error : new Error(`Store initialization failed: ${String(error)}`);

if (this.onErrorCallback) {
this.onErrorCallback('Store', err);
}

throw err;
});
}

registerCC = (webex?: WithWebex['webex']) => {
Expand Down
44 changes: 42 additions & 2 deletions packages/contact-center/store/tests/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,33 @@ describe('Store', () => {
expect(storeInstance.registerCC).toHaveBeenCalledWith(mockWebex);
});

it('should reject the promise if registerCC fails in init method', async () => {
it('should log an error and reject the promise if registerCC fails in init method', async () => {
const initParams = {
webexConfig: {anyConfig: true},
access_token: 'fake_token',
};

jest.spyOn(storeInstance, 'registerCC').mockRejectedValue(new Error('registerCC failed'));
const error = new Error('registerCC failed');
jest.spyOn(storeInstance, 'registerCC').mockRejectedValue(error);

// Provide a logger so the init() error handler can log without failing
storeInstance.logger = {
error: jest.fn(),
log: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
trace: jest.fn(),
};

await expect(storeInstance.init(initParams, jest.fn())).rejects.toThrow('registerCC failed');

expect(storeInstance.logger.error).toHaveBeenCalledWith(
'CC-Widgets: Store init(): registration failed - Error: registerCC failed',
{
module: 'cc-store#store.ts',
method: 'init',
}
);
});

it('should reject the promise if Webex SDK fails to initialize', async () => {
Expand All @@ -206,5 +224,27 @@ describe('Store', () => {

await expect(initPromise).rejects.toThrow('Webex SDK failed to initialize');
});

it('should clear timeout and reject if Webex.init throws synchronously', async () => {
const initParams = {
webexConfig: {anyConfig: true},
access_token: 'fake_token',
};

const syncError = new Error('sync init error');
// @ts-expect-error overriding mock implementation for this test
const initSpy = jest.spyOn(Webex, 'init').mockImplementation(() => {
throw syncError;
});

await expect(storeInstance.init(initParams, jest.fn())).rejects.toThrow('sync init error');

expect(initSpy).toHaveBeenCalledWith({
config: initParams.webexConfig,
credentials: {
access_token: initParams.access_token,
},
});
});
});
});
Loading
Loading