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

alexa smart home event schema #8255

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions lib/plugins/aws/package/compile/events/alexaSmartHome/index.js
Expand Up @@ -11,9 +11,25 @@ class AwsCompileAlexaSmartHomeEvents {
'package:compileEvents': this.compileAlexaSmartHomeEvents.bind(this),
};

// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8024
const appIdSchema = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'll be good to define awsAlexaEventToken at

and rely on that ?

Especially that it looks we will need same reference in alexaSkill event

type: 'string',
minLength: 0,
maxLength: 256,
pattern: '^[a-zA-Z0-9._\\-]+$',
};

this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'alexaSmartHome', {
anyOf: [{ type: 'string' }, { type: 'object' }],
anyOf: [
appIdSchema,
{
type: 'object',
properties: {
appId: appIdSchema,
enabled: { type: 'boolean' },
},
required: ['appId'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We miss additionalProperties: false

},
],
});
}

Expand All @@ -30,15 +46,6 @@ class AwsCompileAlexaSmartHomeEvents {
let Action;

if (typeof event.alexaSmartHome === 'object') {
if (!event.alexaSmartHome.appId) {
const errorMessage = [
`Missing "appId" property for alexaSmartHome event in function ${functionName}`,
' The correct syntax is: appId: amzn1.ask.skill.xxxx-xxxx',
' OR an object with "appId" property.',
' Please check the docs for more info.',
].join('');
throw new this.serverless.classes.Error(errorMessage);
}
EventSourceToken = event.alexaSmartHome.appId;
Action =
event.alexaSmartHome.enabled !== false
Expand All @@ -47,13 +54,6 @@ class AwsCompileAlexaSmartHomeEvents {
} else if (typeof event.alexaSmartHome === 'string') {
EventSourceToken = event.alexaSmartHome;
Action = 'lambda:InvokeFunction';
} else {
const errorMessage = [
`Alexa Smart Home event of function "${functionName}" is not an object or string.`,
' The correct syntax is: alexaSmartHome.',
' Please check the docs for more info.',
].join('');
throw new this.serverless.classes.Error(errorMessage);
}
const lambdaLogicalId = this.provider.naming.getLambdaLogicalId(functionName);

Expand Down
Expand Up @@ -23,36 +23,6 @@ describe('AwsCompileAlexaSmartHomeEvents', () => {
});

describe('#compileAlexaSmartHomeEvents()', () => {
it('should throw an error if alexaSmartHome event type is not a string or an object', () => {
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
first: {
events: [
{
alexaSmartHome: 42,
},
],
},
};

expect(() => awsCompileAlexaSmartHomeEvents.compileAlexaSmartHomeEvents()).to.throw(Error);
});

it('should throw an error if the "appId" property is not given', () => {
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
first: {
events: [
{
alexaSmartHome: {
appId: null,
},
},
],
},
};

expect(() => awsCompileAlexaSmartHomeEvents.compileAlexaSmartHomeEvents()).to.throw(Error);
});

it('should create corresponding resources when alexaSmartHome events are given', () => {
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
first: {
Expand Down