diff --git a/libs/features/jarvis-chat.js b/libs/features/jarvis-chat.js index fc5c313ee5..03e516ba21 100644 --- a/libs/features/jarvis-chat.js +++ b/libs/features/jarvis-chat.js @@ -204,7 +204,7 @@ const openChat = (event) => { }; const startInitialization = async (config, event, onDemand) => { - const asset = 'https://client.messaging.adobe.com/latest/AdobeMessagingClient'; + const asset = `https://${config.env.name !== 'prod' ? 'stage-' : ''}client.messaging.adobe.com/latest/AdobeMessagingClient`; await Promise.all([ loadStyle(`${asset}.css`), loadScript(`${asset}.js`), diff --git a/test/features/jarvis-chat/jarvis-chat.test.js b/test/features/jarvis-chat/jarvis-chat.test.js index ee6e6fe273..ba3e260b2f 100644 --- a/test/features/jarvis-chat/jarvis-chat.test.js +++ b/test/features/jarvis-chat/jarvis-chat.test.js @@ -262,4 +262,29 @@ describe('Jarvis Chat', () => { params.callbacks.onReadyCallback(); expect(openMessagingWindowSpy.called).to.be.true; }); + + it('should use stage asset URL in non-prod environment', async () => { + setConfig(defaultConfig); + const config = getConfig(); + config.jarvis.onDemand = false; + const loadScriptSpy = sinon.spy(); + const loadStyleSpy = sinon.spy(); + await initJarvisChat(config, loadScriptSpy, loadStyleSpy, sinon.stub()); + const expectedAsset = 'https://stage-client.messaging.adobe.com/latest/AdobeMessagingClient'; + expect(loadScriptSpy.calledWithExactly(`${expectedAsset}.js`)).to.be.true; + expect(loadStyleSpy.calledWithExactly(`${expectedAsset}.css`)).to.be.true; + }); + + it('should use prod asset URL in prod environment', async () => { + setConfig(defaultConfig); + const config = getConfig(); + config.jarvis.onDemand = false; + config.env.name = 'prod'; + const loadScriptSpy = sinon.spy(); + const loadStyleSpy = sinon.spy(); + await initJarvisChat(config, loadScriptSpy, loadStyleSpy, sinon.stub()); + const expectedAsset = 'https://client.messaging.adobe.com/latest/AdobeMessagingClient'; + expect(loadScriptSpy.calledWithExactly(`${expectedAsset}.js`)).to.be.true; + expect(loadStyleSpy.calledWithExactly(`${expectedAsset}.css`)).to.be.true; + }); });