These tests show you how you can create tests to execute the functions that make external calls, outside of the Alexa Skills context.
Verify you have node.js available locally by opening a command prompt and typing node --version
Run a test, such as the mock test, by typing:
node TestmockGet.js
Node.js programs can make reference to helper code files that are contained within the project folder. The file is "required" and given a name. All the data and functions within the file can then be accessed from this name using dotted notation.
var MymockGet = require("../mockGet.js");
var myRequest = "Florida";
var myResult;
MymockGet.mockGet(myRequest, myResult => {
console.log("sent : " + myRequest);
console.log("received : " + myResult);
}
);
sent : Florida
received : 5000
Once you have the mock function working, it will be easy to swap it out for the actual web service functions.
Another way to test the functions is via a sample skill called State Pop. The language model for State Pop expects the user to say the name of a US State, such as Florida. The State name can then be sent to one of the external service functions, and the state's population is returned to the calling code.
- Create a new skill on the Developer Portal.
- Call your skill
state pop
with invocation namestate pop
. - Copy and paste the Intent Schema below into the Interaction Model page.
{
"intents": [
{ "intent": "StateRequestIntent"
"slots":[
{
"name":"usstate",
"type":"AMAZON.US_STATE"
}
]
}
]
}
Copy and paste the Sample Utterances into the Interaction Model page.
StateRequestIntent go to {usstate}
StateRequestIntent tell me about {usstate}
Paste in the code from index.js
Back to ExternalCalls