Skip to content

Instantly share code, notes, and snippets.

View microsoftly's full-sized avatar

Matthew Schwartz microsoftly

View GitHub Profile
@microsoftly
microsoftly / componentTest.ts
Last active November 21, 2018 08:04
mocked http tests for awwCounter
import { expect } from 'chai';
import { TapeDeck } from 'mocha-tape-deck';
import { getDogAndCatTitleCount } from './awwCounter';
describe('Aww counter component test', function () {
const deck = new TapeDeck('./cassettes');
deck.createTest('Expects 2 cats and 5 dogs when selecting 20 titles', async () => {
const { cat, dog } = await getDogAndCatTitleCount(20);
@microsoftly
microsoftly / test.ts
Created November 21, 2018 08:02
test the implementation of the aww counter
import { expect } from 'chai';
import { getDogAndCatTitleCount } from './awwCounter';
describe('Aww counter', () => {
it('Expects 2 cats and 5 dogs when selecting 20 titles', async () => {
const { cat, dog } = await getDogAndCatTitleCount(20);
expect(cat).to.be.equal(2)
expect(dog).to.be.equal(5);
})
@microsoftly
microsoftly / awwCounter.ts
Last active November 29, 2018 16:44
get the count of n hot /r/aww posts that contain cat or dog in the title
import rp = require("request-promise");
function countTitlesWithCatOrDog(titles) {
return titles.reduce((accumulator, title) => {
if (title.toLowerCase().includes('cat')) {
accumulator.cat++
}
if (title.toLowerCase().includes('dog')) {
accumulator.dog++
const { BotTester } = require('bot-tester');
const { expect } = require('chai');
describe('Bot Tester', () => {
it('accepts RegExp', () => {
const numberRegex = /^\d+/;
bot.dialog('/', (session) => {
session.send(session.message.text);
});
const { BotTester } = require('bot-tester');
const { expect } = require('chai');
const defaultAddress = { channelId: 'console',
user: { id: 'user1', name: 'A' },
bot: { id: 'bot', name: 'Bot' },
conversation: { id: 'user1Conversation' }
};
describe ('Bot Tester', () => {
@microsoftly
microsoftly / TestStepsAreThenable.ts
Created August 28, 2017 23:44
familiar .then syntax can be used between test steps
const { BotTester } = require('bot-tester');
const { expect } = require('chai');
describe('Bot Tester', () => {
it('can do arbitrary work between test steps', () => {
let responseString = 'goodbye';
bot.dialog('/', (session) => {
// send only numbers for this test case ....
session.send(responseString);
@microsoftly
microsoftly / SendStringsToBot.ts
Last active August 29, 2017 00:21
BotTester testing expected responses with strings only
const { BotTester } = require('bot-tester');
const { expect } = require('chai');
describe('Bot Tester', () => {
it('can test prompts', () => {
bot.dialog('/', [(session) => {
new Prompts.text(session, 'Hi there! Tell me something you like');
}, (session, results) => {
session.send(`${results.response} is pretty cool.`);
new Prompts.text(session, 'Why do you like it?');
@microsoftly
microsoftly / BotTesterCanInspectSession.ts
Last active August 28, 2017 23:45
The BotTester framework can inspect session state
const { BotTester } = require('bot-tester');
const { expect } = require('chai');
describe('Bot Tester', () => {
it('can inspect session state', () => {
bot.dialog('/', [(session) => {
new Prompts.text(session, 'What would you like to set data to?');
}, (session, results) => {
session.userData = { data: results.response };
session.save();
@microsoftly
microsoftly / botbuilderSwitchTest.js
Last active August 28, 2017 23:29
botbuilder unit test canonical
var assert = require('assert');
var builder = require('../');
describe('dialogs', function () {
this.timeout(5000);
it('should process a waterfall of all built-in prompt types', function (done) {
var step = 0;
var connector = new builder.ConsoleConnector();
var bot = new builder.UniversalBot(connector);