-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf3e4dc
commit 6c01a95
Showing
5 changed files
with
81 additions
and
21 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
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,22 @@ | ||
const { ActionsSdkApp } = require('actions-on-google'); | ||
const expressMockery = require('node-mocks-http'); | ||
|
||
function getAssistant(request) { | ||
|
||
// Prep the request and response. | ||
var mockRequest = expressMockery.createRequest({ | ||
body: request.body | ||
}); | ||
|
||
var mockResponse = expressMockery.createResponse(); | ||
|
||
// We need this monkey patch because node-mocks-http doesn't have the append. | ||
mockResponse['append'] = (header, value) => { | ||
console.log('Google SDK added a header: "' + header + '": "' + value + '"'); | ||
}; | ||
|
||
// Feed the request/response to the assistant SDK | ||
return new ActionsSdkApp({ request: mockRequest, response: mockResponse }); | ||
} | ||
|
||
module.exports = getAssistant; |
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,34 @@ | ||
|
||
/*global describe, it, expect, require, beforeEach */ | ||
'use strict'; | ||
const getAssistant = require('../../lib/google/assistant'); | ||
var parse = require('../../lib/google/parse'); | ||
|
||
describe('Google Reply', () => { | ||
beforeEach(() => { | ||
}); | ||
|
||
it('Sets the AccessToken if AuthorizationToken is present in session', () => { | ||
const assistant = getAssistant(request); | ||
var parsed = parse(assistant, request); | ||
expect(parsed.accessToken).toEqual('USER_ACCESSTOKEN'); | ||
}); | ||
|
||
it('Sets the user_id if it is present', () => { | ||
const assistant = getAssistant(request); | ||
var parsed = parse(assistant, request); | ||
expect(parsed.sender).toEqual('USER_ID'); | ||
}); | ||
}); | ||
|
||
|
||
const request = { | ||
body: { | ||
'user': { | ||
'userId': 'USER_ID', | ||
'accessToken': 'USER_ACCESSTOKEN', | ||
'locale': 'en-US', | ||
'lastSeen': '2018-04-25T14:27:02Z' | ||
}, | ||
'isInSandbox': true | ||
}}; |
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,24 @@ | ||
/*global describe, it, expect, require, jasmine, beforeEach */ | ||
'use strict'; | ||
var reply = require('../../lib/google/reply'); | ||
|
||
|
||
describe('Google Reply', () => { | ||
var assistant; | ||
beforeEach(() => { | ||
assistant = jasmine.createSpyObj('assistant', ['tell']); | ||
assistant.response_ = jasmine.createSpyObj('assistant.response_', ['_getData']); | ||
}); | ||
|
||
it('Basic tests to test reply', ()=> { | ||
expect(reply()).toEqual(undefined); | ||
expect(reply(undefined, 'Claudia Google Bot')).toEqual(undefined); | ||
expect(reply({ hello: 'Google'}, 'Claudia Google Bot')).toEqual({ hello: 'Google'}); | ||
}); | ||
|
||
it('just calls tell when its an object', () => { | ||
reply('Hello', '', assistant); | ||
expect(assistant.tell).toHaveBeenCalled(); | ||
}); | ||
|
||
}); |