Skip to content

Commit

Permalink
Migrated tests to Offline Mockbot (#2392)
Browse files Browse the repository at this point in the history
* Added offline MockBot

* Moved tests offline

* Change offline to useProductionBot

* Small issues
  • Loading branch information
tdurnford authored and corinagum committed Sep 12, 2019
1 parent 7da2850 commit 9282174
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion __tests__/cardActionMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ test('card action "signin"', async () => {
return next(cardAction);
}
}
}
},
useProductionBot: true
});

await driver.wait(uiConnected(), timeouts.directLine);
Expand Down
42 changes: 25 additions & 17 deletions __tests__/setup/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
width: 100%;
}
</style>
<script src="https://tdurnford.github.io/BotFramework-Offline-MockBot/index.js"></script>
<script src="https://unpkg.com/event-target-shim@5.0.1/dist/event-target-shim.umd.js"></script>
<script src="/createProduceConsumeBroker.js"></script>
<script src="/mockWebSpeech.js"></script>
Expand Down Expand Up @@ -92,27 +93,36 @@
const PASSTHRU_MIDDLEWARE = store => next => action => next(action);

async function main(options) {
let { createDirectLine, createStyleSet, props, setup, storeInitialState = {}, storeMiddleware = PASSTHRU_MIDDLEWARE } = unmarshal(options);
let { createDirectLine, createStyleSet, props, setup, storeInitialState = {}, storeMiddleware = PASSTHRU_MIDDLEWARE, useProductionBot } = unmarshal(options);

props = unmarshal(props);

if (setup) { await setup(); }

await loadScript('/webchat-instrumented.js');

const { token } = await retry(async () => {
try {
const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST', timeout: 2000 });

return await res.json();
} catch (err) {
console.error('Failed to fetch Direct Line token from Mockbot.');
console.error(err);

throw err;
}
}, 3);

let directLine;

if (!useProductionBot && !createDirectLine) {
directLine = window.MockBotAdapter.createDirectLine({});
} else {
const { token } = await retry(async () => {
try {
const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST', timeout: 2000 });

return await res.json();
} catch (err) {
console.error('Failed to fetch Direct Line token from Mockbot.');
console.error(err);

throw err;
}
}, 3);

createDirectLine || (createDirectLine = window.WebChat.createDirectLine);
directLine = (createDirectLine || window.WebChat.createDirectLine)({ token });
}

const store = window.WebChatTest.store = window.WebChat.createStore(storeInitialState, store => {
const setupMiddleware = storeMiddleware(store);

Expand All @@ -127,10 +137,8 @@
};
});

createDirectLine || (createDirectLine = window.WebChat.createDirectLine);

window.WebChat.renderWebChat({
directLine: createDirectLine({ token }),
directLine,
store,
styleSet: createStyleSet && createStyleSet(props.styleOptions),
username: 'Happy Web Chat user',
Expand Down

0 comments on commit 9282174

Please sign in to comment.