Skip to content

Commit

Permalink
Adding setup tests to cortana and google
Browse files Browse the repository at this point in the history
  • Loading branch information
carloseduardole committed May 2, 2018
1 parent 18c3cab commit 6cf67b8
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/utils/env-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

module.exports = {
encode(str) {
if(!str) return '';
return new Buffer(str).toString('base64').replace(/\+/g, '-');
},
decode(str) {
if(!str) return '';
return new Buffer(str.replace(/\-/g, '+'), 'base64').toString('utf8');
}
};
99 changes: 99 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"minimal-request-promise": "^1.3.0",
"node-mocks-http": "^1.6.6",
"oh-no-i-insist": "^1.0.0",
"sinon": "^4.5.0",
"souffleur": "^1.0.0",
"tsscmp": "^1.0.5"
},
Expand Down
77 changes: 77 additions & 0 deletions spec/cortana/cortana-setup-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*global require, describe, it, expect, beforeEach, beforeAll, afterAll jasmine*/
'use strict';
var underTest = require('../../lib/cortana/setup');
var botBuilder = require('botbuilder');
const sinon = require('sinon');
describe('Cortana setup', () => {
var api, bot, logError, parser, responder, universal, botPromise, builder;

beforeAll(() => {
builder = sinon.stub(botBuilder, 'ChatConnector').returns({ 'listen': Function });
universal = sinon.stub(botBuilder, 'UniversalBot').returns({
'use': function () {
return {
'receive': (event, next) => { next(); },
'send': (event, next) => { next(); }
};
}
});
});

afterAll(() => {
builder.restore();
universal.restore();
});

beforeEach(() => {
api = jasmine.createSpyObj('api', ['get', 'post', 'addPostDeployStep']);
bot = jasmine.createSpy().and.returnValue(botPromise);
parser = jasmine.createSpy();
logError = jasmine.createSpy();
responder = jasmine.createSpy();

underTest(api, bot, logError, parser, responder);
});
describe('message processor', () => {
const envConfig = { cortanaAppId: 'YXBwX3Rlc3Q=', cortanaAppPassword: 'YmVzdA==' };
const singleMessageTemplate = {
type: 'message',
id: '9GaUpYmT6YU',
timestamp: '2018-04-26T17:31:37.6846046Z',
serviceUrl: 'https://CortanaBFChannelEastUs.azurewebsites.net/',
channelId: 'cortana',
from:
{ id: 'E4144E913F76C' },
conversation: { id: 'd35535' },
recipient: { id: 'bot_cortana' },
locale: 'en-US',
text: 'hello cortana',
entities:
[{ type: 'Intent', name: 'None', entities: [] },
{
type: 'AuthorizationToken',
token: 'eyJhbGc',
status: 0
},
{ type: 'DeviceInfo', supportsDisplay: 'true' }]
};
it('wires the POST request for cortana to the message processor', () => {
expect(api.post.calls.count()).toEqual(1);
expect(api.post).toHaveBeenCalledWith('/cortana', jasmine.any(Function));
});
describe('processing a single message', () => {
var handler;
beforeEach(() => {
handler = api.post.calls.argsFor(0)[1];
});
it('connector to be called', () => {
handler({ body: singleMessageTemplate, env: envConfig });
expect(builder.called).toBeTruthy();
});
it('Universal bot to be called', () => {
handler({ body: singleMessageTemplate, env: envConfig });
expect(universal.called).toBeTruthy();
});
});
});
});
50 changes: 50 additions & 0 deletions spec/google/google-setup-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*global require, describe, it, expect, beforeEach, jasmine*/
'use strict';
var underTest = require('../../lib/google/setup');
describe('Google setup', () => {
var api, bot, logError, parser, responder, botPromise, botResolve, botReject;

beforeEach(() => {
api = jasmine.createSpyObj('api', ['get', 'post', 'addPostDeployStep']);
botPromise = new Promise((resolve, reject) => {
botResolve = resolve;
botReject = reject;
});
bot = jasmine.createSpy().and.returnValue(botPromise);
parser = jasmine.createSpy();
logError = jasmine.createSpy();
responder = jasmine.createSpy();

underTest(api, bot, logError, parser, responder);
});
describe('message processor', () => {

const singleMessageTemplate = {
'user': {
'userId': 'USER_ID',
'accessToken': 'USER_ACCESSTOKEN',
'locale': 'en-US',
'lastSeen': '2018-04-25T14:27:02Z'
},
'isInSandbox': true
};
it('wires the POST request for google to the message processor', () => {
expect(api.post.calls.count()).toEqual(1);
expect(api.post).toHaveBeenCalledWith('/google', jasmine.any(Function));
});
describe('processing a single message', () => {
var handler;
beforeEach(() => {
handler = api.post.calls.argsFor(0)[1];
});
it('connector to be called', () => {
handler(singleMessageTemplate);
expect(parser).toHaveBeenCalled();
});
it('test promise', () => {
botReject();
botResolve();
});
});
});
});

0 comments on commit 6cf67b8

Please sign in to comment.