# sqs-mock

> A mock of the aws-sdk SQS client which uses an in-memory queue.

Latest version **0.0.8** (published 2023-07-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install sqs-mock
pnpm add sqs-mock
yarn add sqs-mock
bun add sqs-mock
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-07-25 |
| First published | 2022-10-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xkore |
| Maintainers | xkore |
| Keywords | SQS, aws-sdk, mock, testing |

## Links

- npm: https://www.npmjs.com/package/sqs-mock
- Repository: https://github.com/visionsofparadise/sqs-mock
- Homepage: https://github.com/visionsofparadise/sqs-mock#readme
- Issues: https://github.com/visionsofparadise/sqs-mock/issues
- npm.io page: https://npm.io/package/sqs-mock

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2023-07-25
- 0.0.7 — 2022-11-02
- 0.0.6 — 2022-11-02
- 0.0.5 — 2022-10-31
- 0.0.4 — 2022-10-18
- 0.0.3 — 2022-10-18
- 0.0.2 — 2022-10-18

## README

# sqs-mock

A functional, in-memory mock of the SQS client from AWS-SDK. Queues are automatically created in-memory per QueueUrl provided.

Supports aws-sdk-v2 method and aws-sdk-v3 command APIs.

See documentation for AWS SDK usage: [aws-sdk-v2](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html), [aws-sdk-v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sqs/).

### Functional Methods

- [x] Constructor
- [ ] addPermission
- [ ] changeMessageVisibility
- [ ] changeMessageVisibilityBatch
- [ ] createQueue
- [x] deleteMessage
- [x] deleteMessageBatch
- [ ] deleteQueue
- [ ] getQueueAttributes
- [ ] getQueueUrl
- [ ] listDeadLetterSourceQueues
- [ ] listQueues
- [ ] listQueueTags
- [x] purgeQueue
- [x] receiveMessage
- [ ] removePermission
- [x] sendMessage
- [x] sendMessageBatch
- [ ] setQueueAttributes
- [ ] tagQueue
- [ ] untagQueue

### Other Functionality

- [ ] Message timing (DelaySeconds, VisibilityTimeout)
- [ ] Message attributes and attribute querying (ApproximateNumberOfMessages, ApproximateNumberOfMessagesNotVisible, etc.)
- [ ] Queue attributes and management

---

## Usage

### Set your sqs client to be the mock with a testing flag.

```js
// sqs.js
import { SQS } from 'aws-sdk'
import { SQSMock } from 'sqs-mock'

export const sqs = process.env.NODE_ENV === 'production'
 ? new SQS()
 : new SQSMock() as any as SQS // cast SQSMock as SQS if using typescript
```

### Use SQSMock client in tests

```js
// test.js
import { sqs } from './sqs'

const QueueUrl = 'test'

afterEach(async () => {
 await sqs.purgeQueue({
  QueueUrl
 }).promise()
})

it('adds, receives then deletes message in queue', async () => {
 await sqs
  sendMessage({
   QueueUrl,
   MessageBody: 'test'
  })
  promise();

 const result = await sqs
  receiveMessage({
   QueueUrl
  })
  promise();

 expect(result.Messages!.length).toBe(1);

 await sqs
  deleteMessage({
   QueueUrl,
   ReceiptHandle: result.Messages![0].ReceiptHandle
  })
  promise();

 const result2 = await sqs
  receiveMessage({
   QueueUrl
  })
  promise();

 expect(result2.Messages).toBeUndefined();
})
```

---
_Source: https://npm.io/package/sqs-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
