Skip to content
This repository was archived by the owner on Apr 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
coverage
18 changes: 18 additions & 0 deletions lambda/custom/package-lock.json

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

8 changes: 4 additions & 4 deletions lambda/custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"ask-sdk-core": "^2.0.0",
"ask-sdk-model": "^1.0.0"
},
"repository" : {
"type" : "git",
"url" : ""
"repository": {
"type": "git",
"url": ""
}
}
}
53 changes: 53 additions & 0 deletions test/unit/fullAddress.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#=====================================================================================================================
# ______ _ ____ ______ __ _
# / __/ /__ (_) / / /_ __/__ ___ / /_(_)__ ___ _
# _\ \/ '_// / / / / / / -_|_-</ __/ / _ \/ _ `/
# /___/_/\_\/_/_/_/ /_/ \__/___/\__/_/_//_/\_, /
# /___/
#
# Created by Bespoken
# Learn more at https://read.bespoken.io/unit-testing/getting-started/
#
# Skill name: "Device Address API Integration" Sample Project by Amazon
# Test scope: LaunchRequest, GetAddressIntent, AMAZON.HelpIntent, AMAZON.StopIntent, AMAZON.CancelIntent
# Description: General test for all intents, with mocked address being returned
#=====================================================================================================================

---
configuration:
address:
addressLine1: Lincoln Blvd
city: San Francisco
countryCode: US
postalCode: 94129
stateOrRegion: CA
locale: en-US

---
- test: Launch request, no further interaction and AMAZON.StopIntent.
- LaunchRequest: # LaunchRequest is not an utterance but a request type and reserved word
- response.outputSpeech.ssml: /welcome to the sample device address api skill.*/i # Regular expression
- response.reprompt.outputSpeech.ssml: What do you want to ask?
- response.shouldEndSession: false
- AMAZON.StopIntent: Bye! Thanks for using the Sample Device Address API Skill!

---
- test: Ask for address with GetAddressIntent (full address provided).
- LaunchRequest # No expected part means anything in the actual response is fine
- GetAddressIntent: "Here is your full address: Lincoln Blvd, CA, 94129"

---
- test: Launch request, AMAZON.HelpIntent and AMAZON.CancelIntent.
- LaunchRequest
- AMAZON.HelpIntent:
- response.outputSpeech.ssml: "You can use this skill by asking something like: whats my address?"
- response.reprompt.outputSpeech.ssml: "You can use this skill by asking something like: whats my address?"
- response.shouldEndSession: false
- AMAZON.CancelIntent: Bye! Thanks for using the Sample Device Address API Skill!

---
- test: Launch request, AMAZON.HelpIntent and SessionEndedRequest.
- LaunchRequest
- AMAZON.HelpIntent
- SessionEndedRequest:
- response.outputSpeech: undefined
27 changes: 27 additions & 0 deletions test/unit/noAddress.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#=====================================================================================================================
# ______ _ ____ ______ __ _
# / __/ /__ (_) / / /_ __/__ ___ / /_(_)__ ___ _
# _\ \/ '_// / / / / / / -_|_-</ __/ / _ \/ _ `/
# /___/_/\_\/_/_/_/ /_/ \__/___/\__/_/_//_/\_, /
# /___/
#
# Created by Bespoken
# Learn more at https://read.bespoken.io/unit-testing/getting-started/
#
# Skill name: "Device Address API Integration Sample Project" by Amazon
# Test scope: GetAddressIntent
# Description: Test when a device ID is set, but no address is returned (for whatever reason)
#=====================================================================================================================

---
configuration:
deviceId: mockDeviceID
locale: en-US

---
- test: Ask for address with GetAddressIntent (no address provided).
- LaunchRequest
- GetAddressIntent:
- response.outputSpeech.ssml: Please enable Location permissions in the Amazon Alexa app.
- response.card.type: AskForPermissionsConsent
- response.card.permissions[0]: "read::alexa:device:all:address"
26 changes: 26 additions & 0 deletions test/unit/noDevice.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#=====================================================================================================================
# ______ _ ____ ______ __ _
# / __/ /__ (_) / / /_ __/__ ___ / /_(_)__ ___ _
# _\ \/ '_// / / / / / / -_|_-</ __/ / _ \/ _ `/
# /___/_/\_\/_/_/_/ /_/ \__/___/\__/_/_//_/\_, /
# /___/
#
# Created by Bespoken
# Learn more at https://read.bespoken.io/unit-testing/getting-started/
#
# Skill name: "Device Address API Integration Sample Project" by Amazon
# Test scope: GetAddressIntent
# Description: Test when no device ID is set - causes permission error
#=====================================================================================================================

---
configuration:
locale: en-US

---
- test: Ask for address with GetAddressIntent (no address provided).
- LaunchRequest
- GetAddressIntent:
- response.outputSpeech.ssml: Please enable Location permissions in the Amazon Alexa app.
- response.card.type: AskForPermissionsConsent
- response.card.permissions[0]: "read::alexa:device:all:address"
28 changes: 28 additions & 0 deletions test/unit/postalCodeOnly.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#=====================================================================================================================
# ______ _ ____ ______ __ _
# / __/ /__ (_) / / /_ __/__ ___ / /_(_)__ ___ _
# _\ \/ '_// / / / / / / -_|_-</ __/ / _ \/ _ `/
# /___/_/\_\/_/_/_/ /_/ \__/___/\__/_/_//_/\_, /
# /___/
#
# Created by Bespoken
# Learn more at https://read.bespoken.io/unit-testing/getting-started/
#
# Skill name: "Device Address API Integration Sample Project" by Amazon
# Test scope: GetAddressIntent
# Description: Test when no address is set
#=====================================================================================================================

---
configuration:
locale: en-US
address:
addressLine1: null
countryCode: US
postalCode: 94129
stateOrRegion: null

---
- test: Ask for address with GetAddressIntent (only country code provided).
- LaunchRequest
- GetAddressIntent: It looks like you don't have an address set. You can set your address from the companion app.
53 changes: 53 additions & 0 deletions test/unit/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## **How to setup and run Unit Tests**

There are several methods commonly used to test and simulate Alexa skills during the development process.
See the Alexa Cookbook [testing guide](https://github.com/alexa/alexa-cookbook/tree/master/guides/testing) for more details.

For running formal QA tests, developers can leverage third-party tools that run on standard unit test frameworks like [Jest](https://jestjs.io/) or [Mocha](https://mochajs.org/).

Here we will focus on running a test suite against your local code project using the Bespoken CLI (`bst`) from [Bespoken](https://bespoken.io).

To get started, you need to install the Bespoken CLI, please follow the next steps:
1. Install the Bespoken CLI by running `npm install -g bespoken-tools` on your command line.
2. Create the main testing folder. We recommend to name it `test`; it should be under the root of your skill's directory.
3. Create a folder named `unit` under `test\`, this folder will store your unit test script files.
4. Add the test configuration file `testing.json`. This file should be located under your `test\unit` directory. It might look like this:
```JSON
{
"handler": "../../src/index.js",
"locale": "en-US",
"trace": true,
"jest": {
"silent": false
}
}
```
The most important parameter is the handler where you indicate Bespoken's Skill Tester where the source code of your skill is. These parameters can be overwritten on each test script file under their configuration section.
5. Add your test scripts. We recommend to use next convention when naming your test script files:
* If you have only one test script: `index.test.yml`
* If you want to create more than one test script: `functionalityName.test.yml`.

The yml extension indicates this is a YAML file, which is the syntax we use to create test scripts; `test` means that is a unit test script file. A test script looks like this:
```YAML
---
configuration: # Here you define your locales and mocks
locale: en-US

--- # Three dashes start a new YAML document
- test: Launch request, no further interaction. # A description of this test sequence
- LaunchRequest: # LaunchRequest is not an utterance but a request type
- response.outputSpeech.ssml: Here's your fact
- response.card.type: Simple
- response.card.title: Space Facts
- response.card.content: "*" # A wildcard means any text will match
```
A typical YAML sentence is composed of 2 parts separated by a colon; in the left part we have the intent name we want to test; in the right part we have the expected result. You can also access any element on the JSON response object like the session attributes.
6. To execute the scripts go to the root of your project and run `bst test`. That will find and run all the unit test scripts files.

For more information about skill unit testing with Bespoken, please read [here](https://read.bespoken.io/unit-testing/getting-started/).

If you need assistance, reach Bespoken on any of these channels:
* [Chat with us](https://bespoken.io/testing) (chat is in lower right-hand corner of the page)
* [Email](mailto:[email protected])
* [Twitter](https://twitter.com/bespokenio)
* [Gitter](https://gitter.im/bespoken)
10 changes: 10 additions & 0 deletions test/unit/testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"handler": "../../lambda/custom/index.js",
"trace": false,
"jest": {
"silent": false,
"collectCoverageFrom": [
"lambda/custom/index.js"
]
}
}