Я пытаюсь проверить свой навык Alexa Trivia.Я хотел бы заглушить / подсмотреть случайное распределение вопросов.Использование mocha и Bespoken тестовых фреймворков и кода написано на NodeJS.
Используя Bespoken, вы специально не вызываете какие-либо функции, поэтому я изо всех сил пытаюсь найти, куда внедрить шпиона.
В приведенном ниже фрагменте кода мы вызываем метод choose_questions с аргументом нашего файла вопросов.Есть ли способ, которым мы можем это заглушить?Особенно, когда мы не вызываем эти обработчики непосредственно в тестах.Большая помощь очень смущает.Любая помощь будет оценена!
КОД SNIPPET
const StartQuizIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'QuizIntent'
},
handle(handlerInput) {
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes()
var quiz_questions = choose_questions(questions.QUESTIONS_EN_GB)
sessionAttributes.allQuestions = quiz_questions
var currentQuestionObject = sessionAttributes.allQuestions.pop()
var currentQuestion = currentQuestionObject.question
sessionAttributes.question = currentQuestion
var currentAnswer = currentQuestionObject.answer
sessionAttributes.answer = currentAnswer
sessionAttributes.score = 0
return handlerInput.responseBuilder
.speak(`${currentQuestion} <audio src='soundbank://soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_countdown_loop_32s_full_01'/>`)
.reprompt(currentQuestion)
.withShouldEndSession (false)
.getResponse()
},
}
const AnswerIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AnswerIntent'
},
handle(handlerInput) {
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes()
const slot = handlerInput.requestEnvelope.request.intent.slots
const answerSlot = slot['answer'].value.toLowerCase()
var speechText = ''
speechText+= determine_correct(answerSlot, sessionAttributes.answer, handlerInput)
speechText+= getNextQuestion(handlerInput)
return handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession (false)
.getResponse()
},
}
ТЕСТ
const assert = require('chai').assert;
const va = require("virtual-alexa");
const alexa = va.VirtualAlexa.Builder()
.handler("./lambda/custom/index.handler") // Lambda function file and name
.interactionModelFile("./models/en-US.json") // Path to interaction model file
.create();
describe('MySkill tests', function() {
it('My First Test', async () => {
let result = await alexa.launch();
assert.include(result.prompt(), 'Welcome to Quizza');
});
it('StopIntent', async () => {
let result = await alexa.launch();
assert.include(result.prompt(), 'Welcome to Quizza');
result = await alexa.utter('stop');
assert.include(result.prompt(), 'Goodbye.');
})
it('ReadyIntent say no', async () => {
let result = await alexa.launch();
assert.include(result.prompt(), 'Welcome to Quizza');
result = await alexa.utter('no');
assert.include(result.prompt(), 'Hurry up');
})
it('Start Game', async () => {
let result = await alexa.launch();
assert.include(result.prompt(), 'Welcome to Quizza');
result = await alexa.utter('start game');
assert.include(result.prompt(), 'A,');
})
it("Answer question incorrectly", async () => {
let result = await alexa.launch();
assert.include(result.prompt(), 'Welcome to Quizza');
result = await alexa.utter('start game');
assert.include(result.prompt(), 'A,');
result = await alexa.utter("the answer is d")
assert.include(result.prompt(), "sorry, that is wrong");
})