Skip to content

Commit 58db7da

Browse files
authored
Merge pull request #11 from yoichiro/method_aliases
Support simple API names and add `locale` property
2 parents 75ad1dd + e2d617d commit 58db7da

File tree

10 files changed

+213
-42
lines changed

10 files changed

+213
-42
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ package-lock.json
44
*.tgz
55
.nyc_output/
66
dist/
7-
package/
7+
package/
8+
docs/

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const action = new ActionsOnGoogleAva(require('./test/test-credentials.json'));
4444
// Start out with giving a name to this test
4545
action.startTest('Facts about Google - direct cat path', action => {
4646
// Return a promise that starts a conversation with your test app
47-
return action.startConversation()
47+
return action.start()
4848
.then(({ textToSpeech }) => {
4949
// Get a response back from your fulfillment.
5050
// To continue the conversation, you can send
@@ -70,6 +70,17 @@ action.startTest('Facts about Google - direct cat path', action => {
7070
```
7171
12. Run `yarn test`. You should see your test be executed.
7272

73+
## Supported features
74+
75+
This library provides the following features to control your conversation:
76+
77+
* `action.start()` - Start your conversation with your action using "my test app".
78+
* `action.startWith()` - Start your conversation with your action using the specified action name.
79+
* `action.send()` - Send some phrase to your action.
80+
* `action.cancel()` - End your conversation. This library says "cancel".
81+
* `action.locale` - Set a locale for your conversation.
82+
* `action.location` - Set an array of a latitude and a longitude.
83+
7384
## Possible responses
7485

7586
These responses will come from your fulfillment, and will consist of whatever
@@ -120,13 +131,6 @@ res
120131
.divider - Boolean
121132
```
122133

123-
## Additional features
124-
125-
You can run a few different types of automated test scenarios.
126-
127-
* `action.location = [latitude, longitude];`
128-
* `action.locale = 'en-US'; // Or any other supported locale`
129-
130134
## Known Issues
131135

132136
* Testing transactions does not work

examples/facts-about-google-ts/test/facts-about-google.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const action: ActionsOnGoogleAva = new ActionsOnGoogleAva(require(
2424
// Start action and ask for history facts until there are no more history factsi
2525
action.startTest('Facts about Google - history path', async (action: ActionsOnGoogleAva) => {
2626
let appResponse: AssistResponse
27-
await action.startConversation()
27+
await action.start()
2828
appResponse = await action.send('history')
2929
expect(appResponse.textToSpeech[0]).to.have.string("Sure, here's a history fact.")
3030
appResponse = await action.send('sure')
@@ -40,7 +40,7 @@ action.startTest('Facts about Google - history path', async (action: ActionsOnGo
4040
// Start action and ask for headquarter facts until there are no more headquarter facts
4141
action.startTest('Facts about Google - headquarters path', async (action: ActionsOnGoogleAva) => {
4242
let appResponse: AssistResponse
43-
await action.startConversation()
43+
await action.start()
4444
appResponse = await action.send('headquarters')
4545
expect(appResponse.textToSpeech[0]).to.have.string("Okay, here's a headquarters fact.")
4646
appResponse = await action.send('sure')
@@ -54,7 +54,7 @@ action.startTest('Facts about Google - headquarters path', async (action: Action
5454
// Start action and ask for a cat fact right away
5555
action.startTest('Facts about Google - direct cat path', async (action: ActionsOnGoogleAva) => {
5656
let appResponse: AssistResponse
57-
await action.startConversation()
57+
await action.start()
5858
appResponse = await action.send('cats')
5959
expect(appResponse.textToSpeech[0]).to.have.string("Alright, here's a cat fact.")
6060
})
@@ -63,7 +63,7 @@ action.startTest('Facts about Google - direct cat path', async (action: ActionsO
6363
// then switch to provide facts about cats
6464
action.startTest('Facts about Google - cat path', async (action: ActionsOnGoogleAva) => {
6565
let appResponse: AssistResponse
66-
await action.startConversation()
66+
await action.start()
6767
appResponse = await action.send('headquarters')
6868
expect(appResponse.textToSpeech[0]).to.have.string("Okay, here's a headquarters fact.")
6969
appResponse = await action.send('sure')

examples/facts-about-google/test/facts-about-google.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const action = new ActionsOnGoogleAva(require('../../../test-credentials.json'))
3434

3535
// Start action and ask for history facts until there are no more history facts
3636
action.startTest('Facts about Google - history path', action => {
37-
return action.startConversation()
37+
return action.start()
3838
.then((res) => {
3939
return action.send('history')
4040
})
@@ -61,7 +61,7 @@ action.startTest('Facts about Google - history path', action => {
6161

6262
// Start action and ask for headquarter facts until there are no more headquarter facts
6363
action.startTest('Facts about Google - headquarters path', action => {
64-
return action.startConversation()
64+
return action.start()
6565
.then(({ textToSpeech }) => {
6666
return action.send('headquarters')
6767
})
@@ -84,7 +84,7 @@ action.startTest('Facts about Google - headquarters path', action => {
8484

8585
// Start action and ask for a cat fact right away
8686
action.startTest('Facts about Google - direct cat path', action => {
87-
return action.startConversation()
87+
return action.start()
8888
.then(({ textToSpeech }) => {
8989
return action.send('cats');
9090
})
@@ -96,7 +96,7 @@ action.startTest('Facts about Google - direct cat path', action => {
9696
// Start action and ask for headquarters until there are no more headquarter facts,
9797
// then switch to provide facts about cats
9898
action.startTest('Facts about Google - cat path', action => {
99-
return action.startConversation()
99+
return action.start()
100100
.then(({ textToSpeech }) => {
101101
return action.send('headquarters')
102102
})

examples/number-genie/test/number-genie.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const action = new ActionsOnGoogleAva(require('../../../test-credentials.json'))
3434

3535
// Should start action, presetting the answer to fifty. Then guess a few times until the answer is 50.
3636
action.startTest('Number Genie - should guess the right answer', action => {
37-
return action.startConversation('about 50')
37+
return action.start('about 50')
3838
.then(({ displayText, cards }) => {
3939
expect(displayText[0]).to.have.string("I'm thinking of a number from 0 to 100.");
4040
expect(displayText[1]).to.be.equal("What's your first guess?");
@@ -66,7 +66,7 @@ action.startTest('Number Genie - should guess the right answer', action => {
6666

6767
// Should start action, presetting the answer to a number higher than the range 0-100
6868
action.startTest('Number Genie - starts with invalid number', action => {
69-
return action.startConversation('about 250')
69+
return action.start('about 250')
7070
.then(({ displayText }) => {
7171
expect(displayText[0]).to.have.string("Woah there! I can't use that number.");
7272
expect(displayText[1]).to.be.equal("What's your first guess?");
@@ -82,7 +82,7 @@ action.startTest('Number Genie - starts with invalid number', action => {
8282

8383
// Should start action using the French locale, and confirm the response is also in French
8484
action.startTest('Number Genie French', action => {
85-
action.setLocale('fr-FR');
85+
action.locale = 'fr-FR';
8686
return action.send('parle avec mon application test') // Talk to my test app
8787
.then(({ displayText, cards }) => {
8888
expect(displayText[1]).to.be.equal("Quel est votre premier essai ?");

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"node": ">=6.0.0"
1111
},
1212
"scripts": {
13-
"clean": "rm -rf dist",
13+
"clean": "rm -rf dist docs",
1414
"lint": "tslint -p .",
1515
"build": "tsc && cp -r ./locales ./dist",
16-
"test": "yarn clean && yarn build && yarn lint && nyc ava --fail-fast dist/test/test.js"
16+
"test": "yarn clean && yarn build && yarn lint && nyc ava --fail-fast dist/test/test.js",
17+
"docs": "typedoc --options typedoc.json",
18+
"docs:clean": "rm -rf docs && mkdir docs && touch docs/.nojekyll && yarn docs"
1719
},
1820
"repository": {
1921
"type": "git",
@@ -53,6 +55,7 @@
5355
"sinon": "^6.0.0",
5456
"tslint": "^5.9.1",
5557
"tslint-eslint-rules": "^5.1.0",
58+
"typedoc": "^0.11.1",
5659
"typescript": "^2.7.2",
5760
"winston": "2.2.0"
5861
}

src/actions-on-google.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,14 @@ export class ActionsOnGoogle {
260260
return client
261261
}
262262

263+
/**
264+
* @deprecated This will be removed in future releases. Use `action.locale` instead.
265+
*/
263266
setLocale(l: string) {
267+
this.locale = l
268+
}
269+
270+
set locale(l: string) {
264271
if (SUPPORTED_LOCALES.concat(Object.keys(FALLBACK_LOCALES)).indexOf(l) === -1) {
265272
console.warn(`Warning: Unsupported locale '${l}' in this tool. Ignore.`)
266273
}
@@ -276,18 +283,39 @@ export class ActionsOnGoogle {
276283
}
277284
}
278285

286+
/**
287+
* @deprecated This will be removed at releasing a version 1.
288+
*/
279289
startConversation(prompt?: string) {
280-
return this.startConversationWith(this.i18n_('my_test_app'), prompt)
290+
return this.start(prompt)
281291
}
282292

293+
start(prompt?: string) {
294+
return this.startWith(this.i18n_('my_test_app'), prompt)
295+
}
296+
297+
/**
298+
* @deprecated This will be removed at releasing a version 1.
299+
*/
283300
startConversationWith(action: string, prompt?: string) {
301+
return this.startWith(action, prompt)
302+
}
303+
304+
startWith(action: string, prompt?: string) {
284305
const query = prompt
285306
? this.i18n_('start_conversation_with_prompt', { app_name: action, prompt })
286307
: this.i18n_('start_conversation', { app_name: action })
287308
return this.send(query)
288309
}
289310

311+
/**
312+
* @deprecated This will be removed at releasing a version 1.
313+
*/
290314
endConversation() {
315+
return this.cancel()
316+
}
317+
318+
cancel() {
291319
return this.send(this.i18n_('cancel'))
292320
}
293321

@@ -496,4 +524,4 @@ export class ActionsOnGoogle {
496524
conversation.end()
497525
})
498526
}
499-
}
527+
}

src/test/test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test.serial('sends correct request parameters - en-US', t => {
8888
}
8989
})
9090

91-
return action.startConversation('')
91+
return action.start('')
9292
.then(res => {
9393
t.pass()
9494
mockResponse.restore()
@@ -123,11 +123,11 @@ test.serial('sends correct request parameters - fr-FR', t => {
123123
}
124124
})
125125

126-
action.setLocale('fr-FR')
127-
return action.startConversation('')
126+
action.locale = 'fr-FR'
127+
return action.start('')
128128
.then(res => {
129129
t.pass()
130-
action.setLocale('en-US')
130+
action.locale = 'en-US'
131131
mockResponse.restore()
132132
})
133133
})
@@ -140,7 +140,7 @@ test.serial('opens and exits action', t => {
140140
return conversation
141141
})
142142

143-
return action.startConversation('')
143+
return action.start('')
144144
.then((res: AssistResponse) => {
145145
t.deepEqual(res, Sample.NUMBER_GENIE_WELCOME_VALUES)
146146
mockResponse.restore()
@@ -155,7 +155,7 @@ test.serial('verifies parsing closing response of conversation', t => {
155155
return conversation
156156
})
157157

158-
return action.startConversation('')
158+
return action.start('')
159159
.then((res: AssistResponse) => {
160160
t.is(res.textToSpeech[0],
161161
'<speak>OK, I\'m already thinking of a number for next time.</speak>')
@@ -173,7 +173,7 @@ test.serial('verifies parsing textToSpeech, displayText, suggestions', t => {
173173
return conversation
174174
})
175175

176-
return action.startConversation('')
176+
return action.start('')
177177
.then((res: AssistResponse) => {
178178
t.is(res.textToSpeech[0], 'Hi there!')
179179
t.is(res.textToSpeech[1], 'I can show you basic cards, lists and carousels as well as ' +
@@ -195,7 +195,7 @@ test.serial('verifies parsing basic cards', t => {
195195
return conversation
196196
})
197197

198-
return action.startConversation('')
198+
return action.start('')
199199
.then((res: AssistResponse) => {
200200
const basicCard = res.cards![0]
201201
t.is(basicCard.title, 'Title: this is a title')
@@ -222,7 +222,7 @@ test.serial('verifies parsing a browse carousel', t => {
222222
return conversation
223223
})
224224

225-
return action.startConversation('')
225+
return action.start('')
226226
.then((res: AssistResponse) => {
227227
const firstItem = res.carousel![0]
228228
const secondItem = res.carousel![1]
@@ -246,7 +246,7 @@ test.serial('verifies parsing a carousel', t => {
246246
return conversation
247247
})
248248

249-
return action.startConversation('')
249+
return action.start('')
250250
.then((res: AssistResponse) => {
251251
const firstItem = res.carousel![0]
252252
t.is(res.carousel!.length, 4)
@@ -275,7 +275,7 @@ test.serial('verifies parsing a list', t => {
275275
return conversation
276276
})
277277

278-
return action.startConversation('')
278+
return action.start('')
279279
.then((res: AssistResponse) => {
280280
const firstItem = res.list!.items[0]
281281
t.is(res.list!.items.length, 4)
@@ -305,7 +305,7 @@ test.serial('verifies parsing a media response', t => {
305305
return conversation
306306
})
307307

308-
return action.startConversation('')
308+
return action.start('')
309309
.then((res: AssistResponse) => {
310310
t.is(res.mediaResponse!.type, 'AUDIO')
311311
t.is(res.mediaResponse!.name, 'Jazz in Paris')
@@ -326,7 +326,7 @@ test.serial('verifies parsing a linkout suggestion', t => {
326326
return conversation
327327
})
328328

329-
return action.startConversation('')
329+
return action.start('')
330330
.then((res: AssistResponse) => {
331331
t.is(res.linkOutSuggestion!.url, 'https://assistant.google.com/')
332332
t.is(res.linkOutSuggestion!.name, 'Suggestion Link')
@@ -342,7 +342,7 @@ test.serial('verifies parsing a table', t => {
342342
return conversation
343343
})
344344

345-
return action!.startConversation('')
345+
return action!.start('')
346346
.then((res: AssistResponse) => {
347347
t.deepEqual(res.table!.headers, ['header 1', 'header 2', 'header 3'])
348348
t.deepEqual(res.table!.rows[0].cells, ['row 1 item 1', 'row 1 item 2', 'row 1 item 3'])

typedoc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"out": "docs",
3+
"exclude": [
4+
"**/test/**/*.*",
5+
"**/index.ts"
6+
],
7+
"ignoreCompilerErrors": true,
8+
"disableOutputCheck": true,
9+
"excludeExternals": true,
10+
"excludePrivate": true,
11+
"excludeNotExported": true
12+
}

0 commit comments

Comments
 (0)