-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding setup tests to cortana and google
- Loading branch information
1 parent
18c3cab
commit 6cf67b8
Showing
5 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |