48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import { handler } from './index.js';
|
|
|
|
function buildIntentEvent(intentName, slots = {}) {
|
|
const formattedSlots = {};
|
|
for (const [k, v] of Object.entries(slots)) {
|
|
formattedSlots[k] = { name: k, value: String(v) };
|
|
}
|
|
return {
|
|
version: '1.0',
|
|
session: { new: false, sessionId: 'SessionId.test', application: { applicationId: 'amzn1.ask.skill.test' } },
|
|
context: { System: { application: { applicationId: 'amzn1.ask.skill.test' } } },
|
|
request: {
|
|
type: 'IntentRequest',
|
|
requestId: 'EdwRequestId.test',
|
|
timestamp: new Date().toISOString(),
|
|
locale: 'fr-FR',
|
|
intent: {
|
|
name: intentName,
|
|
confirmationStatus: 'NONE',
|
|
slots: formattedSlots
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
async function runTests() {
|
|
console.log('🎙️ Test local du Skill Alexa "La Banque des Coquillages"...\n');
|
|
const tests = [
|
|
{ label: 'Solde de Violette', event: buildIntentEvent('GetBalanceIntent', { ChildName: 'Violette' }) },
|
|
{ label: 'Activités du mois', event: buildIntentEvent('ListActivitiesIntent', {}) },
|
|
{ label: 'Simulation intérêts (10 coquillages)', event: buildIntentEvent('SimulateInterestIntent', { ShellCount: 10 }) }
|
|
];
|
|
|
|
for (const t of tests) {
|
|
try {
|
|
const res = await new Promise((resolve, reject) => {
|
|
handler(t.event, {}, (err, response) => (err ? reject(err) : resolve(response)));
|
|
});
|
|
console.log(`✅ [${t.label}] ->`, res.response.outputSpeech.ssml);
|
|
} catch (e) {
|
|
console.error(`❌ [${t.label}] -> Erreur (assurez-vous que 'back' tourne sur le port 4000):`, e.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
runTests();
|
|
|