Skip to content

Commit

Permalink
Add dist folder to git
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtuckerphx committed Nov 20, 2018
1 parent 1857e1c commit c6fa92d
Show file tree
Hide file tree
Showing 15 changed files with 444 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -4,7 +4,6 @@ node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/dist

# Editor directories and files
.idea
Expand Down
1 change: 1 addition & 0 deletions dist/lib/decorators/CanHandleIntentRequest.d.ts
@@ -0,0 +1 @@
export declare function CanHandleIntentRequest(...intentNames: string[]): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
26 changes: 26 additions & 0 deletions dist/lib/decorators/CanHandleIntentRequest.js
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function CanHandleIntentRequest(...intentNames) {
return function (target, key, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (handlerInput) {
const className = target.constructor.name;
let possibleIntentNames = intentNames;
if (possibleIntentNames.length === 0) {
const modifiedClassName = className.replace('Handler', '');
possibleIntentNames = [className, modifiedClassName];
}
const request = handlerInput.requestEnvelope.request;
const intentName = request.intent.name;
const canHandle = request.type === 'IntentRequest' && (possibleIntentNames.indexOf(intentName) > -1);
// console.log(`CanHandleIntentRequest for '${className}' checks if '${intentName}' is in '${possibleIntentNames}' returns ${canHandle}`);
if (canHandle === false) {
return false;
}
const result = originalMethod.apply(this, arguments);
return result;
};
return descriptor;
};
}
exports.CanHandleIntentRequest = CanHandleIntentRequest;
1 change: 1 addition & 0 deletions dist/lib/decorators/CanHandleLaunchRequest.d.ts
@@ -0,0 +1 @@
export declare function CanHandleLaunchRequest(): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
18 changes: 18 additions & 0 deletions dist/lib/decorators/CanHandleLaunchRequest.js
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function CanHandleLaunchRequest() {
return function (target, key, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (handlerInput) {
const canHandle = handlerInput.requestEnvelope.request.type === 'LaunchRequest';
// console.log(`CanHandleLaunchRequest for '${target.constructor.name}' checks if '${request.type}' equals 'LaunchRequest' returns ${canHandle}`);
if (canHandle === false) {
return false;
}
const result = originalMethod.apply(this, arguments);
return result;
};
return descriptor;
};
}
exports.CanHandleLaunchRequest = CanHandleLaunchRequest;
1 change: 1 addition & 0 deletions dist/lib/decorators/CanHandleSessionEndedRequest.d.ts
@@ -0,0 +1 @@
export declare function CanHandleSessionEndedRequest(): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
18 changes: 18 additions & 0 deletions dist/lib/decorators/CanHandleSessionEndedRequest.js
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function CanHandleSessionEndedRequest() {
return function (target, key, descriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (handlerInput) {
const canHandle = handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
// console.log(`CanHandleSessionEndedRequest for '${target.constructor.name}' checks if '${request.type}' equals 'SessionEndedRequest' returns ${canHandle}`);
if (canHandle === false) {
return false;
}
const result = originalMethod.apply(this, arguments);
return result;
};
return descriptor;
};
}
exports.CanHandleSessionEndedRequest = CanHandleSessionEndedRequest;
3 changes: 3 additions & 0 deletions dist/lib/index.d.ts
@@ -0,0 +1,3 @@
export { CanHandleIntentRequest } from './decorators/CanHandleIntentRequest';
export { CanHandleLaunchRequest } from './decorators/CanHandleLaunchRequest';
export { CanHandleSessionEndedRequest } from './decorators/CanHandleSessionEndedRequest';
8 changes: 8 additions & 0 deletions dist/lib/index.js
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CanHandleIntentRequest_1 = require("./decorators/CanHandleIntentRequest");
exports.CanHandleIntentRequest = CanHandleIntentRequest_1.CanHandleIntentRequest;
var CanHandleLaunchRequest_1 = require("./decorators/CanHandleLaunchRequest");
exports.CanHandleLaunchRequest = CanHandleLaunchRequest_1.CanHandleLaunchRequest;
var CanHandleSessionEndedRequest_1 = require("./decorators/CanHandleSessionEndedRequest");
exports.CanHandleSessionEndedRequest = CanHandleSessionEndedRequest_1.CanHandleSessionEndedRequest;
1 change: 1 addition & 0 deletions dist/test/spec/CanHandleIntentRequest.spec.d.ts
@@ -0,0 +1 @@
export {};
231 changes: 231 additions & 0 deletions dist/test/spec/CanHandleIntentRequest.spec.js
@@ -0,0 +1,231 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const index_1 = require("../../lib/index");
describe("CanHandleIntentRequest", () => {
describe("with no params", () => {
class TestIntentHandler {
canHandle(handlerInput) {
return true;
}
handle(handlerInput) {
return {};
}
}
__decorate([
index_1.CanHandleIntentRequest(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Boolean)
], TestIntentHandler.prototype, "canHandle", null);
describe("where request intent name matches handler class name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'TestIntentHandler'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
describe("where request intent name does not match handler class name", () => {
it("should return false", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'MismatchIntentHandler'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(false);
});
});
describe("where request intent name matches handler class name minus handler suffix", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'TestIntent'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
});
describe("with one param", () => {
class TestIntentHandler {
canHandle(handlerInput) {
return true;
}
handle(handlerInput) {
return {};
}
}
__decorate([
index_1.CanHandleIntentRequest('MyIntent'),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Boolean)
], TestIntentHandler.prototype, "canHandle", null);
describe("where request intent name matches decorator intent name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'MyIntent'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
describe("where request intent name does not matche decorator intent name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'MismatchIntent'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(false);
});
});
});
describe("with two params", () => {
class TestIntentHandler {
canHandle(handlerInput) {
return true;
}
handle(handlerInput) {
return {};
}
}
__decorate([
index_1.CanHandleIntentRequest('MyIntent1', "MyIntent2"),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Boolean)
], TestIntentHandler.prototype, "canHandle", null);
describe("where request intent name matches decorator first intent name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'MyIntent1'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
describe("where request intent name matches decorator second intent name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'MyIntent2'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
describe("where request intent name does not matche any decorator intent name", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'WrongIntent'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(false);
});
});
});
});
1 change: 1 addition & 0 deletions dist/test/spec/CanHandleLaunchRequest.spec.d.ts
@@ -0,0 +1 @@
export {};
67 changes: 67 additions & 0 deletions dist/test/spec/CanHandleLaunchRequest.spec.js
@@ -0,0 +1,67 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const index_1 = require("../../lib/index");
describe("CanHandleLaunchRequest", () => {
class TestIntentHandler {
canHandle(handlerInput) {
return true;
}
handle(handlerInput) {
return {};
}
}
__decorate([
index_1.CanHandleLaunchRequest(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Boolean)
], TestIntentHandler.prototype, "canHandle", null);
describe("where request type is LaunchRequest", () => {
it("should return true", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'LaunchRequest',
requestId: '',
timestamp: '',
locale: ''
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(true);
});
});
describe("where request is not LaunchRequest", () => {
it("should return false", () => {
const handlerInput = {
requestEnvelope: {
request: {
type: 'IntentRequest',
requestId: '',
timestamp: '',
dialogState: {},
locale: '',
intent: {
name: 'TestIntentHandler'
}
}
}
};
const handler = new TestIntentHandler();
const result = handler.canHandle(handlerInput);
chai_1.expect(result).to.equal(false);
});
});
});
1 change: 1 addition & 0 deletions dist/test/spec/CanHandleSessionEndedRequest.spec.d.ts
@@ -0,0 +1 @@
export {};

0 comments on commit c6fa92d

Please sign in to comment.