Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add integrational test of 'play <collection> should play <collection>… #450

Merged
merged 1 commit into from
Feb 12, 2019
Merged
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
8 changes: 8 additions & 0 deletions functions/tests/integration/alexa/dialog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
- user: 'random'
assistant: "I found"

- scenario: 'play <collection> should play <collection> only music'
dialog:
- user: 'play seventy eighties'
assistant:
request:
- url: 'https://askills-api.archive.org/advancedsearch.php?q=_exists_:coverage%20AND%20collection:georgeblood&fl%5B%5D=identifier,coverage,title,year&sort%5B%5D=random&rows=2&output=json'
res: '../../fixtures/albums.json'

- scenario: 'song details: when song is playing'
dialog:
- user: 'play jazz'
Expand Down
40 changes: 36 additions & 4 deletions functions/tests/integration/alexa/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ function expectOrNot (target, inverted) {
* @private
* @param res
* @param rule
* @param inverted
* @param requestWasTriggered
*/
function validateResponse (res, rule, inverted = false) {
function validateResponse (res, rule, { inverted = false, requestWasTriggered }) {
if (typeof rule === 'string') {
expect(res.response.outputSpeech).to.exist;
expect(res.response.outputSpeech.ssml).to.exist;
Expand All @@ -38,11 +40,12 @@ function validateResponse (res, rule, inverted = false) {
}

if ('without' in rule) {
return validateResponse(res, rule.without, !inverted);
validateResponse(res, rule.without, { inverted: !inverted });
return;
}

if ('all' in rule) {
rule.all.forEach(subRule => validateResponse(res, subRule, inverted));
rule.all.forEach(subRule => validateResponse(res, subRule, { inverted }));
return;
}

Expand All @@ -54,6 +57,15 @@ function validateResponse (res, rule, inverted = false) {
}
}

if ('request' in rule) {
if (requestWasTriggered) {
Object.entries(requestWasTriggered).forEach(([key, triggered]) => {
expect(triggered).to.be.true;
});
}
return;
}

if ('tells' in rule) {
expect(res.response.outputSpeech).to.exist;
expect(res.response.outputSpeech.ssml).to.exist;
Expand Down Expand Up @@ -130,6 +142,12 @@ describe('integration', () => {
axiosMock.onGet(
'https://askills-api.archive.org/metadata/gd70-10-23.aud.wolfson.15080.sbefail.shnf'
).reply(200, require('../../fixtures/gd70-10-23.aud.wolfson.15080.sbefail.shnf.json'));
axiosMock.onGet(
'https://askills-api.archive.org/metadata/gd1970-10-23.aud-wolfson.sketchy-bontempo.12227.shnf'
).reply(200, require('../../fixtures/gd70-10-23.aud.wolfson.15080.sbefail.shnf.json'));
axiosMock.onGet(
'https://askills-api.archive.org/metadata/gd1970-10-23.aud.wolfson.motb-0004.85071.flac16'
).reply(200, require('../../fixtures/gd70-10-23.aud.wolfson.15080.sbefail.shnf.json'));
axiosMock.onGet(
'https://askills-api.archive.org/advancedsearch.php?q=collection:etree&fl%5B%5D=creator,identifier&sort%5B%5D=downloads+desc&rows=3&output=json'
).reply(200, require('../../provider/fixtures/popular-of-etree.json'));
Expand Down Expand Up @@ -197,11 +215,25 @@ describe('integration', () => {

dialog.forEach(({ user, assistant }) => {
const message = [];

message.push(`should utter: "${util.inspect(user, { depth: null })}"`);
if (assistant) {
message.push(`get a response: "${JSON.stringify(assistant)}"`);
}

it(message.join(' and '), () => {
let requestWasTriggered = {};
if (assistant && assistant.request) {
assistant.request.forEach(
({ url, res }) => {
axiosMock.onGet(url).reply(function (config) {
requestWasTriggered[config.url] = true;
return [200, require(res)];
});
}
);
}

let res;
if (typeof (user) === 'string') {
info(`>> user tells: ${user}`);
Expand All @@ -220,7 +252,7 @@ describe('integration', () => {
info(`>> assistant responses: ${res.response.outputSpeech.ssml}`);
}

validateResponse(res, assistant);
validateResponse(res, assistant, { requestWasTriggered });
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions models/alexaskill/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@
"type": "ORDERS"
},
{
"name": "COLLECTION",
"name": "COLLECTION_ID",
"type": "COLLECTIONS"
}
],
"samples": [
"{ORDER_BY} Play {SUBJECT} {COLLECTION}",
"{ORDER_BY} Play {SUBJECT} {COLLECTION_ID}",
"play {ORDER_BY} of {SUBJECT}",
"play {COLLECTION} {SUBJECT}",
"play {COLLECTION_ID} {SUBJECT}",
"play {CREATOR} music",
"play {CREATOR} songs",
"{ORDER_BY} play {SUBJECT}",
Expand Down