Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Theodo-UK/sls-test-tools into main
Browse files Browse the repository at this point in the history
  • Loading branch information
agwhi committed May 21, 2021
2 parents f78a34c + 811dffa commit 87f1cfa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
1 change: 0 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"release": true
},
"hooks": {
"before:init": "yarn lint",
"after:my-plugin:bump": "./bin/my-script.sh",
"after:bump": "yarn build",
"after:git:release": "echo After git push, before github release",
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ sls-test-tools is currently being actively maintained, yet is in alpha. Your fee
## Assertions:

### EventBridge
An interface to the deployed EventBridge, allowing events to be injected and intercepted via an SQS queue and EventBridge rule.

```
expect(eventBridgeEvents).toHaveEvent();
expect(eventBridgeEvents).toHaveEventWithSource("order.created");
```

### S3
```
await expect("BUCKET NAME").toHaveS3ObjectWithNameEqualTo("FILE NAME");
// note this is an async assertion and requires "await"
```

## Helpers

### General
Expand All @@ -54,6 +58,7 @@ getOptions() - get options for making requests to AWS
```

### EventBridge
An interface to the deployed EventBridge, allowing events to be injected and intercepted via an SQS queue and EventBridge rule.

#### Static

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sls-test-tools",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "Custom Jest Assertions for Serverless Projects",
"main": "lib/index.js",
"directories": {
Expand Down
33 changes: 33 additions & 0 deletions src/assertions/toHaveObjectWithNameEqualTo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AWSClient } from '../../helpers/general';

export default {
async toHaveS3ObjectWithNameEqualTo(bucketName, objectName) {
const s3 = new AWSClient.S3();
const params = {
Bucket: bucketName,
Key: objectName,
};

let testResult;
try {
await s3.getObject(params).promise();
testResult = {
message: () =>
`expected ${bucketName} to have object with name ${objectName}`,
pass: true,
};
} catch (error) {
if (error.code === 'NoSuchKey') {
testResult = {
message: () =>
`expected ${bucketName} to have object with name ${objectName} - not found`,
pass: false,
};
} else {
throw error;
}
}

return testResult;
},
};

0 comments on commit 87f1cfa

Please sign in to comment.