Socket
Socket
Sign inDemoInstall

@serverless/event-mocks

Package Overview
Dependencies
2
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.1.1

dist/events/aws/alexa-skill-event-template.json

22

dist/index.d.ts

@@ -1,2 +0,20 @@

import { GeneratedEvent } from './generatedEvent';
export default function createEvent(eventType: string, body: any): GeneratedEvent;
import { ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent, CloudWatchLogsEvent } from "aws-lambda";
import { AlexaSmartHomeEvent, AlexaSkillEvent, CloudWatchEvent } from "aws-lambda";
declare const dictionary: {
"aws:sns": SNSEvent;
"aws:sqs": SQSEvent;
"aws:apiGateway": import("aws-lambda").APIGatewayProxyEvent;
"aws:scheduled": ScheduledEvent;
"aws:s3": S3Event;
"aws:kinesis": KinesisStreamEvent;
"aws:dynamo": DynamoDBStreamEvent;
"aws:cloudWatchLog": CloudWatchLogsEvent;
"aws:alexaSmartHome": AlexaSmartHomeEvent;
"aws:alexaSkill": AlexaSkillEvent;
"aws:cloudWatch": CloudWatchEvent;
"aws:iot": any;
"aws:cognitoUserPool": import("aws-lambda").CognitoUserPoolTriggerEvent;
"aws:websocket": import("aws-lambda").APIGatewayProxyEvent;
};
export default function createEvent<T extends keyof typeof dictionary, B>(eventType: T, body: typeof dictionary[T]): typeof dictionary[T];
export {};

26

dist/index.js

@@ -14,10 +14,22 @@ "use strict";

var dynamo_stream_event_template_json_1 = __importDefault(require("./events/aws/dynamo-stream-event-template.json"));
var cloud_watch_log_event_template_json_1 = __importDefault(require("./events/aws/cloud-watch-log-event-template.json"));
var alexa_smart_home_event_template_json_1 = __importDefault(require("./events/aws/alexa-smart-home-event-template.json"));
var alexa_skill_event_template_json_1 = __importDefault(require("./events/aws/alexa-skill-event-template.json"));
var cloud_watch_event_template_json_1 = __importDefault(require("./events/aws/cloud-watch-event-template.json"));
var cognito_user_pool_event_template_json_1 = __importDefault(require("./events/aws/cognito-user-pool-event-template.json"));
var dictionary = {
'aws:sns': sns_template_json_1.default,
'aws:sqs': sqs_template_json_1.default,
'aws:apiGateway': api_gateway_event_template_json_1.default,
'aws:scheduled': scheduled_template_json_1.default,
'aws:s3': s3_template_json_1.default,
'aws:kinesis': kinesis_template_json_1.default,
'aws:dynamo': dynamo_stream_event_template_json_1.default,
"aws:sns": sns_template_json_1.default,
"aws:sqs": sqs_template_json_1.default,
"aws:apiGateway": api_gateway_event_template_json_1.default,
"aws:scheduled": scheduled_template_json_1.default,
"aws:s3": s3_template_json_1.default,
"aws:kinesis": kinesis_template_json_1.default,
"aws:dynamo": dynamo_stream_event_template_json_1.default,
"aws:cloudWatchLog": cloud_watch_log_event_template_json_1.default,
"aws:alexaSmartHome": alexa_smart_home_event_template_json_1.default,
"aws:alexaSkill": alexa_skill_event_template_json_1.default,
"aws:cloudWatch": cloud_watch_event_template_json_1.default,
"aws:iot": {},
"aws:cognitoUserPool": cognito_user_pool_event_template_json_1.default,
"aws:websocket": api_gateway_event_template_json_1.default,
};

@@ -24,0 +36,0 @@ function createEvent(eventType, body) {

@@ -8,111 +8,211 @@ "use strict";

var index_1 = __importDefault(require("./index"));
describe('creating a new SNS event', function () {
it('should return a valid event', function () {
var event = index_1.default('aws:sns', {
Records: [{
describe("creating a new SNS event", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:sns", {
Records: [
{
Sns: {
Message: 'trigger-email',
Message: "trigger-email",
},
}],
},
],
});
chai_1.expect(event.Records[0].Sns.Message).to.equal('trigger-email');
chai_1.expect(event.Records[0].Sns.Type).to.equal('Notification');
chai_1.expect(event.Records[0].Sns.Message).to.equal("trigger-email");
chai_1.expect(event.Records[0].Sns.Type).to.equal("Notification");
});
});
describe('createSqsEvent()', function () {
it('should return SQS mocked event', function () {
var event = index_1.default('aws:sqs', {
Records: [{
body: {
foo: 'bar',
},
}],
describe("createSqsEvent()", function () {
it("should return SQS mocked event", function () {
var event = index_1.default("aws:sqs", {
Records: [
{
body: JSON.stringify({
foo: "bar",
}),
},
],
});
chai_1.expect(event.Records[0].body.foo).to.equal('bar');
chai_1.expect(event.Records[0].eventSource).to.equal('aws:sqs');
chai_1.expect(event.Records[0].body).to.equal("{\"foo\":\"bar\"}");
chai_1.expect(event.Records[0].eventSource).to.equal("aws:sqs");
});
});
describe('createApigEvent()', function () {
it('should return APIG mocked event', function () {
var event = index_1.default('aws:apiGateway', {
body: {
first_name: 'Sam',
last_name: 'Smith',
describe("createApigEvent()", function () {
it("should return APIG mocked event", function () {
var event = index_1.default("aws:apiGateway", {
body: JSON.stringify({
first_name: "Sam",
last_name: "Smith",
}),
});
var parsedBody = JSON.parse(event.body || "");
chai_1.expect(parsedBody.first_name).to.equal("Sam");
chai_1.expect(parsedBody.last_name).to.equal("Smith");
chai_1.expect(event.httpMethod).to.equal("GET");
});
});
describe("createWebsocketEvent()", function () {
it("should return websocket mocked event", function () {
var event = index_1.default("aws:websocket", {
body: JSON.stringify({
first_name: "Sam",
last_name: "Smith",
}),
requestContext: {
connectedAt: 123,
connectionId: "abc123",
},
});
chai_1.expect(event.body.first_name).to.equal('Sam');
chai_1.expect(event.body.last_name).to.equal('Smith');
chai_1.expect(event.method).to.equal('GET');
var parsedBody = JSON.parse(event.body || "");
chai_1.expect(parsedBody.first_name).to.equal("Sam");
chai_1.expect(parsedBody.last_name).to.equal("Smith");
chai_1.expect(event.requestContext.connectedAt).to.equal(123);
chai_1.expect(event.requestContext.connectionId).to.equal("abc123");
});
});
describe('createS3Event()', function () {
it('should return S3 mocked event', function () {
var event = index_1.default('aws:s3', {
Records: [{
describe("createS3Event()", function () {
it("should return S3 mocked event", function () {
var event = index_1.default("aws:s3", {
Records: [
{
s3: {
bucket: {
name: 'my-bucket-name',
name: "my-bucket-name",
},
object: {
key: 'object-key',
key: "object-key",
},
},
}],
},
],
});
chai_1.expect(event.Records[0].s3.bucket.name).to.equal('my-bucket-name');
chai_1.expect(event.Records[0].s3.object.key).to.equal('object-key');
chai_1.expect(event.Records[0].eventName).to.equal('ObjectCreated:Put');
chai_1.expect(event.Records[0].s3.bucket.name).to.equal("my-bucket-name");
chai_1.expect(event.Records[0].s3.object.key).to.equal("object-key");
chai_1.expect(event.Records[0].eventName).to.equal("ObjectCreated:Put");
});
it('should return S3 mocked event without side-effect', function () {
var event = index_1.default('aws:s3', {
Records: [{
it("should return S3 mocked event without side-effect", function () {
var event = index_1.default("aws:s3", {
Records: [
{
s3: {
bucket: {
name: 'my-bucket-name',
name: "my-bucket-name",
},
object: {
key: 'object-key',
key: "object-key",
},
},
}],
},
],
});
var event2 = index_1.default('aws:s3', {
Records: [{
var event2 = index_1.default("aws:s3", {
Records: [
{
s3: {
bucket: {
name: 'my-bucket-name',
name: "my-bucket-name",
},
object: {
key: 'object-key-2',
key: "object-key-2",
},
},
}],
},
],
});
chai_1.expect(event.Records[0].s3.bucket.name).to.equal('my-bucket-name');
chai_1.expect(event.Records[0].s3.object.key).to.equal('object-key');
chai_1.expect(event2.Records[0].s3.object.key).to.equal('object-key-2');
chai_1.expect(event.Records[0].eventName).to.equal('ObjectCreated:Put');
chai_1.expect(event.Records[0].s3.bucket.name).to.equal("my-bucket-name");
chai_1.expect(event.Records[0].s3.object.key).to.equal("object-key");
chai_1.expect(event2.Records[0].s3.object.key).to.equal("object-key-2");
chai_1.expect(event.Records[0].eventName).to.equal("ObjectCreated:Put");
});
});
describe('createScheduledEvent()', function () {
it('should return Scheduled mocked event', function () {
var event = index_1.default('aws:scheduled', {
region: 'us-west-2',
describe("createScheduledEvent()", function () {
it("should return Scheduled mocked event", function () {
var event = index_1.default("aws:scheduled", {
region: "us-west-2",
});
chai_1.expect(event.region).to.equal('us-west-2');
chai_1.expect(event['detail-type']).to.equal('Scheduled Event');
chai_1.expect(event.region).to.equal("us-west-2");
chai_1.expect(event["detail-type"]).to.equal("Scheduled Event");
});
});
describe('createKinesisEvent()', function () {
it('should return Kinesis mocked event', function () {
var event = index_1.default('aws:kinesis', {
Records: [{
describe("createKinesisEvent()", function () {
it("should return Kinesis mocked event", function () {
var event = index_1.default("aws:kinesis", {
Records: [
{
kinesis: {
data: Buffer.from('kinesis test').toString('base64'),
data: Buffer.from("kinesis test").toString("base64"),
},
}],
},
],
});
chai_1.expect(Buffer.from(event.Records[0].kinesis.data, 'base64').toString('ascii')).to.equal('kinesis test');
chai_1.expect(Buffer.from(event.Records[0].kinesis.data, "base64").toString("ascii")).to.equal("kinesis test");
});
});
describe("createCloudWatchEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:cloudWatch", {
"detail-type": "Something has been deleted.",
"region": "us-east-1",
});
chai_1.expect(event["detail-type"]).to.equal("Something has been deleted.");
chai_1.expect(event.region).to.equal("us-east-1");
});
});
describe("createCloudWatchLogEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:cloudWatchLog", {
awslogs: {
data: "Some gzipped, then base64 encoded data",
},
});
chai_1.expect(event.awslogs.data).to.equal("Some gzipped, then base64 encoded data");
});
});
describe("createAlexaSkillEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:alexaSkill", {
request: {
type: "CanFulfillIntentRequest",
},
context: {
System: {
device: {
deviceId: "myDevice",
},
},
},
});
chai_1.expect(event.request.type).to.equal("CanFulfillIntentRequest");
chai_1.expect(event.context.System.device.deviceId).to.equal("myDevice");
});
});
describe("createAlexaSmartHomeEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:alexaSmartHome", {
payload: {
switchControlAction: "TURN_OFF",
},
});
chai_1.expect(event.payload.switchControlAction).to.equal("TURN_OFF");
});
});
describe("createIotEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:iot", {
this: {
can: {
be: "anything I want",
},
},
});
chai_1.expect(event.this.can.be).to.equal("anything I want");
});
});
describe("createCognitoPoolEvent()", function () {
it("should return a valid event", function () {
var event = index_1.default("aws:cognitoUserPool", {
userName: "notAJ",
});
chai_1.expect(event.userName).to.eql("notAJ");
});
});
//# sourceMappingURL=index.spec.js.map
{
"name": "@serverless/event-mocks",
"version": "1.1.0",
"version": "1.1.1",
"description": "Event Mocks is a simple library designed to generate simple AWS events for testing and automation purposes.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc