Skip to content

Commit

Permalink
fix: cover LaunchIntent & ErrorHandler in test and cleanup Launch res…
Browse files Browse the repository at this point in the history
…ponse
  • Loading branch information
favna committed Jan 5, 2020
1 parent 0586dc1 commit 8d3fb40
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
32 changes: 32 additions & 0 deletions __tests__/DexIntent.test.ts
Expand Up @@ -214,4 +214,36 @@ describe('DexIntent', () => {
It is genderless.</speak>
`);
});

test('GIVEN invalid data THEN returns error response', async () => {
// Mocking out the GraphQL warning response
jest.spyOn(console, 'warn').mockImplementationOnce(() => undefined);
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'IntentRequest',
intent: {
name: 'DexIntent',
slots: {
POKEMON: {
name: 'POKEMON',
value: 'aklsjdkjlashgdjlhaksgdjaghsdghasjd'
}
}
}
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>I am sorry but I could not resolve that query.
I think you said aklsjdkjlashgdjlhaksgdjaghsdghasjd?
Maybe try again, or respond with \"Alexa Cancel\" if you want to stop.</speak>
`);
});
});
34 changes: 34 additions & 0 deletions __tests__/LaunchIntent.test.ts
@@ -0,0 +1,34 @@
import { oneLine } from 'common-tags';
import fetch from 'supertest';
import { SERVER, setup, teardown } from './utils';

describe('LaunchIntent', () => {
beforeAll(() => {
setup();
});

afterAll(() => {
teardown();
});

test('GIVEN Request to Launch THEN returns launch blurb', async () => {
expect.assertions(2);

const res = await fetch(SERVER)
.post('/dexa')
.send({
request: {
type: 'LaunchRequest'
}
});

const { ssml } = res.body.response.outputSpeech;

expect(res.status).toBe(200);
expect(ssml).toBe(oneLine`
<speak>Welcome to Dexa, your one stop place for PokéDex information.
You can start browsing right away by giving me a command, or respond with \"help\" to learn all my commands.
If you want to stop Dexa, then respond with \"Alexa Stop\".</speak>
`);
});
});
4 changes: 2 additions & 2 deletions src/dexa.ts
Expand Up @@ -295,7 +295,7 @@ export default class extends AlexaApp {
'Welcome to Dexa, your one stop place for PokéDex information.',
'You can start browsing right away by giving me a command, or respond with "help" to learn all my commands.',
'If you want to stop Dexa, then respond with "Alexa Stop".'
].join('');
].join(' ');

const reprompt = 'I did not quite catch that, could you repeat it?';

Expand All @@ -320,7 +320,7 @@ export default class extends AlexaApp {

private throwQueryErr(res: Response, req: Request, slot: SLOTS) {
const prompt = [
'Woops, I could not resolve that query.',
'I am sorry but I could not resolve that query.',
req.slot(slot) ? `I think you said ${removeDiacritics(req.slot(slot))}? ` : '',
'Maybe try again, or respond with "Alexa Cancel" if you want to stop.'
].join(' ');
Expand Down

0 comments on commit 8d3fb40

Please sign in to comment.