Skip to content

Commit

Permalink
Readme copied from AWS event mocks. Newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
astuyve committed Apr 15, 2019
1 parent 8cde391 commit 6f165da
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 11 deletions.
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Event Mocks
A small library that includes details mocks of AWS Lambda event sources. Useful for use when unit testing your Lambda functions. Supported Event Sources are: SNS, API Gateway, S3, & Scheduled.

The library simply uses default event source mock templates and merge it with any overwrite you provide. [Check out the JSON template files](./lib/events) to learn more about the data structure of each event source.

## Usage

### SNS

```js
const createEvent = require('aws-event-mocks');
const mocked = createEvent({
template: 'aws:sns',
merge: {
Records: [{
Sns: {
Message: 'trigger-email'
}
}]
}
});
```

### API Gateway

```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:apiGateway',
merge: {
body: {
first_name: 'Sam',
last_name: 'Smith'
}
}
});
```

### S3

```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:s3',
merge: {
Records: [{
eventName: 'ObjectCreated:Put',
s3: {
bucket: {
name: 'my-bucket-name'
},
object: {
key: 'object-key'
}
}
}]
}
});
```

### Scheduled

```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:scheduled',
merge: {
region: 'us-west-2'
}
});
```

### Kinesis

```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:kinesis',
merge: {
data: new Buffer('this is test data').toString('base64')
}
});
2 changes: 1 addition & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '*.json' {
const value: any;
export default value;
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/api-gateway-event-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"user": ""
},
"stageVariables": {}
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/dynamo-stream-event-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"eventSource": "aws:dynamodb"
}
]
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/kinesis-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/s3-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/scheduled-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"arn:aws:events:us-east-1:123456789:rule/test-service-rule"
],
"detail": {}
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/sns-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/sqs-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"awsRegion": "us-east-2"
}
]
}
}
2 changes: 1 addition & 1 deletion lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ describe('createKinesisEvent()', function () {

expect(new Buffer(event.Records[0].kinesis.data, 'base64').toString('ascii')).to.equal('kinesis test')
})
})
})
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export default function createEvent(eventType: string, body: any): any {
if (event) {
return merge(cloneDeep(event), body)
}
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"semicolon": [true, "never"],
"no-bitwise": false
}
}
}

0 comments on commit 6f165da

Please sign in to comment.