UNPKG

ask-assertions

Version:
192 lines 9.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); function checkResponseStructure(response) { chai_1.expect(response).to.have.property("version", "1.0"); chai_1.expect(response).to.have.property("response"); } exports.checkResponseStructure = checkResponseStructure; function checkOutputSpeech(response) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.have.property("outputSpeech"); chai_1.expect(r.outputSpeech).to.have.property("type"); chai_1.expect(r.outputSpeech.type).to.equal("SSML"); chai_1.expect(r.outputSpeech).to.have.property("ssml"); const os = r.outputSpeech; chai_1.expect(os.ssml).to.match(/^<speak>/); chai_1.expect(os.ssml).to.match(/<\/speak>$/); } exports.checkOutputSpeech = checkOutputSpeech; function checkNoOutputSpeech(response) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.not.have.property("outputSpeech"); } exports.checkNoOutputSpeech = checkNoOutputSpeech; function checkOutputSpeechContains(response, text) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.have.property("outputSpeech"); chai_1.expect(r.outputSpeech).to.have.property("type"); chai_1.expect(r.outputSpeech.type).to.equal("SSML"); chai_1.expect(r.outputSpeech).to.have.property("ssml"); const os = r.outputSpeech; chai_1.expect(os.ssml).to.contains(text); chai_1.expect(os.ssml).to.match(/^<speak>/); chai_1.expect(os.ssml).to.match(/<\/speak>$/); } exports.checkOutputSpeechContains = checkOutputSpeechContains; function checkOutputSpeechContainsAtLeastOneOf(response, ...validText) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.have.property("outputSpeech"); chai_1.expect(r.outputSpeech).to.have.property("type"); chai_1.expect(r.outputSpeech.type).to.equal("SSML"); chai_1.expect(r.outputSpeech).to.have.property("ssml"); const os = r.outputSpeech; const containsAtLeastOne = validText.some(text => os.ssml.includes(text)); chai_1.expect(containsAtLeastOne).to.equal(true); chai_1.expect(os.ssml).to.match(/^<speak>/); chai_1.expect(os.ssml).to.match(/<\/speak>$/); } exports.checkOutputSpeechContainsAtLeastOneOf = checkOutputSpeechContainsAtLeastOneOf; function checkOutputSpeechDoesNotContains(response, text) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.have.property("outputSpeech"); chai_1.expect(r.outputSpeech).to.have.property("type"); chai_1.expect(r.outputSpeech.type).to.equal("SSML"); chai_1.expect(r.outputSpeech).to.have.property("ssml"); const os = r.outputSpeech; chai_1.expect(os.ssml).to.not.contains(text); chai_1.expect(os.ssml).to.match(/^<speak>/); chai_1.expect(os.ssml).to.match(/<\/speak>$/); } exports.checkOutputSpeechDoesNotContains = checkOutputSpeechDoesNotContains; function sessionAttributes(response) { return response.sessionAttributes; } exports.sessionAttributes = sessionAttributes; function checkSessionAttributes(response, obj) { chai_1.expect(sessionAttributes(response)).to.deep.include(obj); } exports.checkSessionAttributes = checkSessionAttributes; function checkSessionStatus(response, shouldEndSession) { const r = response.response; chai_1.expect(r).to.have.property("shouldEndSession"); if (shouldEndSession) { chai_1.expect(r.shouldEndSession).to.be.true; } else { chai_1.expect(r.shouldEndSession).to.be.false; } } exports.checkSessionStatus = checkSessionStatus; function checkStandardCard(response) { const r = response.response; chai_1.expect(r).to.have.property("card"); chai_1.expect(r.card.type).to.equal("Standard"); chai_1.expect(r.card.text).to.not.be.equal(""); chai_1.expect(r.card.title).to.not.be.equal(""); } exports.checkStandardCard = checkStandardCard; function checkReprompt(response) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.have.property("reprompt"); chai_1.expect(r.reprompt).to.have.property("outputSpeech"); chai_1.expect(r.reprompt.outputSpeech).to.have.property("type"); chai_1.expect(r.reprompt.outputSpeech.type).to.equal("SSML"); chai_1.expect(r.reprompt.outputSpeech).to.have.property("ssml"); const os = r.reprompt.outputSpeech; chai_1.expect(os.ssml).to.match(/^<speak>/); chai_1.expect(os.ssml).to.match(/<\/speak>$/); } exports.checkReprompt = checkReprompt; function checkNoReprompt(response) { chai_1.expect(response).to.have.property("response"); const r = response.response; chai_1.expect(r).to.not.have.property("reprompt"); } exports.checkNoReprompt = checkNoReprompt; function checkAudioPlayDirective(response, replace = true) { const r = response.response; chai_1.expect(r).to.have.property("directives"); chai_1.expect(r.directives).to.have.length.greaterThan(0); const audioDirective = r.directives.find(d => d.type === "AudioPlayer.Play"); chai_1.expect(audioDirective).to.not.equal(undefined); const app = audioDirective; chai_1.expect(app).to.have.property("playBehavior"); if (replace) { chai_1.expect(app.playBehavior).to.be.equal("REPLACE_ALL"); } else { chai_1.expect(app.playBehavior).to.be.equal("REPLACE_ENQUEUED"); } chai_1.expect(app).to.have.property("audioItem"); chai_1.expect(app.audioItem).to.have.property("stream"); chai_1.expect(app.audioItem.stream).to.have.property("url"); chai_1.expect(app.audioItem.stream.url).to.match(/^https:\/\//); chai_1.expect(app.audioItem.stream).to.have.property("token"); chai_1.expect(app.audioItem.stream).not.to.have.property("expectedPreviousToken"); chai_1.expect(app.audioItem.stream).to.have.property("offsetInMilliseconds"); chai_1.expect(app.audioItem.stream.offsetInMilliseconds).to.equal(0); } exports.checkAudioPlayDirective = checkAudioPlayDirective; function checkAudioPlayStreamURL(response, streamURL) { const r = response.response; chai_1.expect(r).to.have.property("directives"); chai_1.expect(r.directives).to.have.length.greaterThan(0); const d = r.directives.find(dir => dir.type === "AudioPlayer.Play"); chai_1.expect(d).to.not.equal(undefined); chai_1.expect(d.audioItem.stream.url).to.include(streamURL); } exports.checkAudioPlayStreamURL = checkAudioPlayStreamURL; function checkAudioStopDirective(response, replace = true) { const r = response.response; chai_1.expect(r).to.have.property("directives"); chai_1.expect(r.directives).to.have.length.greaterThan(0); const audioDirective = r.directives.find(d => d.type === "AudioPlayer.Stop"); chai_1.expect(audioDirective).to.not.equal(undefined); } exports.checkAudioStopDirective = checkAudioStopDirective; function checkNoAudioDirective(response) { const r = response.response; const audioDirective = r.directives && r.directives.find(d => d.type.startsWith("AudioPlayer")); chai_1.expect(audioDirective).to.equal(undefined); } exports.checkNoAudioDirective = checkNoAudioDirective; function checkDisplayDirective(response, imageURL) { const r = response.response; chai_1.expect(r).to.have.property("directives"); const displayDirective = r.directives.find(dir => dir.type === "Display.RenderTemplate"); chai_1.expect(displayDirective).to.not.equal(undefined); chai_1.expect(displayDirective) .to.have.property("template") .that.is.an("object"); chai_1.expect(displayDirective.template).to.have.property("backButton", "HIDDEN"); chai_1.expect(displayDirective.template).to.have.property("type", "BodyTemplate6"); chai_1.expect(displayDirective.template) .to.have.property("backgroundImage") .that.is.an("object") .that.has.property("sources") .that.is.an("array") .and.has.length.greaterThan(0); chai_1.expect(displayDirective.template.backgroundImage.sources[0]).to.have.property("url", imageURL); } exports.checkDisplayDirective = checkDisplayDirective; function checkNoDisplayDirective(response) { const r = response.response; const displayDirective = r.directives && r.directives.find(d => d.type.startsWith("Display")); chai_1.expect(displayDirective).to.equal(undefined); } exports.checkNoDisplayDirective = checkNoDisplayDirective; function checkSlotDirective(response, slot) { const r = response.response; chai_1.expect(r).to.have.property("directives"); const slotDirective = r.directives.find(dir => dir.type === "Dialog.ElicitSlot" && dir.slotToElicit === slot); chai_1.expect(slotDirective).to.not.equal(undefined); } exports.checkSlotDirective = checkSlotDirective; //# sourceMappingURL=index.js.map